3
votes

I have:

  • A hornetq-2.2.14-final standalone server
  • A client application C1 that send messages to queue A
  • A client application C2 that consume messages from a queue A

C1 use jmstemplate for sending messages in CLIENT_ACKNOWLEDGE mode:

<bean name="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
    <property name="connectionFactory" ref="connectionFactory" />
    <property name="sessionAcknowledgeModeName" value="CLIENT_ACKNOWLEDGE" />
    <property name="sessionTransacted" value="true" />
</bean>

so C2 should acknowledge messages manually:

@Override
@Transactional
public void onMessage(Message message) 
{
    try 
    {
        messageHandlerService.handleReceivedMessage(message);
        message.acknowledge();
    } 
    catch (DeserializeXmlException e) 
    {
        // TODO log
        e.printStackTrace();
    }   
    catch (InvalidMessageException e) 
    {
        //TODO log
        e.printStackTrace();
    }
    catch (JMSException e) 
    {
        //TODO log
        e.printStackTrace();
    }   
}

My questions:

  • What will happen to a message, when Client C2 received that message, but crashes before acknowledge it?
  • Is there any timeout mechanism? if yes,What is default timeout for acknowledgment? how can i modify it?
1

1 Answers

5
votes

Any non acked message will be sent back to the queue upon a customer close or rollback.

In case of a crashed server, the message will be re-delivered if it's non-persistent as if nothing happened.

Notice that the system could crash at the time you called ack but before the ack actually reached the server.

The ack timeout is configured through changing callTimeout on the connection factory.

Notice that if you have two resources to update and want to guarantee a single commit between the ack and your database insert (or whatever you're doing next), then you need to perform XA Transactions to guarantee both branches will be committed.

The message will be resent after a crash. You need XA if you need 100% guarantee of that receipt.