ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » IBM MQ Java / JMS » Message getting back to the queue..

Post new topic  Reply to topic
 Message getting back to the queue.. « View previous topic :: View next topic » 
Author Message
newtomq22
PostPosted: Mon May 02, 2005 10:21 am    Post subject: Message getting back to the queue.. Reply with quote

Novice

Joined: 08 Apr 2005
Posts: 24

Hi,

I am using WAS/MQ and JMS as the api. I am an inbound queue and an error inbound queue. I receive the message off the error q and just log it to a file. From th inbound queue i get the message, try to process it , if there is an exception thrown i log it to the rejected message log. It seems that the messages which throw an exception are getting thrown back to the queue.
Do i have to commit the session every time i process/reject a message?
Following is the code snippet
try {
Context context = new InitialContext();

QueueConnectionFactory factory =
(QueueConnectionFactory) context.lookup(
MsgConstants.QUEUE_CONNECTION_FACTORY_NAME);

queue = (Queue) context.lookup(MsgConstants.INBOUND_QUEUE_NAME);
Queue errorQueue = (Queue) context.lookup(MsgConstants.INBOUND_ERROR_QUEUE_NAME);

connection = factory.createQueueConnection();

session =
connection.createQueueSession(true, Session.AUTO_ACKNOWLEDGE);

receiver = session.createReceiver(queue);
QueueReceiver errorReceiver = session.createReceiver(errorQueue);

connection.start();
while (true) {
Message m = receiver.receive(1);

Message errorMsg = errorReceiver.receive(1);

if(errorMsg != null) {
if(errorMsg instanceof JMSBytesMessage) {

bytesMsg = (JMSBytesMessage) errorMsg;

byte[] myBytes = new byte[1500];

int i = bytesMsg.readBytes(myBytes);
System.out.println("string message " + new String(myBytes));

MsgLogger.logRejectedMsg(new String(myBytes));
}
else if(errorMsg instanceof TextMessage) {

MsgLogger.logRejectedMsg(((TextMessage) errorMsg).getText());

}
}

if (m != null) {
if (m instanceof TextMessage) {
processMessage(m);
message = (TextMessage) m;
}
} else {
break;
}
}
session.commit();
} catch (Exception je) {

je.printStackTrace();

} finally {

if (connection != null) {

try {
connection.close();
} catch (Exception e) {
e.printStackTrace();
}

}

}

}

and the processMessage(m) basically does this
try {

xmlMsg = ((TextMessage) msg).getText();
MsgLogger.logRecvMsg(xmlMsg);

SchMsgDigester schDigester = new SchMsgDigester();
Object msgObj = schDigester.digest(xmlMsg);
ProcessXmlMsg pxm = new ProcessXmlMsgImpl();
pxm.processMsg(msgObj);

} catch (Exception t) {

StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
t.printStackTrace(pw);

StringBuffer sb = new StringBuffer("\n\nRejected :");
sb.append(sw.toString());
sb.append(" ** ");
sb.append(xmlMsg);
MsgLogger.logRejectedMsg(sb.toString());

}
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Mon May 02, 2005 11:16 am    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20756
Location: LI,NY

Read the part about transaction and messages and JMS and websphere.
Look either in a Websphere, JMS, or MQ manual (using Java)

You need to familiarize yourself with MDBs and Backout queues etc...

What you are attempting there is not the best of designs.
I would not try to read off the data queue and off the error queue in the same transaction... It just ain't healthy...

Enjoy
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » IBM MQ Java / JMS » Message getting back to the queue..
Jump to:  



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
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.