Home > Archive > EAserver > April 2005 > Can I add JMS message listener in a start up servlet's init() method?--HELP!









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Can I add JMS message listener in a start up servlet's init() method?--HELP!
Jenny Zhang

2005-04-11, 7:25 am

Hi:

I am using EAServer 4.2.2 on Win2000. I have a message queue defined in
EAServer and I need to add a message listener to that queue during the
server start up. This servlet will be initialised during the server's
start up. The following code is called from StartupServlet.java's
init(ServletConfig config) method.

String queueName = "QualCheckQueue";
QueueConnectionFacto
ry queueConnectionFacto
ry = null;
QueueConnection queueConnection = null;
QueueSession queueSession = null;
Queue queue = null;
QueueReceiver receiver = null;
try {

Properties prop = new Properties();
prop.put("com.sybase.jms.debug", "true");
prop.put("java.naming.security.principal", "jagadmin");
prop.put("java.naming.security.credentials", "password");
prop.put("java.naming.factory.initial",
"com.sybase.jms. InitialContextFactor
y");
prop.put("java.naming.provider.url", "iiop://wgtndev45:9000");

Context ctx = new InitialContext(prop)
;
try {
queueConnectionFacto
ry = (QueueConnectionFact
ory)
ctx.lookup(" QualCheckConnectionF
actory");
}
catch (NamingException e) {
//
}

queueConnection =
queueConnectionFacto
ry. createQueueConnectio
n();
queueConnection.start();
queueSession = queueConnection. createQueueSession(f
alse,
Session.AUTO_ACKNOWLEDGE);
//from this place you can add more queues and receivers
queue = (Queue) ctx.lookup(queueName);
receiver =
queueSession. createReceiver(queue
);

SXIQualCheckMessageL
istener messageListener = new
SXIQualCheckMessageL
istener(queueSession
);
receiver. setMessageListener(n
ew
SXIQualCheckMessageL
istener(queueSession
));

setInitialised(true)
;
}
catch (Exception e) {
try {
if (receiver != null) {
receiver.close();
}
if (queueSession != null) {
queueSession.close();
}
if (queueConnection != null) {
queueConnection.close();
}
}
catch (JMSException ee) {
logger.debug(ee.toString());
}
}

Once the server start up, I got heap of repeating error message of the
following:

SystemException: INV_OBJREF (CtsComponents/MessageQueueST/receive - ?@?)
Apr 11 13:03:58 2005: Class Name: com.sybase.jms.SybQueueConnection
Method Name: getExceptionListener

Apr 11 13:03:58 2005: Class Name: com.sybase.jms.SybQueueConnection
Method Name: getExceptionListener

Apr 11 13:03:58 2005: Class Name: com.sybase.jms.SybQueueSession Method
Name: getTransacted
Apr 11 13:03:58 2005: Thread::threadData: tml_keydata_get() failed
Apr 11 13:03:58 2005: Thread::threadData: tml_keydata_get() failed

It hangs the server, I have to stop the server to free my CPU.

My SXIQualCheckMessageL
istener code is:

public class SXIQualCheckMessageL
istener implements MessageListener {
private static Logger logger =
Logger. getLogger(SXIQualChe
ckMessageListener.class);

private QueueSession session = null;

public SXIQualCheckMessageL
istener(QueueSession
session) {
this.session = session;
}

public void onMessage(javax.jms.Message msg) {

if (msg instanceof TextMessage) {

TextMessage txtMsg = (TextMessage)msg;
try {
String productDescription =
txtMsg.getStringProperty("ProductDescription");
int orderNumber = txtMsg.getIntProperty("OrderNumber");
logger.debug("The ProductDescription is " + productDescription);

logger.debug("the OrderNumber is " + orderNumber);
session.commit();
} catch (JMSException e) {
logger.error(e.getStackTrace());
try {
session.rollback();
}
catch (JMSException ee) {
}
}

}
}
}

I have tried if I run the message listener as a standalone application
to retrieve from message queue, there is no problem. This only happens
when I added the listener to the message queue during server start up.
Is there any restrictions that I should not add message listener during
a servlet startup? Or did I do it in the wrong way?

Thank you for your help.

Jenny

Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com