Djarshi
Djarshi

Reputation: 93

ActiveMQ Async sending waiting on all message to be sent

I am using activemq to send messages. Due to the number of messages being sent and the amount of other work the application is sending. I've enabled async sending.

When the application ends I want to be sure the remaining messages are actually delivered as we sometimes miss one of the last messages that go on the connection.

Googling around I found only the warnings that state you might miss some messages well this is acceptable however we miss some of the last ones about 40% of the time. I wish to improve this situation.

Q: Is there any method to check wether the activemq producer/sender has sent all it's async messages?

    ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory( brokerUrl );
    connectionFactory.setUseAsyncSend( true );
    RedeliveryPolicy policy = connectionFactory.getRedeliveryPolicy();
    policy.setInitialRedeliveryDelay( 500 );
    policy.setBackOffMultiplier((short)2);
    policy.setUseExponentialBackOff(true);
    policy.setMaximumRedeliveries(10);

Upvotes: 1

Views: 1874

Answers (1)

Tim Bish
Tim Bish

Reputation: 18421

You could set the async send mode back to off for the last message which would cause the client to wait on the send until the broker acknowledges that the message has been received. The Connection object would need to be cast to ActiveMQConnection and then you can call setUseAsyncSend(false)

Upvotes: 1

Related Questions