简体   繁体   English

JMS 1.1 持久订阅 - 无法设置客户端 ID

[英]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:

  • if I don't set the clientID, I get a "clientID cannot be null" error...如果我不设置 clientID,我会收到“clientID 不能为空”错误...
  • if I try to set it, I get: com.ibm.msg.client.jms.DetailedIllegalStateException: JMSCC3031: A client ID cannot be set after connection has been used.如果我尝试设置它,我会得到: com.ibm.msg.client.jms.DetailedIllegalStateException: JMSCC3031:使用连接后无法设置客户端 ID。 The client ID of a connection can be set only once, and only before the connection is used.一个连接的客户端 ID 只能设置一次,并且只能在使用该连接之前设置。 Set the client ID before using the connection.在使用连接之前设置客户端 ID。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM