Hi guys, I was wondering if I read a message from a message Queue, and want to put it back can I do it? I am using a JMS Queue inside JBoss 3.0. Inside a session bean, I am sending messages to this queue. In my frontend I am reading the messages and using them. But if at a previous action the usecase terminated earlier than expected, not all the messages inside the queue were processed so there were some left inside the queue. The next time the usecase is runned, the frontend will process these leftout messages too but I don't want that. Now, I've written a message consumer which is called at the beginning of the usecase, and this consumer pops out all the messages inside the queue. But this messages are different for different users/machines/browsers. Inside each message I have a sessionID. Now, the consumer pops out all the messages, but I want it to pop out only the messages for a certain user. Here is my question: 1)Can I read the contents of a message without poping out the message? or 2)If I pop out the message to read it's contents and I see that it's a message for another user and not the one currently running the usecase, I have to put the message back into the queue. Can I do that and how? Thanks guys Wish you well
1)Can I read the contents of a message without poping out the message?
I have done this when I was using Oracle's AQ that reads straight from the queue tables but that was part of administration, if the real app can read directly from db table or other place where the message is stored then the use Messaging server for queing becomes irrelevent. I don't know any other way of reading the message in the queue with out poping it out.
2)If I pop out the message to read it's contents and I see that it's a message for another user and not the one currently running the usecase, I have to put the message back into the queue. Can I do that and how?
I have read some were if you are a durable subscriber and your message listeners (MDB) are part of a (container managed)transaction then if an exception is thrown when processing the message then the message is put back into the queue automatically (I don't have any clear proof of the above). Or your listener application can have a message producer which can reformat the poped out message and put it back to the queue.
Yes, I know that if an exception occures, the message will be put back into the queue. I'm not sure if in my case this is true but it's not a solution and I will tell you why: if I have 10 messages inside the queue, and at the 5th message I realize it's not for the current user, I throw an exception and maybe the message gets back into the queue, but for sure the last 5 messages are not proccessed. Do you get my point? Reformatting the message and putting it back into the queue is a solution but it's not the most elegant. Do you know of any other solution guys? Thanks, Sergiu.