0

I am using ActiveMQ-CPP 3.4.5 to connect from C++ program to message broker. The problem I encountered is connected with redelivery policy. Messages which are returned to queue are redelivered immediately. This is not the behaviour I expect. I would expect the messages to be returned after certain period of time which is set through redelivery policy.

This is a code snipped showing the way I set up redelivery policy:

policy = new activemq::core::policies::DefaultRedeliveryPolicy();

policy->setInitialRedeliveryDelay(0);
policy->setRedeliveryDelay(10000);
policy->setMaximumRedeliveries((int)activemq::core::RedeliveryPolicy::NO_MAXIMUM_REDELIVERIES);

connectionFactory.setRedeliveryPolicy(policy);

As I said before I would except the messages to be redelivered after 10000 ms, but the are not. They come back to consumer immediately.

Does anyone know what could be the reason of such behaviour?

Damian
  • 593
  • 6
  • 27

2 Answers2

0

You set the initial delay to zero so they are going to be redelivered immediately the first time a transaction is rolled back. If you want them to be delayed on the first redelivery cycle then you need to set the initial delay to 10000 as well.

Tim Bish
  • 17,475
  • 4
  • 32
  • 42
  • Tim, I have tried setting intitial delay to 10000 but it did not help. Messages still arrive immediately. – Damian Mar 20 '13 at 14:10
0

When I looked into ActiveMQ-CPP sources I found the following code snippet in ActiveMQConsumer.cpp file:

if( internal->redeliveryDelay > 0 && !this->internal->unconsumedMessages->isClosed() ) {
// TODO - Can't do this until we can control object lifetime.
// Start up the delivery again a little later.
// this->internal->scheduler->executeAfterDelay(
//    new StartConsumerTask(this), internal->redeliveryDelay);
    start();
} else {
    start();
}

So it seems that redeliveryDelay is not taken into account after rollback at all. That is why, I suppose, my messages arrive immediately after rollback.

onMessage method:

void BaseProdListener::onMessage( const cms::Message* message ){    
log4cxx::Logger::getLogger("BaseProdListener")->info("onMessage");

_message = message;

try {
    const cms::TextMessage* textMessage = dynamic_cast< const cms::TextMessage* >( message );
    std::string text = "";
    if( textMessage != NULL ) {
        text = textMessage->getText();
        log4cxx::Logger::getLogger("BaseProdListener")->debug("Received message:" + text);
        handleMessage(text);
    }
} catch (cms::CMSException& e){
    log4cxx::Logger::getLogger("BaseProdListener")->error(e.getStackTraceString());
}

}

Damian
  • 593
  • 6
  • 27
  • Upgrade to the latest version and you shouldn't have these issues. – Tim Bish Mar 21 '13 at 10:21
  • Yeah, I know Tim. I've seen in 3.5.0 and 3.6.0 sources that it should work properly. Unfortunately I cannot upgrade because after upgrading my application stops working. I get an exception in my listener in onMessage function. I have no clue what is the reason of that exception. When I switch back to 3.4.5 everything works all right. I addded onMessage method listing to my answer. Exception seems to be thrown at the following line: text = textMessage->getText(); – Damian Mar 21 '13 at 12:18
  • There's user groups, jira, etc. All you have to do is put together a test case and ask to get some help. – Tim Bish Mar 21 '13 at 13:36