[英]JMS 1.1 durable subscription - can't set Client ID
I am trying to setup a durable subscription with JMS 1.1 but I get in a Catch 22:我正在尝试使用 JMS 1.1 设置持久订阅,但我遇到了 Catch 22:
How do I solve this?我该如何解决这个问题? How do I make the connection 'unused'?
如何使连接“未使用”? Or - as the exception message suggests - how do I set the ID before I use the connection?
或者 - 正如异常消息所暗示的 - 如何在使用连接之前设置 ID?
My code snippet:我的代码片段:
public class BbsListener implements MessageListener {
...
public BbsListener(BbsListenerConfig config) {
try {
Context context = new InitialContext();
TopicConnectionFactory topicConnectionFactory = (TopicConnectionFactory) context.lookup(config.getConnectionFactoryName());
TopicConnection topicConnection = topicConnectionFactory.createTopicConnection();
topicConnection.setClientID("ID");
TopicSession topicSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
Topic topic = (Topic) context.lookup(config.getTopicName());
topicSubscriber = topicSession.createDurableSubscriber(topic, "EAMPtestSubscriber");
topicSubscriber.setMessageListener(this);
topicConnection.start();
}
...
Thank you谢谢
It looks like your app is running on a Java EE application server.看起来您的应用程序正在 Java EE 应用程序服务器上运行。 If that's the case you'll need to be careful about what kind of connection factory you use and where you invoke
setMessageListener()
.如果是这种情况,您需要小心使用哪种连接工厂以及在何处调用
setMessageListener()
。 First, an "outbound" connection factory is meant to be used for sending messages (hence the name "outbound").首先,“出站”连接工厂旨在用于发送消息(因此得名“出站”)。 This is part of JCA.
这是 JCA 的一部分。 Second, you can't call
setMessageListener()
in an EJB as that's not allowed by spec.其次,您不能在 EJB 中调用
setMessageListener()
,因为这是规范所不允许的。 I recommend you just use a normal JMS connection factory rather than a pooled one from the application server.我建议您只使用普通的 JMS 连接工厂,而不是来自应用服务器的池化连接工厂。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.