【问题标题】:How to connect programmatically to an embedded HornetQ server如何以编程方式连接到嵌入式 HornetQ 服务器
【发布时间】:2012-10-04 15:37:39
【问题描述】:

按照嵌入式 HornetQ Core 的示例,我在 OSGI 容器上运行嵌入式 HornetQ 服务器。

我有三个 OSGI 容器:一个用于服务器,一个用于生产者,最后一个用于消费者。一切都在本地运行。

我在生产者和消费者中用于连接服务器的代码如下:

// Step 4. As we are not using a JNDI environment we instantiate the objects directly
ServerLocator serverLocator = HornetQClient.createServerLocatorWithoutHA(new TransportConfiguration(NettyConnectorFactory.class.getName()));
ClientSessionFactory sf = serverLocator.createSessionFactory();

我试过查看TransportConfiguration 方法,但没有找到setter。

【问题讨论】:

    标签: java osgi hornetq


    【解决方案1】:

    您需要将参数传递给传输配置:

    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("port", org.hornetq.core.remoting.impl.netty.TransportConstants
                          .DEFAULT_PORT);
    parameters.put(TransportConstants.HOST_PROP_NAME, "127.0.0.1");
    
    TransportConfiguration configuration = new TransportConfiguration(
            NettyConnectorFactory.class.getName(), parameters);
    

    请注意,您已经/可以对NettyAcceptor 执行相同的操作。我不确定你是如何在测试中配置接受器的。但我希望你能明白。

    【讨论】:

    • 我根本没有配置接受器。目前我只是在玩弄 HornetQ,而一位同事对 ActiveMQ 做同样的事情,所以我们可以比较它们。我会尝试答案,稍后再回来接受它。
    • 既然您接受了答案,我认为它解决了您的问题。如果您有任何问题,请告诉我。在这里或 HornetQ 用户论坛
    • 是的,我的问题已经解决了,谢谢。我也很确定我们会在项目中使用 HornetQ,所以在不久的将来会出现更多问题。
    猜你喜欢
    • 2019-11-16
    • 2011-10-06
    • 2016-01-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-11
    相关资源
    最近更新 更多