wood burning stoves 2.0*
The moose likes EJB and other Java EE Technologies and the fly likes Multithreaded JMS application 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 "Multithreaded JMS application" Watch "Multithreaded JMS application" New topic
Author

Multithreaded JMS application

Jyoti Sharma
Greenhorn

Joined: Apr 23, 2010
Posts: 9
I am working on a multithreaded JMS receiver and publisher code. XML message is received from a Queue, stored procedures(takes 70 sec to execute) are called and response is send to Topic within 90 sec. I need to handle a condition when broker is down. i.e. a condition in which messages are received from Queue and are being processed in java, in the mean time both Queue and Topic will be down. Then how to handle those messages which are not on queue and not send to topic but are in java memory? Different options available:

1.To use CLIENT_ACKNOWLEDGE
2.To separate publisher code from receiver code.
3.To have error utility which will take messages from log and process them and send to Topic(least preferred)

Please suggest me the right option

Thanks,
Jyoti
ramprasad madathil
Ranch Hand

Joined: Jan 24, 2005
Posts: 489

Put this whole stuff - receiving msg from the queue, procedure call and posting to a topic in a transaction? If any one fails, everything is rolled back.

ram.
Prabhakar Reddy Bokka
Ranch Hand

Joined: Jul 26, 2005
Posts: 189

Once the message received from a queue it will be deleted from the queue. You cannot roll back that.

The solution i think is...
You can store the messages to a temp storage or temp table, and send them to topic once topic is up.
delete them from temp table after successfully sending to topic.



SCJP 5, SCWCD 5
Jyoti Sharma
Greenhorn

Joined: Apr 23, 2010
Posts: 9
ramprasad madathil wrote:Put this whole stuff - receiving msg from the queue, procedure call and posting to a topic in a transaction? If any one fails, everything is rolled back.

ram.


Thanks!

In below two approaches which one is better?

(1) To create CLIENT_ACKNOWLEDGE session as :
connection.createSession(false, javax.jms.Session.CLIENT_ACKNOWLEDGE)
Here I will acknowledge message only after the successful completion of transactions(stored procedures)

(2) To use transacted session i.e., connection.createSession(true, -1). In this approach because of some exception in transaction (stored procedure) the message is rolled back and Redelivered. They are rolled back again and again and continue until I kill the program. Can I limit the number of redelivery of jms messages from queue?
ramprasad madathil
Ranch Hand

Joined: Jan 24, 2005
Posts: 489

To create CLIENT_ACKNOWLEDGE session as :
connection.createSession(false, javax.jms.Session.CLIENT_ACKNOWLEDGE)
Here I will acknowledge message only after the successful completion of transactions(stored procedures)


With client acknowledge, when you acknowledge a message, all previously unacknowledged messages are also automatically acknowledged.

To use transacted session


commit() on a transacted session commits all messages in that session. Which means you have to use a new connection and create a new session() per message you receive. In other words your receiver should end it's work after each message.

If you simply want messages to be redelivered if there is an error in processing, set the acknowledge mode to auto acknowledge and throw an exception from within the receiver. With auto acknowledge messages are acknowledged only when the onMessage() method succesfully returns. If there is an exception, messages will be redelivered.


Going back to your original question which was

a condition in which messages are received from Queue and are being processed in java, in the mean time both Queue and Topic will be down. Then how to handle those messages which are not on queue and not send to topic but are in java memory?


The answer to that would be option 3 (the least preferred ) in your original post - have error utility which will take messages from log and process them and send to Topic

cheers,
ram.


 
Consider Paul's rocket mass heater.
 
subject: Multithreaded JMS application