Friday November 25, 2005
How to develop JMS client in NetBeans I will describe developing of a client application that send JMS message with order. The order will be processed in application tier. Since, I would like to conform patterns, I will use business pattern that separates presentations from business logic. I would like to describe this pattern in one of the next posts. Specifically, a business delegate is a helper class that handles the details of connecting and sending JMS message. GUI invokes methods in business delegate class and isn't interested in low-level stuff. :-) Let's start to create J2SE client:
public class DelegateImpl implements OrderDelegate{
private static String JMS_FACTORY_NAME = "jms/ProcessOrderDestinationFactory";
private static String QUEUE_NAME = "jms/ProcessOrderBean";
public DelegateImpl() throws ApplicationException{
try{
ctx = new InitialContext();
connFactory = (TopicConnectionFactory) ctx.lookup(JMS_FACTORY_NAME);
destination = (Topic) ctx.lookup(QUEUE_NAME);
}catch(NamingException ex){
throw new ApplicationException(ex.getMessage());
}
}
public void createOrder(Order order) throws ApplicationException{
Connection conn = null;
MessageProducer producer;
try {
conn = connFactory.createConnection();
Session session = conn.createSession(false,
Session.AUTO_ACKNOWLEDGE);
producer = session.createProducer(destination);
ObjectMessage objMsg = session.createObjectMessage();
objMsg.setObject(order);
producer.send(objMsg);
if(conn != null){
conn.close();
}
} catch (JMSException ex) {
throw new ApplicationException(ex.getMessage());
}
}