繁体   English   中英

连接失败到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();
}

我使用的是带有默认配置的独立式全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();
}

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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