我有一个Spring Boot Application 2.2.6.RELEASE。 我正在使用spring-boot-starter-activemq(active-mq 5.15.12)
我正在尝试将2个代理配置为一个主代理和一个辅助代理:
broker.url: "failover:(tcp://192.168.0.28:61616,tcp://localhost:61616)?randomize=false&priorityBackup=true"
但是,如果主服务器发生故障(我停止了activemq代理),我会遇到异常,并且永远不会切换到辅助服务器
WARN - Transport (tcp://192.168.0.28:61616) failed , attempting to automatically reconnect: {}
java.io.EOFException: null
at java.io.DataInputStream.readInt(DataInputStream.java:392)
at org.apache.activemq.openwire.OpenWireFormat.unmarshal(OpenWireFormat.java:268)
at org.apache.activemq.transport.tcp.TcpTransport.readCommand(TcpTransport.java:240)
at org.apache.activemq.transport.tcp.TcpTransport.doRun(TcpTransport.java:232)
at org.apache.activemq.transport.tcp.TcpTransport.run(TcpTransport.java:215)
at java.lang.Thread.run(Thread.java:748)
如果我在没有主服务器的情况下启动应用程序,然后打开主服务器,则我也会遇到异常,并且不会发送或接收任何消息(即使它说已成功重新连接)
WARN - Transport Connection to: tcp://127.0.0.1:61179 failed: java.io.EOFException
INFO - Successfully reconnected to tcp://192.168.0.28:61616
欢迎任何帮助
答案 0 :(得分:0)
我的问题是我在为日志使用附加器。
public class LogAppender extends AppenderBase<ILoggingEvent> implements CommandLineRunner
此附加程序将日志发布到代理
@Override
protected void append(ILoggingEvent event) {
ServerLogLine log = new ServerLogLine(event);
if (logPublisher != null) {
logPublisher.publish(log);
}
}
但是当代理停止时具有故障转移选项,FailoverTransport类将发送日志:
LOG.warn("Transport ({}) failed {} attempting to automatically reconnect: {}",
connectedTransportURI, (reconnectOk ? "," : ", not"), e);
由于我的LogAppender,该程序在此处阻塞。
LogAppender的init方法纠正:
// Remove log level for activemq
logger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger("org.apache.activemq");
logger.setLevel(Level.toLevel("OFF"));