I need to consume messages from a JMS queue deployed on JBoss 7.2. My consumer is particular in the sense that it needs to keep the processed message, in order to "chain it" with the next message : Mn = Mn-1 + Mn, before sending it to a DB.
I know MDB are stateless, so I can't use them for this specific use case.
I opted for a classic Java Thread, applying an endless loop inside its run method, and call queue recieve.
public void run() {
// queue to listen to
consumer = session.createConsumer(myQueue);
// start
con.start();
while (true) {
// listen ...
ObjectMessage recievedObj = (ObjectMessage) consumer.receive();
// do some work
lastRecievedObj = recievedObj;
}
}
The fact is that it's not recommended to handle threads in a Java EE environment (except for Java EE 7).
What do you think? Do you have a better idea?