Juergen,
Thanks for the replies. I tried to use ActiveMQs JCA container, but ran into classpath issues related to the classes in the J2EE.jar file; so I decided to use JMS APIs directly. Everything seems to be working fine now; but I am concerned because you said that this isn't suitable for concurrent message reception. As far as I can tell, my logic *should* work for concurrent messages as well. Can you please quickly review the following code snippets and tell me why this solution will not work in the Multi threading environment?
(My next option is to use the traditional MDBs, but as far as possible I would like to avoid that).
Anyway, here's a code snippet from my Consumer class:
Code:
// This method will be triggered only once, via init-method="start"
public void start() throws Exception {
try {
connection = getJmsConf().getJmsConnectionFactory().createQueueConnection();
QueueSession session = null;
QueueReceiver queueReceiver = null;
//TODO: Set appropriate client id
connection.setClientID("foo");
connection.start();
session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = session.createQueue(getJmsConf().getQueueName());
queueReceiver = session.createReceiver(queue);
queueReceiver.setMessageListener(this);
}
catch (Exception ex) {
logger.error(ex.getMessage());
throw ex;
}
}
// This *light-weight* method delegates processing to a SSB
public void onMessage(Message message) {
TextMessage txt = (TextMessage) message;
try {
String text = txt.getText();
if (message.getJMSRedelivered()) {
logger.error("This message was redelivered:" + text);
} else {
logger.debug("This message is new" + text);
MessageDelegate.processMessage(_testUser, text);
}
message.acknowledge();
}
catch (JMSException e) {
logger.error("Message processing failed!);
}
}
When a message is received, the MessageDelegate sends it to a Stateless Session Bean EJB for processing.
As far as I can tell, my 'onMessage' method is thread-safe and it should process messages received concurrently safely. Am I missing something? Your help will be greatly appreciated.
Thanks.
- Ajay