欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

记录activeMQ [doReconnect,1100] - Failed to connect to after: 10 attempt(s) continuing to retr

程序员文章站 2024-03-13 09:18:33
...

业务:
通过activeMQ发送消息,发送不成功进行告警发送消息。
但是由于不成功一直重试机制导致获取不到异常信息。

  private static final String BROKEURL = "failover:(tcp://1:61616,tcp://2:61616,tcp://3:61616)?randomize=false"
    ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(USERNAME, PASSWORD, BROKEURL);
    Connection connection = connectionFactory.createConnection();
    Session session = connection.createSession( Boolean.TRUE, Session.AUTO_ACKNOWLEDGE );
    Destination topic = session.createTopic( "TOPIC.UPLOAD.OTC" );
    MessageProducer producer = session.createProducer( topic );
    producer.setDeliveryMode( DeliveryMode.PERSISTENT );
    connection.start();

    TextMessage message = session.createTextMessage( messageContent );
    producer.send( message );
    session.commit();
    session.close();
    connection.close();

代码一致循环尝试重连,异常也不抛出,本地是抛出异常进行微信告警通知的。

log信息:

15:51:52.341 [ActiveMQ Task-1] ERROR o.a.a.t.f.FailoverTransport - [doReconnect,1080] - Failed to connect to [tcp://:61616, tcp://:61616, tcp://:61616] after: 10 attempt(s)
15:51:52.341 [ActiveMQ Task-1] ERROR o.a.a.t.f.FailoverTransport - [doReconnect,1080] - Failed to connect to [tcp://:61616, tcp://:61616, tcp://:61616] after: 20 attempt(s)

后修改failover为,加入参数startupMaxReconnectAttempts:

private static final String BROKEURL = “failover:(tcp://192.168.152.207:61616,tcp://192.168.152.208:61616,tcp://192.168.152.209:61616)?randomize=false&startupMaxReconnectAttempts=10”;

log信息并且成功捕获到异常:

   15:51:52.341 [ActiveMQ Task-1] ERROR o.a.a.t.f.FailoverTransport - [doReconnect,1080] - Failed to connect to [tcp://:61616] after: 10 attempt(s)
javax.jms.JMSException: Connection refused: connect
	at org.apache.activemq.util.JMSExceptionSupport.create(JMSExceptionSupport.java:72)
	at org.apache.activemq.ActiveMQConnection.syncSendPacket(ActiveMQConnection.java:1421)
	at org.apache.activemq.ActiveMQConnection.ensureConnectionInfoSent(ActiveMQConnection.java:1486)
	at org.apache.activemq.ActiveMQConnection.createSession(ActiveMQConnection.java:329)
	at com.airtravel.odb.common.utils.msg.JMSProducer.sendMessages(JMSProducer.java:49)
	at com.airtravel.odb.project.system.service.impl.SendToMoniterServiceImpl.sendMessage(SendToMoniterServiceImpl.java:506)
	at com.airtravel.odb.common.utils.AcrsMq.ActiveMqSendMsgToMonitorService.sendMq(ActiveMqSendMsgToMonitorService.java:83)
	at com.airtravel.odb.common.utils.AcrsMq.QueueListener1.receiveQueueTwo(QueueListener1.java:66)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
相关标签: java java