JBOSS EAP 6.2 中嵌入的 HornetQ 主题连接失败
Connection Failure to a HornetQ topic embedded in a JBOSS EAP 6.2
我正在尝试远程连接到在 JBOSS EAP 6.2 中嵌入的 HornetQ 上配置的主题。我尝试了不同的方法来这样做,但都给了我同样的错误:
javax.jms.JMSException: Failed to create session factory
at org.hornetq.jms.client.HornetQConnectionFactory.createConnectionInternal(HornetQConnectionFactory.java:676)
at org.hornetq.jms.client.HornetQConnectionFactory.createTopicConnection(HornetQConnectionFactory.java:196)
at TesteTags.main(TesteTags.java:82)
Caused by: HornetQConnectionTimedOutException[errorType=CONNECTION_TIMEDOUT message=HQ119013: Timed out waiting to receive cluster topology. Group:null]
at org.hornetq.core.client.impl.ServerLocatorImpl.createSessionFactory(ServerLocatorImpl.java:950)
at org.hornetq.jms.client.HornetQConnectionFactory.createConnectionInternal(HornetQConnectionFactory.java:672)
... 2 more
我遵循了此快速入门中的信息:Jboss Eap Quickstart: helloworld-jms
按照我的代码:
try {
final Properties env = new Properties();
env.put(Context.INITIAL_CONTEXT_FACTORY,"org.jboss.naming.remote.client.InitialContextFactory");
env.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
env.put(Context.PROVIDER_URL, "remote://localhost:4447");
env.put(Context.SECURITY_PRINCIPAL, "testuser");
env.put(Context.SECURITY_CREDENTIALS, "testpassword");
Context context = new InitialContext(env);
TopicConnectionFactory factory = (TopicConnectionFactory) context.lookup("jms/RemoteConnectionFactory");
Topic topic = (Topic) context.lookup("jms/topic/myTopic");
Connection connection = factory.createTopicConnection("testuser", "testpassword"); // The Error occurred here
connection.start();
Session session = connection.createSession(false, TopicSession.AUTO_ACKNOWLEDGE);
MessageProducer producer = session.createProducer(topic);
Message message = session.createTextMessage("My Test Message");
producer.send(message);
System.out.println("It Worked!");
} catch (Exception e) {
System.out.println("It Failed!");
e.printStackTrace();
}
我正在使用默认配置的 standalone-full-ha 配置文件。
我的代码有问题吗?或者是否有任何不同于我必须做的默认配置?
您是否使用与您正在使用的 JBoss EAP 版本相同的 HornetQ 库编译了您的客户端代码?你要知道,有一个版本兼容性问题,不允许不同的HornetQ版本互操作。
经过大量的研究和测试,我解决了这个问题。首先,我将 jboss-as-jms-client-bom-7.2.0 的依赖更改为:
<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-jms-client-bom</artifactId>
<version>7.1.2.Final</version>
<type>pom</type>
</dependency>
此外,我更改了代码以使用这种不同的方法连接到服务器:
Connection connection = null;
Session session = null;
Formatter formatter = new Formatter();
Map<String, Object> connectionParams = new HashMap<String, Object>();
connectionParams.put(TransportConstants.PORT_PROP_NAME, 5445);
connectionParams.put(TransportConstants.HOST_PROP_NAME, "localhost");
TransportConfiguration transportConfiguration = new TransportConfiguration(
NettyConnectorFactory.class.getName(), connectionParams);
try {
HornetQConnectionFactory cf = HornetQJMSClient
.createConnectionFactoryWithHA(JMSFactoryType.CF, transportConfiguration);
connection = cf.createConnection("testuser", "testpassword");
connection.start();
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Topic topicTarifas = session.createTopic("tarifas.01101");
MessageProducer producer = session.createProducer(topicTarifas);
Message message = session.createTextMessage("My Test Message");
producer.send(message);
System.out.println("It Worked!");
} catch (Exception e) {
System.out.println("It Failed!");
e.printStackTrace();
}
希望这对其他人有用:)
我正在尝试远程连接到在 JBOSS EAP 6.2 中嵌入的 HornetQ 上配置的主题。我尝试了不同的方法来这样做,但都给了我同样的错误:
javax.jms.JMSException: Failed to create session factory
at org.hornetq.jms.client.HornetQConnectionFactory.createConnectionInternal(HornetQConnectionFactory.java:676)
at org.hornetq.jms.client.HornetQConnectionFactory.createTopicConnection(HornetQConnectionFactory.java:196)
at TesteTags.main(TesteTags.java:82)
Caused by: HornetQConnectionTimedOutException[errorType=CONNECTION_TIMEDOUT message=HQ119013: Timed out waiting to receive cluster topology. Group:null]
at org.hornetq.core.client.impl.ServerLocatorImpl.createSessionFactory(ServerLocatorImpl.java:950)
at org.hornetq.jms.client.HornetQConnectionFactory.createConnectionInternal(HornetQConnectionFactory.java:672)
... 2 more
我遵循了此快速入门中的信息:Jboss Eap Quickstart: helloworld-jms
按照我的代码:
try {
final Properties env = new Properties();
env.put(Context.INITIAL_CONTEXT_FACTORY,"org.jboss.naming.remote.client.InitialContextFactory");
env.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
env.put(Context.PROVIDER_URL, "remote://localhost:4447");
env.put(Context.SECURITY_PRINCIPAL, "testuser");
env.put(Context.SECURITY_CREDENTIALS, "testpassword");
Context context = new InitialContext(env);
TopicConnectionFactory factory = (TopicConnectionFactory) context.lookup("jms/RemoteConnectionFactory");
Topic topic = (Topic) context.lookup("jms/topic/myTopic");
Connection connection = factory.createTopicConnection("testuser", "testpassword"); // The Error occurred here
connection.start();
Session session = connection.createSession(false, TopicSession.AUTO_ACKNOWLEDGE);
MessageProducer producer = session.createProducer(topic);
Message message = session.createTextMessage("My Test Message");
producer.send(message);
System.out.println("It Worked!");
} catch (Exception e) {
System.out.println("It Failed!");
e.printStackTrace();
}
我正在使用默认配置的 standalone-full-ha 配置文件。
我的代码有问题吗?或者是否有任何不同于我必须做的默认配置?
您是否使用与您正在使用的 JBoss EAP 版本相同的 HornetQ 库编译了您的客户端代码?你要知道,有一个版本兼容性问题,不允许不同的HornetQ版本互操作。
经过大量的研究和测试,我解决了这个问题。首先,我将 jboss-as-jms-client-bom-7.2.0 的依赖更改为:
<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-jms-client-bom</artifactId>
<version>7.1.2.Final</version>
<type>pom</type>
</dependency>
此外,我更改了代码以使用这种不同的方法连接到服务器:
Connection connection = null;
Session session = null;
Formatter formatter = new Formatter();
Map<String, Object> connectionParams = new HashMap<String, Object>();
connectionParams.put(TransportConstants.PORT_PROP_NAME, 5445);
connectionParams.put(TransportConstants.HOST_PROP_NAME, "localhost");
TransportConfiguration transportConfiguration = new TransportConfiguration(
NettyConnectorFactory.class.getName(), connectionParams);
try {
HornetQConnectionFactory cf = HornetQJMSClient
.createConnectionFactoryWithHA(JMSFactoryType.CF, transportConfiguration);
connection = cf.createConnection("testuser", "testpassword");
connection.start();
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Topic topicTarifas = session.createTopic("tarifas.01101");
MessageProducer producer = session.createProducer(topicTarifas);
Message message = session.createTextMessage("My Test Message");
producer.send(message);
System.out.println("It Worked!");
} catch (Exception e) {
System.out.println("It Failed!");
e.printStackTrace();
}
希望这对其他人有用:)