Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

org.apache.activemq.broker.TransportConnection serviceTransportException WARNING: java.io.EOFException

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.

like image 722
seba.wagner Avatar asked Nov 09 '22 07:11

seba.wagner


1 Answers

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;
}
like image 130
Matt Pavlovich Avatar answered Nov 14 '22 23:11

Matt Pavlovich