Question

The JMS docs for Spring 4 here: http://docs.spring.io/spring/docs/4.0.0.RELEASE/spring-framework-reference/htmlsingle/#jms-receiving don't seem to cover this.

I have multiple clients connecting with sockets to a socket server. They send messages to my server and receive messages back, all of which are being routed through an active MQ queue.

Some messages get a response message back. The problem happens when a client sends a message A that gets a response B to send back to the client. After sending A to the server, the box with the open socket drops due to an error. Message B comes back and waits in the queue and nothing ever picks up the result.

As I understand it, you can set up JMS queues for durable topics with no auto acknowledge. This way if the server drops, the message comes back and broadcasts to all boxes. If one of the boxes is currently connected to that client, it will process the message.

If not, it will sit in the queue until a new server connects and then it will do it again. Once the message is sent, it will be marked as acknowledged and dropped from the queue.

Since this seems doable with active MQ, how do I implement with Spring 4?

Was it helpful?

Solution

What you want is to use transactions and not rely on acknowlegements. Then you can start a transaction upon read, then commit the transaction when you sent the response message. If some bad things happends, the transaction rolls back and some node consuming messages have to redo the procedure.

The DefaultMessageListenerContainer in Spring can be setup to support transactions. The javadoc is pretty good and provides links to other sources of information regarding spring and transactions (itself, a rather large subject). In a nutshell, if you setup session transacted, your transaction will roll back if there is an Exception thrown and commit when your onMessage method returns.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top