In my server log I can see occasionally exceptions like:
Aug 11, 2015 10:13:34 AM org.apache.activemq.broker.TransportConnection serviceTransportException
WARNING: Transport Connection to: tcp://127.0.0.1:55472 failed: java.io.EOFException
Those do not seem to be actual events or messages send to the queue. They just happen randomly.
This is with ActiveMQ on Tomcat/Tomee
The code that configures ActiveMQ is:
My ActiveMQ configuration is very simple:
<?xml version="1.0" encoding="UTF-8"?>
<tomee>
<!-- see http://tomee.apache.org/containers-and-resources.html -->
<!-- activate next line to be able to deploy applications in apps -->
<!-- <Deployments dir="apps" /> -->
<Resource id="MyJmsResourceAdapter" type="ActiveMQResourceAdapter">
BrokerXmlConfig = broker:(tcp://localhost:61616)
ServerUrl = tcp://localhost:61616
</Resource>
<Resource id="MyJmsConnectionFactory" type="javax.jms.ConnectionFactory">
ResourceAdapter = MyJmsResourceAdapter
</Resource>
</tomee>
And to define the Queue I have a simple code:
@Resource(name = "myQueue")
private Queue barQueue;
@Resource
private ConnectionFactory connectionFactory;
/**
* Push Message to Queue
*
* @param payload
* @throws JMSException
*/
private void pushToQueue(Serializable payload) throws JMSException {
Connection connection = connectionFactory.createConnection();
connection.start();
// Create a Session
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
// Create a MessageProducer from the Session to the Topic or Queu
MessageProducer producer = session.createProducer(barQueue);
producer.setDeliveryMode(DeliveryMode.PERSISTENT);
// Create a message
ObjectMessage message = session.createObjectMessage(payload);
// Tell the producer to send the message
producer.send(message);
connection.close();
}
I can see messages fine in the log.
I just randomly see this EOFException popping up.
And it happens without me adding any messages to the queue.
This is usually caused by the client not cleaning up connections properly. Calling connection.close() is not complete. Also, the bit about the port number being different than 61616 is the client-specific port number of the port-pair.
The best practice for JMS connection clean up:
} finally {
if(producer != null) {
try { producer.close(); } catch (JMSException e) { log.. bad thing }
}
if(session != null) {
try { session.close(); } catch (JMSException e) { log.. bad thing }
}
if(connection != null) {
try { connection.close(); } catch (JMSException e) { log.. bad thing }
}
producer = null;
session = null;
connection = null;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With