Integer orderId = (Integer) servletContext.getAttribute(ORDER_ID_ATTR);
Float linePrice = (Float) servletContext.getAttribute(LINE_PRICE_ATTR);
float amount = linePrice + shippingPrice;
// create a connection
Connection connection = connectionFactory.createConnection();
try {
// create a session
Session session =
connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
try {
// create the message
MapMessage invoiceMessage = session.createMapMessage();
invoiceMessage.setInt("orderId", orderId);
invoiceMessage.setFloat("amount", amount);
// send it!
MessageProducer producer = session.createProducer(invoiceQueue);
producer.send(invoiceMessage);
logger.log(
Level.FINE,
"sent invoice message for PO #{0,number,integer} with amount {1,number,currency}",
new Object[] { orderId, amount });
}
finally {
session.close();
}
}
finally {
connection.close();
}
}