我在Liberty 18.0.0.2上使用JavaEE8。
我像这样(server.xml)设置jms激活配置:
<messagingEngine>
<queue id="application" />
</messagingEngine>
<jmsActivationSpec id="app/appMDB">
<properties.wasJms destinationRef="java:app/onlineQueue" />
</jmsActivationSpec>
这是我简单的MDB消息侦听器:
@MessageDriven(
name = "appMDB",
mappedName = "java:app/onlineQueue",
activationConfig = {
@ActivationConfigProperty(propertyName = "destinationType",
propertyValue = "javax.jms.Queue"),
@ActivationConfigProperty(propertyName = "destination",
propertyValue = "java:app/onlineQueue")
}
)
public class ApplicationMessageListener implements MessageListener {
...
}
我也定义了两个这样的队列:
@Stateless
@JMSDestinationDefinitions(
value = {
@JMSDestinationDefinition(
name = "java:app/onlineQueue",
interfaceName = "javax.jms.Queue",
destinationName = "application"),
@JMSDestinationDefinition(
name = "java:app/offlineQueue",
interfaceName = "javax.jms.Queue",
destinationName = "application")
}
)
public class MessageService {
@Inject
private Logger logger;
@Resource(lookup = "java:app/onlineQueue")
private Queue onlineQueue;
@Resource(lookup = "java:app/offlineQueue")
private Queue offlineQueue;
@Inject
private JMSContext context;
@EJB
private MessageUtils messageUtils;
public void sendToOnlineQueue(SimpleMessage simpleMessage) {
TextMessage message = messageUtils.createTextMessage(simpleMessage);
logger.info("Send online Message : " + simpleMessage);
JMSProducer producer = context.createProducer();
producer.send(onlineQueue, message);
}
public void sendToOfflineQueue(SimpleMessage simpleMessage) {
TextMessage message = messageUtils.createTextMessage(simpleMessage);
logger.info("Send offline Message : " + simpleMessage);
JMSProducer producer = context.createProducer();
producer.send(offlineQueue, message);
}
}
我的问题是MDB监听多个队列。
我想让mdb只听onlineQueue。
如何解决这个问题?
答案 0 :(得分:1)
您有两个不同的@JMSDestinationDefinition
。一个具有name
的{{1}},另一个具有java:app/onlineQueue
的名称。但是,他们两个都具有java:app/offlineQueue
的应用程序,这对我来说似乎是错误的。无论您在JNDI中查找destinationName
还是java:app/onlineQueue
,都将得到对名为java:app/offlineQueue
的目的地的引用。几乎可以肯定,这就是为什么发送到application
的邮件被MDB接收的原因。