|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
transacted session with backout support |
« View previous topic :: View next topic » |
Author |
Message
|
brendanl |
Posted: Thu Sep 29, 2005 8:54 pm Post subject: transacted session with backout support |
|
|
Newbie
Joined: 29 Sep 2005 Posts: 2
|
I've seen quite a few posts with some ideas that I have had a play with, but found no solution to my problem.
I need a transacted connection - so no messages are ever lost.
I need the support of an automatic backoutcount increment and redeliver
& I need the support of the automatic message forwarding to the backout queue.
From my many combinations of code, I have observed the following
untransacted Session createQueueSession(false, ...)
onMessage - throws RuntimeException
message is redelivered until max is reached then forwarded to backout queue.
However, as mentioned untransacted is no good - if the power goes off within onMessage, the message is lost.
So
Transacted Session - createQueueSession(true, ...)
onMessage - throws RuntimeException
Message is forward immediately to backoutqueue - there is no concept of redeliver until max is reached. And when the application is shutdown, the message is put back to the original queue.
This message back to the original queue behaviour would be related to the fact that its transacted and a commit was never issued
So
Within onMessage, I am now sending a commit command. So - its now transacted and messages dont return to the original queue from the backout once the app is turned off. However, the messages dont wait for the max retry count before they are put to the backout - there is no redeliver. I quess this is because the commit is somehow issued earlier??
What does it take to satisfy my requirements????
Heres some code if it helps. I also tried passing the session to the listener, but that didnt work to well either.
Thanks very much to all those that are able to offer some advice.
public class OnMessageReceiver {
public static void main(String[] args) {
OnMessageReceiver app = new OnMessageReceiver();
app.go();
}
public Object lock;
public void dowait() throws Exception{
synchronized(lock){
lock.wait();
}
}
public void unwait(){
synchronized(lock){
lock.notifyAll();
}
}
public void go(){
try{
System.out.println("starting");
MQJMSQueueConnectionFactory factory = new MQJMSQueueConnectionFactory();
factory.setTransportType(1);
factory.setQueueManager("localQM");
factory.setHostName("CORWCS0003");
factory.setPort(Integer.parseInt("1414"));
factory.setChannel("serverConnection");
lock = new Integer(1);
QueueConnection connection = factory.createQueueConnection();
QueueSession session = connection.createQueueSession (true, Session.AUTO_ACKNOWLEDGE);
connection.start();
QueueReceiver receiver = session.createReceiver(session.createQueue("MFP_REQUEST"));
MyListenerSimple listener = new MyListenerSimple(this);
receiver.setMessageListener(listener);
while(true){
dowait();
System.out.println("Commiting session");
session.commit();
}
//session.close();
//connection.close();
}catch(Exception e){
e.printStackTrace();
}
}
}
class MyListenerSimple implements javax.jms.MessageListener {
public OnMessageReceiver that;
MyListenerSimple(OnMessageReceiver that) {this.that = that;}
public void onMessage(javax.jms.Message msg) {
try{
System.out.println ("JMS client: received message ======> " + ((TextMessage)msg).getJMSMessageID() +" " + ((TextMessage)msg).getText());
that.unwait();
}catch(Exception e){e.printStackTrace();}
if(true){
System.out.println("throwing exception");
throw new RuntimeException("sss");
}
}
} |
|
Back to top |
|
 |
fjb_saper |
Posted: Fri Sep 30, 2005 3:26 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
Don't know what you are exactly trying to do but I would certainly not have set it up this way.
Remember in J2EE the transactional boundaries would be on the method onMessage().
Enjoy  |
|
Back to top |
|
 |
brendanl |
Posted: Sun Oct 02, 2005 1:45 pm Post subject: |
|
|
Newbie
Joined: 29 Sep 2005 Posts: 2
|
Thanks for the reply
The code is probably a little overkill - I was trying out a few different things.
I was hoping to be able to reap the benefits of redelivery on exception, followed by automatic forwarding to the backout queue once the retry count had been reached – all while having a transacted read so the message is not in jeopardy of being lost.
From my observations I can only have one (untransacted retries and forwarding) or the other (transacted reads with no permanent forwarding) |
|
Back to top |
|
 |
fjb_saper |
Posted: Sun Oct 02, 2005 7:15 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
Not quite...
If using Websphere Apps Server and MDB (transacted)...
Set the backout threshold to 1 less than the retry threshold of the MDB.
If the backout threshold is reached the message will be put on the backout queue. If none has been defined it will go to the DLQ.
Now if you are not using WAS you may have to implement that functionality yourself. This means checking the number of retries while doing your transacted read. If the backout threshold has been reached move the message to the retry queue or add a DLQ hdr and send it to the DLQ.
Enjoy  |
|
Back to top |
|
 |
|
|
 |
|
Page 1 of 1 |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|