File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB and other Java EE Technologies and the fly likes putting back into the queue the JMS messages Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "putting back into the queue the JMS messages" Watch "putting back into the queue the JMS messages" New topic
Author

putting back into the queue the JMS messages

Sergiu Truta
Ranch Hand

Joined: Dec 16, 2003
Posts: 121
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


...watch me...as I'm walking the path...
Vinod John
Ranch Hand

Joined: Jun 23, 2003
Posts: 162

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.
Sergiu Truta
Ranch Hand

Joined: Dec 16, 2003
Posts: 121
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.
Melody Siu
Greenhorn

Joined: Nov 06, 2003
Posts: 21
What about using the browsing capability of JMS or
rollback the user transaction will undo all read from the queue...
Melody
Malli Raman
Ranch Hand

Joined: Nov 07, 2001
Posts: 312
Originally posted by Melody Sadler:
What about using the browsing capability of JMS or
rollback the user transaction will undo all read from the queue...
Melody


I think you can use for QueueBroswer facilities..
- Raman
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: putting back into the queue the JMS messages
 
Similar Threads
How to read JMS messages from all the managed servers.
URGENT Help Needed regarding the sending XML file to the JMS Queue
Very simple JMS ActiveMQ PTP interaction on Tomcat
Persistent Messages, What heppens if a system is started!
2 jms interview questions