HA になる hornetq コア API と spring を使用して hornetq クライアントを定義しようとしています。しかし、ライブサーバーを停止し、バックアップサーバーが「ライブ」になると、クライアントは接続エラーで失敗します。私が間違っていることは何か分かりますか?
クラスター化されたスタンドアロンの hornetq サーバーを定義しました (グループまたはディスカバリーなし)。hornetq-configuration.xml:
...
<connectors>
<connector name="netty">
<factory-class>org.hornetq.core.remoting.impl.netty.NettyConnectorFactory</factory-class>
<param key="host" value="${hornetq.remoting.netty.host:live-host}"/>
<param key="port" value="${hornetq.remoting.netty.port:5445}"/>
</connector>
<!-- Connector to this server.s backup. This is needed for failback to work properly in a static cluster -->
<connector name="netty-backup">
<factory-class>org.hornetq.core.remoting.impl.netty.NettyConnectorFactory</factory-class>
<param key="host" value="${hornetq.remoting.netty.host:backup-host}"/>
<param key="port" value="${hornetq.remoting.netty.port:5446}"/>
</connector>
<cluster-connections>
<cluster-connection name="my-cluster">
<address>jms</address>
<connector-ref>netty</connector-ref>
<retry-interval>500</retry-interval>
<use-duplicate-detection>true</use-duplicate-detection>
<forward-when-no-consumers>false</forward-when-no-consumers>
<max-hops>1</max-hops>
<static-connectors>
<!-- Without this the connection factory won.t be able to reconnect on failback -->
<connector-ref>netty-backup</connector-ref>
</static-connectors>
</cluster-connection>
...
hornetq クライアントを定義しました。
@Test
public void testHA() throws InterruptedException, IOException{
List<TransportConfiguration> transportConfigurationList = new ArrayList<TransportConfiguration>();
Map<String, Object> transportProperties = new HashMap<String, Object>();
transportProperties.put("host", "live-server");
transportProperties.put("port", 5445);
transportConfigurationList.add(new TransportConfiguration("org.hornetq.core.remoting.impl.netty.NettyConnectorFactory", transportProperties));
transportProperties = new HashMap<String, Object>();
transportProperties.put("host", "backup-server");
transportProperties.put("port", 5446);
transportConfigurationList.add(new TransportConfiguration("org.hornetq.core.remoting.impl.netty.NettyConnectorFactory", transportProperties));
HornetQJMSConnectionFactory connectionFactory = new HornetQJMSConnectionFactory(true, transportConfigurationList.toArray(new TransportConfiguration[2]));
JmsTemplate producer = new JmsTemplate(connectionFactory);
producer.send(new HornetQTopic("deploy"), new MessageCreator() {
@Override
public Message createMessage(Session session) throws JMSException {
TextMessage txtMessage = session.createTextMessage("my message");
return txtMessage;
}
});
System.out.println("Stop live server");
System.in.read();
producer.send(new HornetQTopic("deploy"), new MessageCreator() {
@Override
public Message createMessage(Session session) throws JMSException {
TextMessage txtMessage = session.createTextMessage("my message");
return txtMessage;
}
});
Thread.sleep(60000);
}
出力:
Stop live server
Apr 30, 2012 5:08:32 PM org.hornetq.core.logging.impl.JULLogDelegate warn
WARNING: Tried 1 times to connect. Now giving up on reconnecting it.
さらに、ライブサーバーにはログエラーがあります:
- [Thread-4 (HornetQ-server-HornetQServerImpl::serverUUID=70ca0e65-8ecf-11e1-82e8-d5eac4a07302-1433965066)] 5 月 1 日 8:27:57,976 FINE [ServerLocatorImpl] コネクタ [initialConnector=org-hornetq-core-remoting -impl-netty-NettyConnectorFactory?port=5446&host=10-45-7-150]::コネクターの初期接続確立時の例外 HornetQException[errorCode=2 message=構成 org-hornetq-core-remoting-impl を使用してサーバーに接続できません-netty-NettyConnectorFactory?port=5446&host=backup-server] at org.hornetq.core.client.impl.ClientSessionFactoryImpl.connect(ClientSessionFactoryImpl.java:234) at org.hornetq.core.client.impl.ServerLocatorImpl$StaticConnector$Connector org.hornetq.core.client.impl.ServerLocatorImpl$StaticConnector.connect(ServerLocatorImpl.java:1614) の .tryConnect(ServerLocatorImpl.java:1777)。org.hornetq.core.client.impl.ServerLocatorImpl$3 の core.client.impl.ServerLocatorImpl.connect(ServerLocatorImpl.java:587)。org.hornetq.utils.OrderedExecutorFactory$OrderedExecutor$1 の run(ServerLocatorImpl.java:554)。 run(OrderedExecutorFactory.java:100) で java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) で java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) で java.lang .Thread.run(Thread.java:662)concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) で java.lang.Thread.run(Thread.java:662)concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) で java.lang.Thread.run(Thread.java:662)