使用InVMConnectorFactory获取HornetQ的ClientSessionFactory

时间:2013-04-16 16:13:02

标签: hornetq

我正在尝试运行HornetQ 2.14最终用户手册中提供的一个示例。下面是我在Servlet中执行的java代码(客户端和服务器都在同一个VM中)....

    TransportConfiguration transportConfiguration = new TransportConfiguration(InVMConnectorFactory.class.getName());

    ServerLocator locator = HornetQClient.createServerLocatorWithoutHA(transportConfiguration);

    ClientSessionFactory factory = locator.createSessionFactory(); //Causing error

[用于创建ClientSessionFactory的Java代码]

以下是 standalone-full.xml ...

中的配置
<acceptors>
   <netty-acceptor name="netty" socket-binding="messaging"/>

   <netty-acceptor name="netty-throughput" socket-binding="messaging-throughput">
    <param key="batch-delay" value="50"/>
    <param key="direct-deliver" value="false"/>
    </netty-acceptor>

   <in-vm-acceptor name="in-vm" server-id="0"/>
</acceptors>

[独立-full.xml]

不幸的是locator.createSessionFactory()抛出异常 -

WARN [org.hornetq.jms.server.recovery.HornetQXAResourceWrapper](定期恢复)恢复时无法连接到任何hornetq服务器  [XARecoveryConfig [hornetQConnectionFactory = HornetQConnectionFactory [serverLocator = ServerLocatorImpl]  [initialConnectors = [org-hornetq-core-remoting-impl-invm-InVMConnectorFactory?server-id = 0],discoveryGroupConfiguration = null],  clientID = null,dupsOKBatchSize = 1048576,transactionBatchSize = 1048576,readOnly = false],username = null,password = null]]

ERROR [stderr](http - 127.0.0.1-8080-1)HornetQException [errorCode = 2 message =无法连接到服务器。尝试使用所有可用的服务器。]

错误[stderr](http - 127.0.0.1-8080-1)位于org.hornetq.core.client.impl.ServerLocatorImpl.createSessionFactory(ServerLocatorImpl.java:774)

错误[stderr](http - 127.0.0.1-8080-1)at test.jms.JMSReceiver.receive1(JMSReceiver.java:150)

错误[stderr](http - 127.0.0.1-8080-1)at test.jms.JMSReceiver.doGet(JMSReceiver.java:48)

错误[stderr](http - 127.0.0.1-8080-1)在javax.servlet.http.HttpServlet.service(HttpServlet.java:734)

错误[stderr](http - 127.0.0.1-8080-1)在javax.servlet.http.HttpServlet.service(HttpServlet.java:847)....续

不确定这有多相关,但在调试源代码时我发现了

  public class InVMConnector implements Connector
  {
       public static final Logger log = Logger.getLogger(InVMConnector.class);

   public InVMConnector(final Map<String, Object> configuration,
                    final BufferHandler handler,
                    final ConnectionLifeCycleListener listener,
                    final Executor closeExecutor,
                    final Executor threadPool)
      {
         this.listener = listener;

        id =    ConfigurationHelper.getIntProperty(TransportConstants.SERVER_ID_PROP_NAME, 0, configuration);
  //Value of id = 0 in my case
        this.handler = handler;

        this.closeExecutor = closeExecutor;

         executorFactory = new OrderedExecutorFactory(threadPool);

         InVMRegistry registry = InVMRegistry.instance;

         acceptor = registry.getAcceptor(id);
     //acceptor is null here for me
       }

    }

[从Hornetq的源代码复制 - 2.14 Final]

由于acceptor = registry.getAcceptor(id)对我来说是空的,所以根本不会尝试创建与服务器的连接。

如果我错过了接受者的任何配置,请告诉我吗?

提前感谢您的帮助。

关于, -ak

0 个答案:

没有答案