My application is using ActiveMQ embedded with TomEE Plus-8.0.0-M1.

The behavior of running out of pooled connections is the same regardless of using an explicitly defined javax.jms.ConnectionFactory using resources.xml or letting TomEE generate one on the fly.

Different settings for connection timeout don't seem to have an effect:

connectionMaxIdleTime = 3 seconds
connectionMaxIdleTime = 15 minutes

If ExampleSessionBean.sendMessage() is called 11 times sequentially, Abandoned Connection warnings are logged on messages 1-10. On message #11, the JMSRuntimeException: No Managed Connections Available, is thrown.

Then if I wait a few minutes, the JMSContext producer is able to send again.

My first thought was that the underlying connection in JMSContext needed to be closed with

jmsContext.close();

but from Interface JMSContext

"This method must not be used if the JMSContext is container-managed (injected)."

What programmatic or configuration changes are needed here?

Thank you, Ted S

resources.xml

<?xml version="1.0" encoding="UTF-8"?>
<resources>
    <Resource id="jmsConnectionFactory" type="javax.jms.ConnectionFactory">
        connectionMaxIdleTime = 3 seconds
        connectionMaxWaitTime = 5 seconds
        poolMaxSize = 10
        poolMinSize = 0
        resourceAdapter = Default JMS Resource Adapter
        transactionSupport = xa
    </Resource>
</resources>

ExampleSessionBean.java

@Named
@LocalBean
@Stateless
public class ExampleSessionBean
{

    @Resource(name = "jms/localNotificationQueue")
    private Queue _localNotificationQueue;

    @Inject
    @JMSConnectionFactory("jmsConnectionFactory")
    private JMSContext _jmsContext;

    public void sendMessage(String message) 
    {
        try
        {      
            TextMessage textMessage = 
                _jmsContext.createTextMessage(message);
            _jmsContext.createProducer().
                setDeliveryMode(DeliveryMode.PERSISTENT).
                send(_localNotificationQueue, textMessage);   
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }
}

Warnings - Messages 1-10: (Pardon the formatting. SE formatter won't format this text block for some reason)

Begin Warning Text

WARNING: Transaction complete,
 but connection still has handles associated: ManagedConnectionInfo: ... org.apache.openejb.resource.activemq.jms2.cdi.JMS2CDIExtension$InternalJMSContext.createProducer(JMS2CDIExtension.java:370),
 com.myorg.jms.ExampleSessionBean.sendMessage(ExampleSessionBean.java:46),


...

End Warning Text

Message #11 Exception

javax.jms.JMSRuntimeException: No ManagedConnections available within configured blocking timeout ( 5000 [ms] ) for pool org.apache.geronimo.connector.outbound.SinglePoolConnectionInterceptor@12aff7fa
    at org.apache.openejb.resource.activemq.jms2.JMS2.toRuntimeException(JMS2.java:83)
    at org.apache.openejb.resource.activemq.jms2.JMSContextImpl.connection(JMSContextImpl.java:85)
    at org.apache.openejb.resource.activemq.jms2.JMSContextImpl.session(JMSContextImpl.java:102)
    at org.apache.openejb.resource.activemq.jms2.JMSContextImpl.getInnerProducer(JMSContextImpl.java:124)
    at org.apache.openejb.resource.activemq.jms2.JMSContextImpl.createProducer(JMSContextImpl.java:302)
    at org.apache.openejb.resource.activemq.jms2.cdi.JMS2CDIExtension$InternalJMSContext.createProducer(JMS2CDIExtension.java:370)
    at com.myorg.jms.ExampleSessionBean.sendMessage(ExampleSessionBean.java:46)
...

UPDATE: This behavior has been duplicated and added to the TomEE issues tracker.

1

There are 1 best solutions below

0
On

I gave up on JMSContext & went back to manually managing the connection. All functions as expected even when loading up with 100s of messages.

ExampleSessionBean.java

@Named
@LocalBean
@Stateless
public class ExampleSessionBean
{
    @Resource(name = "jms/localNotificationQueue")
    private Queue _localNotificationQueue;

    @Resource(mappedName = "jmsConnectionFactory")
    private ConnectionFactory _connectionFactory;    

    public void sendMessage(String message) 
    {
        Connection connection = null;
        Session session = null;
        MessageProducer messageProducer = null;
        try
        {      
            connection = 
                    _connectionFactory.createConnection();
            connection.start();
            session =
                    connection.createSession();
            messageProducer =
                    session.createProducer(null);
            messageProducer.setDeliveryMode(DeliveryMode.PERSISTENT);
            TextMessage textMessage = session.createTextMessage(message);
            messageProducer.send(_localNotificationQueue, 
                    textMessage);   
        }
        catch (Exception e)
        {
            // TODO Handle exception
        }
        finally
        {
            if (connection != null)
            {
                try
                {
                    connection.close();
                }
                catch (JMSException e) {}
            }
        }
    }
}