识别ActiveMQ异步消息失败?

时间:2016-02-17 12:19:41

标签: activemq

我有ActiveMQ持久队列,由于性能,我使用异步模式发布到生产者。

 ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(brokerURL);
 factory.setUseAsyncSend(true);
 PooledConnectionFactory connectionFactory = new PooledConnectionFactory(factory);
 Connection connection = connectionFactory.createConnection();
 connection.start();
 Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
 MessageProduer producer = session.createProducer(destination);
 Queue queue = session.createQueue(qName);
 producer.send(queue, message);

有没有办法注册处理程序以获取producer.send()方法的错误/成功?

1 个答案:

答案 0 :(得分:2)

似乎jms 1.1规范不允许在send方法中注册回调而jms 2.0允许它(http://www.oracle.com/technetwork/articles/java/jms2messaging-1954190.html)。由于ActiveMq基于jms 1.1,因此没有注册回调的标准方法。但ActvieMQ javax.jms.MessageProducer实现org.apache.activemq.ActiveMQMessageProducer允许注册回调,我用它来创建我的解决方案(但遗憾的是我不得不放弃PooledConnectionFactory,因为无法从org.apache.activemq.ActiveMQMessageProducer获取PooledConnectionFactory ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(brokerURL); factory.setUseAsyncSend(true); Connection connection = connectionFactory.createConnection(); connection.start(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageProduer producer = session.createProducer(destination); Queue queue = session.createQueue(qName); ((ActiveMQMessageProducer)producer).send(queue, message, new AsyncCallback() { @Override public void onSuccess() { } @Override public void onException(JMSException exception) { } };); 方法。

// Using CFAttributedStringGetString as an example
// but I am asking about *any* GET rule function

CFStringRef * str = CFAttributedStringGetString(...);
CFRetain(str);