无法创建持久订户(Glassfish 4)

时间:2014-02-02 22:32:40

标签: jms glassfish-4

我正在尝试测试glassfish 4上的持久订阅,但收到错误。代码:

Session session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
TopicSubscriber subscriber = session.createDurableSubscriber((Topic) context.lookup("jms/Topic"), "testDurableSubName");
subscriber.setMessageListener(this);
con.start();

错误是:

creating a topic subscriber ....
Feb 02, 2014 11:19:38 PM org.hibernate.validator.internal.util.Version <clinit>
INFO: HV000001: Hibernate Validator 5.0.0.Final
Feb 02, 2014 11:19:38 PM com.sun.messaging.jms.ra.ResourceAdapter start
INFO: MQJMSRA_RA1101: GlassFish MQ JMS Resource Adapter: Version:  5.0  (Build 14-e) Compile:  April 12 2013 0104
Feb 02, 2014 11:19:38 PM com.sun.messaging.jms.ra.ResourceAdapter start
INFO: MQJMSRA_RA1101: GlassFish MQ JMS Resource Adapter starting: broker is REMOTE, connection mode is TCP
Feb 02, 2014 11:19:38 PM com.sun.messaging.jms.ra.ResourceAdapter start
INFO: MQJMSRA_RA1101: GlassFish MQ JMS Resource Adapter Started:REMOTE
javax.jms.IllegalStateException: [C4053]: Invalid client ID - ""
closing jms connection...
    at com.sun.messaging.jmq.jmsclient.UnifiedSessionImpl.checkClientIDWithBroker(UnifiedSessionImpl.java:699)
    at com.sun.messaging.jmq.jmsclient.UnifiedSessionImpl.createDurableSubscriber(UnifiedSessionImpl.java:440)
    at com.sun.messaging.jmq.jmsclient.UnifiedSessionImpl.createDurableSubscriber(UnifiedSessionImpl.java:330)
    at com.sun.messaging.jms.ra.SessionAdapter.createDurableSubscriber(SessionAdapter.java:339)

1 个答案:

答案 0 :(得分:2)

忘记在连接上设置clientid,例如con.setClientID(InetAddress.getLocalHost().getHostName());

持久订阅者需要连接才能设置ClientID。它可以是任何唯一的字符串,例如主题名称+使用者ID。做出这个改变后,它起作用了。