ActiveMQ Redelivery Police only for a Message Container

时间:2015-07-31 19:41:18

标签: java jms policy jms-topic

In this piece of code I'm trying to set up a redelivery police only only for the messages in a specific topic:

    RedeliveryPolicy redeliveryPolicy = new RedeliveryPolicy();
    emailByFolioRedeliveryPolicy.setInitialRedeliveryDelay(5000);
    emailByFolioRedeliveryPolicy.setRedeliveryDelay(5000);
    emailByFolioRedeliveryPolicy.setUseExponentialBackOff(false);
    emailByFolioRedeliveryPolicy.setBackOffMultiplier(10);
    emailByFolioRedeliveryPolicy.setMaximumRedeliveries(3);

    PooledConnectionFactory connPool = new PooledConnectionFactory();
    ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616");

    RedeliveryPolicyMap redeliveryPolicyMap = connectionFactory.getRedeliveryPolicyMap();
    redeliveryPolicyMap.put(new ActiveMQTopic("VirtualTopic.firstTopic"), redeliveryPolicy );

    connPool.setConnectionFactory(connectionFactory);
    connPool.setCreateConnectionOnStartup(true);
    connPool.setMaxConnections(20);
    return connPool;

The problem is that the messages being sent to another topic (VirtualTopic.secondTopic) are also impacted for this policy, because I can see the listener on the second topic is processing redelivered messages. In the RedeliveryPolicyMap I'm adding the policy specifying the Destination. But for some reason I can not get it working as expected.

The expected is:

  • A new message A is posted to "VirtualTopic.firstTopic"
  • A new message B is posted to "VirtualTopic.secondTopic"
  • The listener "Consume.FIRST.VirtualTopic.firstTopic" on "VirtualTopic.firstTopic" will process the message A.
  • The listener "Consume.SECOND.VirtualTopic.firstTopic" on "VirtualTopic.secondTopic" will process the message B.
  • If the FIRST listener fails, will retry in 15 minutes.
  • If the SECOND listener fails, nothing happens. The message will end up in the Dead Letter Queue.

I took the configuration from this page:

http://activemq.apache.org/redelivery-policy.html

Does anybody has accomplished something like this? Thanks.

1 个答案:

答案 0 :(得分:0)

Policies are set at the ActiveMQConnectionFactory or ActiveMQConnection level - if your policies are different, you need to use different connection factories in your project accordingly. In the case you mentioned, you need to define 2 seperate ActiveMQ connection factories with their own redelivery policies. Hope it helps