连接失败到JBOSS EAP 6.2中嵌入的HornetQ主题

时间:2016-06-15 20:55:07

标签: java jms hornetq jboss-eap-6

我正在尝试远程连接到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();
}

我使用的是带有默认配置的独立式全ha配置文件。

我在代码上做错了吗?或者我是否有任何与默认配置不同的配置?

2 个答案:

答案 0 :(得分:0)

您是否使用与您正在使用的JBoss EAP版本一起提供的相同HornetQ库编译了客户端代码?您必须知道版本兼容性问题不允许不同HornetQ版本的互操作性。

答案 1 :(得分:0)

经过大量的研究和测试,我解决了这个问题。首先,我将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();
}

希望这可能对其他人有用:)