java brokelistqueue,Java PolicyEntry.setQueue方法代碼示例

import org.apache.activemq.broker.region.policy.PolicyEntry; //導入方法依賴的package包/類

@Override

public void before() throws Throwable {

log.info("+++ BEFORE on JUnit Rule '" + id(Rule_Mats.class) + "', JMS and MATS:");

String sysprop_matsTestActiveMq = System.getProperty(SYSPROP_MATS_TEST_ACTIVEMQ);

// ::: Server (BrokerService)

// ====================================

// :? Do we have specific brokerUrl to connect to?

if (sysprop_matsTestActiveMq == null) {

// -> No - the system property was not set, hence start the in-vm broker.

log.info("Setting up in-vm ActiveMQ BrokerService '" + BROKER_NAME + "' (i.e. the MQ server).");

_amqServer = new BrokerService();

_amqServer.setBrokerName(BROKER_NAME);

_amqServer.setUseJmx(false); // No need for JMX registry.

_amqServer.setPersistent(false); // No need for persistence (prevents KahaDB dirs from being created).

_amqServer.setAdvisorySupport(false); // No need Advisory Messages.

_amqServer.setUseShutdownHook(false);

// :: Set Individual DLQ

// Hear, hear: http://activemq.2283324.n4.nabble.com/PolicyMap-api-is-really-bad-td4284307.html

PolicyMap destinationPolicy = new PolicyMap();

_amqServer.setDestinationPolicy(destinationPolicy);

PolicyEntry policyEntry = new PolicyEntry();

policyEntry.setQueue(">");

destinationPolicy.put(policyEntry.getDestination(), policyEntry);

IndividualDeadLetterStrategy individualDeadLetterStrategy = new IndividualDeadLetterStrategy();

individualDeadLetterStrategy.setQueuePrefix("DLQ.");

policyEntry.setDeadLetterStrategy(individualDeadLetterStrategy);

_amqServer.start();

}

else {

// -> Yes, there is specified a brokerUrl to connect to, so we

log.info("SKIPPING setup of in-vm ActiveMQ BrokerService (MQ server), since System Property '"

+ SYSPROP_MATS_TEST_ACTIVEMQ + "' was set (to [" + sysprop_matsTestActiveMq + "]).");

}

// ::: Client (ConnectionFactory)

// ====================================

// :: Find which broker URL to use

String brokerUrl;

if (sysprop_matsTestActiveMq == null) {

brokerUrl = "vm://" + BROKER_NAME + "?create=false";

}

else if (SYSPROP_VALUE_LOCALHOST.equals(sysprop_matsTestActiveMq)) {

brokerUrl = "tcp://localhost:61616";

}

else {

brokerUrl = sysprop_matsTestActiveMq;

}

// :: Connect to the broker

log.info("Setting up ActiveMQ ConnectionFactory (MQ client), brokerUrl: [" + brokerUrl + "].");

_amqClient = new ActiveMQConnectionFactory(brokerUrl);

RedeliveryPolicy redeliveryPolicy = _amqClient.getRedeliveryPolicy();

// :: Only try redelivery once, since the unit tests does not need any more to prove that they work.

redeliveryPolicy.setInitialRedeliveryDelay(500);

redeliveryPolicy.setUseExponentialBackOff(false);

redeliveryPolicy.setMaximumRedeliveries(1);

// ::: MatsFactory

// ====================================

log.info("Setting up JmsMatsFactory.");

_matsStringSerializer = new MatsDefaultJsonSerializer();

// Allow for override in specialization classes, in particular the one with DB.

_matsFactory = createMatsFactory(_matsStringSerializer, _amqClient);

// For all test scenarios, it makes no sense to have a concurrency more than 1, unless explicitly testing that.

_matsFactory.getFactoryConfig().setConcurrency(1);

log.info("--- BEFORE done! JUnit Rule '" + id(Rule_Mats.class) + "', JMS and MATS.");

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值