JMS configuration -- client exclusive messages I am SURE this is somehow easy but reading the docs isn't bringing it to light.

The problem: I am trying to setup a JMS message listener and what I need is for the first client to have exclusive message processing rights.

That is: Until a single client acknowledges the message the server will not notify any other consumers of the message.

I believe this is correct but I am looking for some verification. The whole 'transacted' part is throwing me off 

As an aside: I posted it to regular SOF and got told to repost here. 

  public class QueueMessengerMessageListener implements MessageListener {

    protected Logger log = LoggerFactory.getLogger(getClass());

    private Connection connection;

    @Autowired
    private Queue q;

    @Autowired
    private ConnectionFactory connectionFactory;

    @Autowired
    private DWHService dwhService;

    @PostConstruct
    private void listen() throws JMSException {
        connection = connectionFactory.createConnection();
        Session jmsSession = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
        MessageConsumer consumer = jmsSession.createConsumer(q);
        consumer.setMessageListener(this);
        connection.start();
    }

    @PreDestroy
    public void destroy() throws JMSException {
        connection.close();
    }

    @Override
    @Transactional
    public void onMessage(Message m) {
        BytesMessage jmsMessage = (BytesMessage) m;
        MyObject userMessage = null;
        try {
            byte[] in = new byte[(int) jmsMessage.getBodyLength()];
            jmsMessage.readBytes(in);
            ObjectInputStream inStream = new ObjectInputStream(new ByteArrayInputStream(in));
            userMessage = (MyObject) inStream.readObject();
            dwhService.addDwhEntry(userMessage);
            m.acknowledge();

        }
         catch (Exception e) {
            /* I normally wouldn't catch *all* exceptions, but the JMS tutorial says Thou Shalt Not throw
             * a RuntimeException from this method. */
             log.error("Error sending message {}",  e.getMessage());
        }
    }
}
The code looks fine although I'm not familiar with JMS, so I can't say anything about it's correctness. Just three minor notes:


userMessage could be declared inside the try block:

try {
    byte[] in = new byte[(int) jmsMessage.getBodyLength()];
    jmsMessage.readBytes(in);
    ObjectInputStream inStream = new ObjectInputStream(new ByteArrayInputStream(in));
    MyObject userMessage = (MyObject) inStream.readObject();
...


(Effective Java, Second Edition, Item 45: Minimize the scope of local variables)

protected Logger log = LoggerFactory.getLogger(getClass());



The logger could be private.

(Item 13 of Effective Java 2nd Edition: Minimize the accessibility of classes and members.)
The logger also could be static. There is a good template for Eclipse for generating getLogger calls with MyType.class classes instead of getClass():

private static final Logger log = LoggerFactory.getLogger(QueueMessengerMessageListener.class);