简体   繁体   中英

ActiveMQ-CPP - message redelivery delay do not get applied

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?

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.

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());
}

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM