Java JMS MessageListener onMessage在某些PC上运行,但在其他PC上不运行
我正在寻找关于Java软件应用程序的这个奇怪问题的见解。应用程序从网站下载并进行通信 在发布/订阅模型中使用JMS/JBOSS的internet服务器。从高层次上讲,问题是在我们的许多Windows 7 PC(64位Win7操作系统,JRE 1.7.0_51-b13 32位)上,客户机应用程序不接收从服务器发送的消息。onMessage()方法似乎未被调用 令人沮丧的是,在我们的一些PC上(使用Ghost硬盘映像部署,因此理论上应该具有相同的配置),应用程序确实收到了消息——我们可以看到onMessage()方法按预期工作 我能够检查进入PC的TCP/IP流量,并且可以看到从服务器到客户端TCP/IP堆栈的消息。但不知何故,有一些东西阻止消息触发JavaOnMessage处理程序 另一个非常奇怪的情况是,如果让客户机应用程序运行20分钟,它会突然开始接收消息(即onMessage()方法被触发)。我们再次知道,它一直在通过查看TCP/IP流量来获取消息 我们正在使用的代码的基本概要如下所示。我认为它基本上遵循了这里的示例,并且具有大多数类似的元素。如对进一步调试或探索有任何建议,将不胜感激Java JMS MessageListener onMessage在某些PC上运行,但在其他PC上不运行,java,jboss,jms,publish-subscribe,Java,Jboss,Jms,Publish Subscribe,我正在寻找关于Java软件应用程序的这个奇怪问题的见解。应用程序从网站下载并进行通信 在发布/订阅模型中使用JMS/JBOSS的internet服务器。从高层次上讲,问题是在我们的许多Windows 7 PC(64位Win7操作系统,JRE 1.7.0_51-b13 32位)上,客户机应用程序不接收从服务器发送的消息。onMessage()方法似乎未被调用 令人沮丧的是,在我们的一些PC上(使用Ghost硬盘映像部署,因此理论上应该具有相同的配置),应用程序确实收到了消息——我们可以看到onMe
public class MyPubSub {
private static final String CONN_FACTORY_QUEUE = "jms/RemoteConnectionFactory";
private static final String QUEUE_A = "jms/queue/QueueA";
private static final String CONN_FACTORY_TOPIC = "jms/RemoteConnectionFactory";
private static final String USERNAME = "xyz";
private static final String PWD = "xyz123";
public static void main(String[] args)
{
String hostURL = "some_host_string_thing_here";
String remotingURL = "remote://"+hostURL+":4447";
// Establish context
Context ctx;
QueueConnectionFactory qcf = null;
Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
p.put(Context.PROVIDER_URL, remotingURL);
p.put(Context.SECURITY_PRINCIPAL, USERNAME);
p.put(Context.SECURITY_CREDENTIALS, PWD);
ctx = new InitialContext(p);
// Set up Queue
QueueConnectionFactory qcf = null;
QueueConnection qconn = null;
QueueSession qsession = null;
Queue queueA = null;
QueueReceiver qrecv = null;
qcf = (QueueConnectionFactory)ctx.lookup(CONN_FACTORY_QUEUE);
qconn = qcf.createQueueConnection(USERNAME, PWD);
qsession = qconn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
messageProducer = qsession.createProducer(queueA);
// Set up Topic
TopicConnectionFactory tcf;
TopicConnection connA = null;
TopicSession sessionA = null;
Topic topicA = null;
TopicSubscriber recvA;
tcf = (TopicConnectionFactory)ctx.lookup(CONN_FACTORY_TOPIC);
topicA = (Topic)ctx.lookup(TOPICA);
connA = tcf.createTopicConnection(USERNAME, PWD);
connA.setExceptionListener(new ExceptionListenerImpl());
sessionA = connA.createTopicSession(false, TopicSession.AUTO_ACKNOWLEDGE);
messageProducerA = sessionA.createProducer(getJmsDestination(TOPICA));
recvA = sessionA.createSubscriber(topicA);
// Associate the MessageListener ExListenerA()
recvA.setMessageListener(new ExListenerA());
// Start
connA.start();
}
public class ExListenerA implements MessageListener {
public void onMessage(Message msg) {
TextMessage oo = (TextMessage) msg;
System.out.println("Got message" + oo.getText());
}
}
}
设置消息侦听器后,连接不会启动。这可能会导致问题。我编辑了这个示例-我们确实调用connA.start();(我第一次复制并粘贴代码时错过了)-谢谢