简体   繁体   English

activemq故障转移连接不起作用

[英]activemq failover connection not working

I am trying to use this following code to connect to tcp://datafeeds.networkrail.co.uk:61619 to receive messages. 我正在尝试使用下面的以下代码连接到tcp://datafeeds.networkrail.co.uk:61619以接收消息。 The code works fine without failover (using url1 from the following code), but when I tried to add a failover feature (use url from the following code) the connection keep failing. 该代码可以正常工作而无需故障转移(使用以下代码中的url1),但是当我尝试添加故障转移功能(使用以下代码中的url)时,连接仍然会失败。 Seems from the debug info, activemq fails to lookup INetAddress for the URI. 从调试信息看来,activemq无法为URI查找INetAddress。 What is the INetAddress and what could be causing the problem? 什么是INetAddress,可能是什么原因引起的? I am more than confused now. 我现在很困惑。 Could anyone please shed some light on how to solve this issue please? 有人可以请您阐明如何解决此问题吗?

Best regards, 最好的祝福,

Here is the code: 这是代码:

import javax.jms.*;

import org.apache.activemq.ActiveMQConnection;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.log4j.BasicConfigurator;

public class Consumer {
 // URL of the JMS server
 private static String url = "failover://(tcp://datafeeds.networkrail.co.uk:61619)";
 private static String url1 = "tcp://datafeeds.networkrail.co.uk:61619";
 private static String username = "my username";
 private static String password = "my password";
 private static String topic = "*";

 public static void main(String[] args) throws JMSException {
  BasicConfigurator.configure();
  // Getting JMS connection from the server
  ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(url);
  Connection connection = connectionFactory.createConnection(username,password);
   connection.start();
  Session session = connection.createSession(false,
    Session.AUTO_ACKNOWLEDGE);
  Destination destination = session.createTopic(topic);

  MessageConsumer consumer = session.createConsumer(destination);

    while (true)
    {
        //System.out.println("Waiting for message...");
        Message message = consumer.receive();
        if (message != null && message instanceof TextMessage) {
            TextMessage txtMsg = (TextMessage)message;
            System.out.println("Received: " + txtMsg.getText());
        }
    }
    //System.out.println("Closing connection");
    //consumer.close();
    //session.close();
    //connection.close();

}}

Here is the debug info from activemq. 这是来自activemq的调试信息。

0 [main] DEBUG org.apache.activemq.thread.TaskRunnerFactory  - Initialized TaskRunnerFactory[ActiveMQ Task] using ExecutorService: java.util.concurrent.ThreadPoolExecutor@471ed915[Running, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0]
2 [main] DEBUG org.apache.activemq.transport.failover.FailoverTransport  - Reconnect was triggered but transport is not started yet. Wait for start to connect the transport.
135 [main] DEBUG org.apache.activemq.transport.failover.FailoverTransport  - Started unconnected
135 [main] DEBUG org.apache.activemq.transport.failover.FailoverTransport  - Waking up reconnect task
137 [ActiveMQ Task-1] DEBUG org.apache.activemq.transport.failover.FailoverTransport  - urlList connectionList:[tcp://datafeeds.networkrail.co.uk:61619], from: [tcp://datafeeds.networkrail.co.uk:61619]
214 [ActiveMQ Task-1] DEBUG org.apache.activemq.transport.failover.FailoverTransport  - Attempting  0th  connect to: tcp://datafeeds.networkrail.co.uk:61619
284 [ActiveMQ Task-1] DEBUG org.apache.activemq.transport.WireFormatNegotiator  - Sending: WireFormatInfo { version=10, properties={MaxFrameSize=9223372036854775807, CacheSize=1024, CacheEnabled=true, SizePrefixDisabled=false, MaxInactivityDurationInitalDelay=10000, TcpNoDelayEnabled=true, MaxInactivityDuration=30000, TightEncodingEnabled=true, StackTraceEnabled=true}, magic=[A,c,t,i,v,e,M,Q]}
291 [ActiveMQ Task-1] DEBUG org.apache.activemq.transport.failover.FailoverTransport  - Connection established
292 [ActiveMQ Task-1] INFO org.apache.activemq.transport.failover.FailoverTransport  - Successfully connected to tcp://datafeeds.networkrail.co.uk:61619
314 [ActiveMQ Transport: tcp://datafeeds.networkrail.co.uk/176.34.248.27:61619@50427] DEBUG org.apache.activemq.transport.InactivityMonitor  - Using min of local: WireFormatInfo { version=10, properties={MaxFrameSize=9223372036854775807, CacheSize=1024, CacheEnabled=true, SizePrefixDisabled=false, MaxInactivityDurationInitalDelay=10000, TcpNoDelayEnabled=true, MaxInactivityDuration=30000, TightEncodingEnabled=true, StackTraceEnabled=true}, magic=[A,c,t,i,v,e,M,Q]} and remote: WireFormatInfo { version=9, properties={CacheSize=1024, MaxFrameSize=9223372036854775807, CacheEnabled=true, SizePrefixDisabled=false, TcpNoDelayEnabled=true, MaxInactivityDurationInitalDelay=10000, MaxInactivityDuration=30000, TightEncodingEnabled=true, StackTraceEnabled=true}, magic=[A,c,t,i,v,e,M,Q]}
317 [ActiveMQ Transport: tcp://datafeeds.networkrail.co.uk/176.34.248.27:61619@50427] DEBUG org.apache.activemq.transport.WireFormatNegotiator  - Received WireFormat: WireFormatInfo { version=9, properties={CacheSize=1024, MaxFrameSize=9223372036854775807, CacheEnabled=true, SizePrefixDisabled=false, TcpNoDelayEnabled=true, MaxInactivityDurationInitalDelay=10000, MaxInactivityDuration=30000, TightEncodingEnabled=true, StackTraceEnabled=true}, magic=[A,c,t,i,v,e,M,Q]}
318 [ActiveMQ Transport: tcp://datafeeds.networkrail.co.uk/176.34.248.27:61619@50427] DEBUG org.apache.activemq.transport.WireFormatNegotiator  - tcp://datafeeds.networkrail.co.uk/176.34.248.27:61619@50427 before negotiation: OpenWireFormat{version=10, cacheEnabled=false, stackTraceEnabled=false, tightEncodingEnabled=false, sizePrefixDisabled=false, maxFrameSize=9223372036854775807}
373 [ActiveMQ Transport: tcp://datafeeds.networkrail.co.uk/176.34.248.27:61619@50427] DEBUG org.apache.activemq.transport.WireFormatNegotiator  - tcp://datafeeds.networkrail.co.uk/176.34.248.27:61619@50427 after negotiation: OpenWireFormat{version=9, cacheEnabled=true, stackTraceEnabled=true, tightEncodingEnabled=true, sizePrefixDisabled=false, maxFrameSize=9223372036854775807}
445 [ActiveMQ Transport: tcp://datafeeds.networkrail.co.uk/176.34.248.27:61619@50427] DEBUG org.apache.activemq.transport.failover.FailoverTransport  - Waking up reconnect task
747 [ActiveMQ Task-2] ERROR org.apache.activemq.transport.failover.FailoverTransport  - Failed to Lookup INetAddress for URI[ nio://ec2netrailprodmaster1:61619 ] : java.net.UnknownHostException: ec2netrailprodmaster1
748 [ActiveMQ Task-2] DEBUG org.apache.activemq.transport.failover.FailoverTransport  - Doing rebalance from: tcp://datafeeds.networkrail.co.uk:61619 to [nio://ec2netrailprodmaster1:61619]
774 [ActiveMQ Task-2] DEBUG org.apache.activemq.util.ThreadPoolUtils  - Shutdown of ExecutorService: java.util.concurrent.ThreadPoolExecutor@1d60498d[Terminated, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0] is shutdown: true and terminated: true took: 0.001 seconds.
776 [ActiveMQ Task-2] DEBUG org.apache.activemq.transport.tcp.TcpTransport  - Stopping transport tcp://datafeeds.networkrail.co.uk/176.34.248.27:61619@50427
777 [ActiveMQ Task-2] DEBUG org.apache.activemq.thread.TaskRunnerFactory  - Initialized TaskRunnerFactory[ActiveMQ Task] using ExecutorService: java.util.concurrent.ThreadPoolExecutor@4d1793dc[Running, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0]
779 [ActiveMQ Task-1] DEBUG org.apache.activemq.transport.tcp.TcpTransport  - Closed socket Socket[addr=datafeeds.networkrail.co.uk/176.34.248.27,port=61619,localport=50427]
779 [ActiveMQ Task-2] DEBUG org.apache.activemq.util.ThreadPoolUtils  - Forcing shutdown of ExecutorService: java.util.concurrent.ThreadPoolExecutor@4d1793dc[Running, pool size = 1, active threads = 0, queued tasks = 0, completed tasks = 1]
780 [ActiveMQ Task-2] DEBUG org.apache.activemq.transport.failover.FailoverTransport  - Waiting 10 ms before attempting connection. 
803 [ActiveMQ Task-2] DEBUG org.apache.activemq.transport.failover.FailoverTransport  - Attempting  0th  connect to: nio://ec2netrailprodmaster1:61619
804 [ActiveMQ Task-2] DEBUG org.apache.activemq.transport.failover.FailoverTransport  - Connect fail to: nio://ec2netrailprodmaster1:61619, reason: java.net.UnknownHostException
804 [ActiveMQ Task-2] DEBUG org.apache.activemq.transport.tcp.TcpTransport  - Stopping transport nio://ec2netrailprodmaster1:61619
804 [ActiveMQ Task-2] DEBUG org.apache.activemq.thread.TaskRunnerFactory  - Initialized TaskRunnerFactory[ActiveMQ Task] using ExecutorService: java.util.concurrent.ThreadPoolExecutor@7e7ee722[Running, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0]
805 [ActiveMQ Task-1] DEBUG org.apache.activemq.transport.tcp.TcpTransport  - Closed socket Socket[unconnected]
805 [ActiveMQ Task-2] DEBUG org.apache.activemq.util.ThreadPoolUtils  - Forcing shutdown of ExecutorService: java.util.concurrent.ThreadPoolExecutor@7e7ee722[Running, pool size = 1, active threads = 0, queued tasks = 0, completed tasks = 1]
805 [ActiveMQ Task-2] DEBUG org.apache.activemq.transport.failover.FailoverTransport  - Waiting 10 ms before attempting connection
815 [ActiveMQ Task-2] DEBUG org.apache.activemq.transport.failover.FailoverTransport  - Waiting 20 ms before attempting connection. 
835 [ActiveMQ Task-2] DEBUG org.apache.activemq.transport.failover.FailoverTransport  - Attempting  1th  connect to: nio://ec2netrailprodmaster1:61619
835 [ActiveMQ Task-2] DEBUG org.apache.activemq.transport.failover.FailoverTransport  - Connect fail to: nio://ec2netrailprodmaster1:61619, reason: java.net.UnknownHostException
835 [ActiveMQ Task-2] DEBUG org.apache.activemq.transport.tcp.TcpTransport  - Stopping transport nio://ec2netrailprodmaster1:61619
835 [ActiveMQ Task-2] DEBUG org.apache.activemq.thread.TaskRunnerFactory  - Initialized TaskRunnerFactory[ActiveMQ Task] using ExecutorService: java.util.concurrent.ThreadPoolExecutor@e1ddc89[Running, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0]
836 [ActiveMQ Task-1] DEBUG org.apache.activemq.transport.tcp.TcpTransport  - Closed socket Socket[unconnected]
836 [ActiveMQ Task-2] DEBUG org.apache.activemq.util.ThreadPoolUtils  - Forcing shutdown of ExecutorService: java.util.concurrent.ThreadPoolExecutor@e1ddc89[Running, pool size = 1, active threads = 0, queued tasks = 0, completed tasks = 1]
836 [ActiveMQ Task-2] DEBUG org.apache.activemq.transport.failover.FailoverTransport  - Waiting 20 ms before attempting connection
856 [ActiveMQ Task-2] DEBUG org.apache.activemq.transport.failover.FailoverTransport  - Waiting 40 ms before attempting connection. 
896 [ActiveMQ Task-2] DEBUG org.apache.activemq.transport.failover.FailoverTransport  - Attempting  2th  connect to: nio://ec2netrailprodmaster1:61619`enter code here`

尝试使用

private static String url = "failover:(tcp://datafeeds.networkrail.co.uk:61619)";

Old issue I know but we just fell foul of it so thought I share the answer.... 我知道老问题,但我们只是犯规,所以以为我同意答案。

When ActiveMQ is installed as a cluster you configure your clients to connect as follows: 当ActiveMQ作为群集安装时,您可以配置客户端以如下方式进行连接:

private static String url = "failover://(tcp://datafeeds.networkrail.co.uk:61619)";

Periodically, ActiveMQ sends responses to connected clients to disconnect and re-establish the connection. ActiveMQ会定期向连接的客户端发送响应,以断开连接并重新建立连接。 You can see this in the following log: 您可以在以下日志中看到它:

748 [ActiveMQ Task-2] DEBUG org.apache.activemq.transport.failover.FailoverTransport - Doing rebalance from: tcp://datafeeds.networkrail.co.uk:61619 to [nio://ec2netrailprodmaster1:61619] 748 [ActiveMQ任务2]调试org.apache.activemq.transport.failover.FailoverTransport-进行重新平衡:从tcp://datafeeds.networkrail.co.uk:61619到[nio:// ec2netrailprodmaster1:61619]

The unpleasantness occurs here when ActiveMQ tells the client to rebalance and sends it back the nio://ec2netrailprodmaster1:61619 uri which can't be reached. 当ActiveMQ告诉客户端重新平衡并将其发送回无法nio://ec2netrailprodmaster1:61619nio://ec2netrailprodmaster1:61619 uri时,就会出现不愉快的情况。

So, the correct fix is to edit the ActiveMQ configuration. 因此,正确的解决方法是编辑ActiveMQ配置。 For the above problem there will be something like this : 对于上述问题,将出现以下内容:

<transportConnectors>
    <transportConnector name="openwire" uri="nio://ec2netrailprodmaster1:61619?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"  rebalanceClusterClients="true"/>
</transportConnectors>  

Which should be changed to something like this: 应该将其更改为以下内容:

<transportConnectors>
    <transportConnector name="openwire" uri="tcp://datafeeds.networkrail.co.uk:61619?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"  rebalanceClusterClients="true"/>
</transportConnectors> 

Or more specifically the transportConnector uri should be set to the host of the ActiveMQ instance. 更具体地说,应该将transportConnector uri设置为ActiveMQ实例的主机。

Old Thread, but i recently had this problem and it maybe of help to someone else. 旧线程,但我最近有这个问题,可能对其他人有帮助。

The solution for me was to find the ip address of datafeeds.networkrail.co.uk. 对我来说,解决方案是找到datafeeds.networkrail.co.uk的IP地址。 For me it was 54.247.175.93. 对我来说是54.247.175.93。

Then add this to your hosts file, as ec2netrailprodmaster1. 然后将其作为ec2netrailprodmaster1添加到您的主机文件中。

So it looks like. 所以看起来像。

54.247.175.93     ec2netrailprodmaster1

And my full failover URL looks like so. 我的完整故障转移URL看起来像这样。

failover:(tcp://datafeeds.networkrail.co.uk:61619)?initialReconnectDelay=1000&amp;maxReconnectDelay=60000&amp;warnAfterReconnectAttempts=2&amp;"

More Info: On Google Groups 更多信息: 在Google网上论坛上

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

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