I've got a problem when sending messages onto a queue. My task is simple, I get some records from one database and insert them into another. I'm using a Global Transaction, infact an XA Transaction as my connections span databases. After retrieving the records from the first database, for each record, I start a new transaction to perform the inserts. Inside of this tx I perform my inserts into several tables and I want to finally send a message onto a Queue. This all seemed simple and appeared to work initially, when I had a small volume of records.
Basically, in my EJB, I have defined the following:
@Resource(mappedName="jms/ConnectionFactory")
private javax.jms.ConnectionFactory connectionFactory;
@Resource(mappedName="jms/processQ")
private javax.jms.Queue processQ;
private javax.jms.Connection jmsConnection;
@PostConstruct
protected void PostConstruct() {
jmsConnection = connectionFactory.createConnection();
}
Then, when I go to send my message I perform the following:
public static void sendForProcessing(
javax.jms.Connection jmsConnection, javax.jms.Queue queue,
Long entityId) {
javax.jms.Session session = null;
try {
session = jmsConnection.createSession(true, Session.AUTO_ACKNOWLEDGE);
javax.jms.Message outMsg = session.createMessage();
session.createProducer(queue).send(outMsg);
outMsg.setLongProperty(ENTITY_ID_KEY, entityId);
} catch (JMSException e) {
... log exception
}
finally {
if(session != null) {
try {
session.close();
}
catch(javax.jms.JMSException e) {
... log exception
}
}
}
}
After the entities have been inserted and the messages has been sent onto the queue, the tx should commit. The problem is that I'm getting an exception after a few invocations of this method.
[#|2009-01-20T13:52:24.657-0800|SEVERE|sun-appserver9.1|com.sybase.it.ecv.jms.JmsUtils|_ThreadID=16;_ThreadName=org.springframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-1;_RequestID=03ad9395-d231-42e4-8efa-dc785b964a12;|JmsUtils.sendForProcessing.. EXCEPTION CAUGHT durig send!
com.sun.messaging.jms.JMSException: [SEND_REPLY(9)] [C4036]: A broker error occurred. :[500] transaction failed: Unexpected Broker Exception: [received message with Unknown Transaction ID -1: ignoring message] user=guest, broker=localhost:7676(4342)
at com.sun.messaging.jmq.jmsclient.ProtocolHandler.throwServerErrorException(ProtocolHandler.java:3930)
at com.sun.messaging.jmq.jmsclient.ProtocolHandler.writeJMSMessage(ProtocolHandler.java:1918)
From the looks of the message I would assume that the connection to the JMS server is on a different thread and is associated to the suspended tx. Is this because I am holding onto the connection to the JMS Server? I thought that it would be better to keep the connection to the server as a reference rather than constantly recreating a new connection to the server. But looking at the log file from openMQ it seems that this is an issue because I'm seeing the following messages in it's log file:
[20/Jan/2009:13:52:32 PST] [B1066]: Closing: guest_at_127.0.0.1:4489->jms:4342 because "[B0061]: Client exited without closing connections". Count: service=0 broker=10
So should I simply keep opening a new connection and close it when I complete my send? Or is there something that I am overlooking here?
Thanks for the help....
[Message sent by forum member 'cmathrusse' (cmathrusse)]
http://forums.java.net/jive/thread.jspa?messageID=327253