我正在尝试运行 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]]
错误 [stderr] (http--127.0.0.1-8080-1) HornetQException[errorCode=2 message=无法连接到服务器。尝试了所有可用的服务器。]
org.hornetq.core.client.impl.ServerLocatorImpl.createSessionFactory(ServerLocatorImpl.java:774) 处的错误 [stderr] (http--127.0.0.1-8080-1)
错误 [stderr] (http--127.0.0.1-8080-1) 在 test.jms.JMSReceiver.receive1(JMSReceiver.java:150)
错误 [stderr] (http--127.0.0.1-8080-1) 在 test.jms.JMSReceiver.doGet(JMSReceiver.java:48)
javax.servlet.http.HttpServlet.service(HttpServlet.java:734) 处的错误 [stderr] (http--127.0.0.1-8080-1)
javax.servlet.http.HttpServlet.service(HttpServlet.java:847) 处的错误 [stderr] (http--127.0.0.1-8080-1) .... 继续
不确定这有多相关,但在调试源代码时我发现
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) 对我来说是 null 它根本没有尝试创建与服务器的连接。
如果我缺少接受者的任何配置,请告诉我吗?
提前感谢您的所有帮助。
关于,-ak