我正在为 JMS 使用 jbossall-client jar,并且我是消息传递的新手。每当我尝试浏览向其发送消息(其对象消息)的队列时,我的 qBrowser.getEnumeration().hasMoreElements();
这就是我创建连接的方式:
public void initialize() throws Exception {
try {
InitialContext initialContext = new InitialContext(contextProperties);
connectionFactory = (QueueConnectionFactory) initialContext.lookup(connectionFactoryName);
queue = (Queue) initialContext.lookup("queue/" + queueName);
initialContext.close();
} catch (NamingException e) {
throw new Exception("Error initializing enqueuer for " + queueName, e);
}
}
public MyQueueConnection openQueueConnection() throws JMSException {
QueueConnection connection = null;
try {
connection = connectionFactory.createQueueConnection();
connection.start();
QueueSession session = connection.createQueueSession(true, QueueSession.DUPS_OK_ACKNOWLEDGE);
QueueSender sender = session.createSender(queue);
sender.setDeliveryMode(DeliveryMode.PERSISTENT);
return new MyQueueConnection(connection, session, sender);
} catch (JMSException e) {
throw e;
}
}
我是否需要使用 QueueConnection/QueueSession/QueueSender 或其他配置来浏览队列中的消息?我需要在 jboss 属性中配置什么吗? (我在单例MDB中执行此操作;该项目是一个Spring框架项目)
请指教;提前致谢。
最佳答案
只是对另一个的建议。 我用的是hornetQ
- 请检查您在调用 getEnumeration() 之后创建的 QueueReceiver createReceiver()。
- 确保启动连接connection.start()
关于java - jms queuebrowser # getEnumeration 总是获取为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28318698/