ActiveMQ:使用Java配置每个目标策略(总排序)

时间:2011-06-16 19:38:04

标签: configuration jms activemq

我有一个ActiveMQ嵌入式代理,以及一些Topic客户端。目前一切都是用Java(而不是XML)配置的。我想在客户端配置主题消息的总排序。

ActiveMQ将total ordering指定为每个目标策略。有没有办法直接在Java中配置它?

我一直在使用的香草启动代码:

// broker code (single broker)
BrokerService broker = new BrokerService();
broker.addConnector(address);
broker.setPersistent(false);
broker.setUseJmx(false);
broker.start();

// client code (multiple clients)
ActiveMQConnectionFactory connectionFactory 
           = new ActiveMQConnectionFactory(address);
connection = connectionFactory.createConnection();
connection.start();

session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
topic = session.createTopic(topicName);    
producer = session.createProducer(topic);
consumer = session.createConsumer(topic);

1 个答案:

答案 0 :(得分:2)

代码看起来像这样:

    PolicyEntry policy = new PolicyEntry();
    policy.setDispatchPolicy(new StrictOrderDispatchPolicy());

    PolicyMap pMap = new PolicyMap();
    pMap.setDefaultEntry(policy);

    broker.setDestinationPolicy(pMap);