2

所以我有一个运行 Spring 堆栈的 tomcat 服务器 (tomcat6)。作为堆栈的一部分,我有一个用于处理消息的 ActiveMQ 嵌入式服务器。我在我的 spring 上下文中配置了代理,如下所示:

<bean id="jmsConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory" 
    p:brokerURL="tcp://localhost:61616" />
<bean id="jmsCachedConnectionFactory" 
    class="org.springframework.jms.connection.CachingConnectionFactory" 
    p:targetConnectionFactory-ref="jmsConnectionFactory"
    p:sessionCacheSize="100" />

<amq:broker id="broker" useJmx="false" persistent="false">
    <amq:transportConnectors>
    <amq:transportConnector uri="tcp://localhost:61616" />
    </amq:transportConnectors>
</amq:broker>

<bean id="jmsDestination" class="org.apache.activemq.command.ActiveMQQueue">
    <constructor-arg value="EDS.PUSHES" />
</bean>

<bean id="jmsMessageProducerTemplate" class="org.springframework.jms.core.JmsTemplate" 
    p:connectionFactory-ref="jmsCachedConnectionFactory"
    p:defaultDestination-ref="jmsDestination" />

<jms:listener-container container-type="default" 
    connection-factory="jmsCachedConnectionFactory" task-executor="pollingExecutor"
    acknowledge="auto" prefetch="5" destination-type="queue" cache="none" concurrency="50-100">
    <jms:listener destination="EDS.PUSHES" ref="pushMessageConsumer" method="onMessage" />
</jms:listener-container>

pushMessageConsumer 只是我的类,它通过 onMessage 方法从队列中读取消息。

jms 服务器会定期报告 EOF Exception:

012-08-09 14:50:02,891 [ActiveMQ Connection Executor: tcp://localhost/127.0.0.1:61616] 
    WARN  org.springframework.jms.connection.CachingConnectionFactory  - Encountered a 
    JMSException - resetting the underlying JMS Connection

javax.jms.JMSException: java.io.EOFException
    at org.apache.activemq.util.JMSExceptionSupport.create(JMSExceptionSupport.java:49)
    at org.apache.activemq.ActiveMQConnection.onAsyncException(ActiveMQConnection.java:1841)
    at org.apache.activemq.ActiveMQConnection.onException(ActiveMQConnection.java:1858)
    at org.apache.activemq.transport.TransportFilter.onException(TransportFilter.java:101)
    at org.apache.activemq.transport.ResponseCorrelator.onException(ResponseCorrelator.java:126)
    at org.apache.activemq.transport.TransportFilter.onException(TransportFilter.java:101)
    at org.apache.activemq.transport.TransportFilter.onException(TransportFilter.java:101)
    at org.apache.activemq.transport.WireFormatNegotiator.onException(WireFormatNegotiator.java:160)
    at org.apache.activemq.transport.InactivityMonitor.onException(InactivityMonitor.java:265)
    at org.apache.activemq.transport.TransportSupport.onException(TransportSupport.java:96)
    at org.apache.activemq.transport.tcp.TcpTransport.run(TcpTransport.java:206)
    at java.lang.Thread.run(Thread.java:679)
Caused by: java.io.EOFException
    at java.io.DataInputStream.readInt(DataInputStream.java:392)
    at org.apache.activemq.openwire.OpenWireFormat.unmarshal(OpenWireFormat.java:269)
    at org.apache.activemq.transport.tcp.TcpTransport.readCommand(TcpTransport.java:227)
    at org.apache.activemq.transport.tcp.TcpTransport.doRun(TcpTransport.java:219)
    at org.apache.activemq.transport.tcp.TcpTransport.run(TcpTransport.java:202)
    ... 1 more
2012-08-09 14:50:02,908 [pollingExecutor-4] WARN  
    org.springframework.jms.listener.DefaultMessageListenerContainer  - Setup of JMS 
    message listener invoker failed for destination 'EDS.PUSHES' - trying to recover.  
    Cause: The Session is closed

然后它重新启动 Tomcat,重新启动我的整个应用程序。我尝试通过更改代理定义并使用 DefaultIOExceptionHandler 添加 bean 来添加 ioExceptionHandler:

<bean id="ioExceptionHandler" class="org.apache.activemq.util.DefaultIOExceptionHandler">
    <property name="ignoreAllErrors"><value>true</value></property>
</bean>

<amq:broker id="broker" useJmx="false" persistent="false" 
    ioExceptionHandler="#ioExceptionHandler">
  <amq:transportConnectors>
    <amq:transportConnector uri="tcp://localhost:61616" />
  </amq:transportConnectors>
</amq:broker>

但是当EOF异常发生时,它会继续重新启动tomcat服务器。我在配置中遗漏了什么吗?

4

0 回答 0