In my case, I need to process message by order, so I create a Session Bean (Processor) to
do that, the code is like following:
| @TransactionAttribute(TransactionAttributeType.REQUIRED)
| public boolean process() throws BusinessException {
| try {
| Message message = poll();
| if (message != null) {
| handle(message);
| return true;
| }
| } catch (Exception e) {
| logger.error("error", e);
| throw new BusinessException(e);
| }
| return false;
| }
|
in the function poll(), I just create a MessageConsumer and call receive().
In another job, call this session bean like this:
| processor.open();
| try {
| while (processor.process())
| ;
| } finally {
| processor.close();
| }
|
and in open() function, i create connection and session, and in close() function i close
them.
In my test, first put 10 messages into the queue, and the 5th will throw a exception in
process.
I found strange problems:
1. messages after the 5th one was processed, i.e. some of 6, 7, 8, 9, 10 was processed
2. there are 2 messages left, one is the 5th, another is any of 6, 7, 8, 9, 10
How to explain these?
And how to receive 1, 2, 3, 4, and then blocked.
My version jboss-messaging-1.4.2.GA-SP1.
The following is the code to send message:
| Connection connection = factory.createConnection();
| Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
| MessageProducer pub = session.createProducer(topic);
| ObjectMessage msg = session.createObjectMessage();
| msg.setObject(cmd);
| pub.send(msg);
| pub.close();
| session.close();
| connection.close();
|
View the original post :
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4229593#...
Reply to the post :
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&a...