Does ActiveMQManagedConnection (EAP/AMQ) support Autoclosable?

138 views Asked by At

I am using:

  • openshift
    • AMQ (seems to be a forked activemq-5.11.0.redhat...... version)
  • EAP 7.2.3
  • While local debugging I get as Connection some ~ConnectionProxy with a physical ActiveMQManagedConnection

Can I use "try-with-resources"?

I am not sure and think no ... because ActiveMQManagedConnection 5.11.0 (I dont know what redhat has changed) doesnt implement Autoclosable. Neither does the implemented javax.resource.spi.ManagedConnection

https://github.com/apache/activemq/blob/activemq-5.11.0/activemq-ra/src/main/java/org/apache/activemq/ra/ActiveMQManagedConnection.java#L53

I havent found the source of this EAP ConnectionProxy. Maybe it has Autoclosable.

1

There are 1 answers

0
Justin Bertram On BEST ANSWER

If you're using Red Hat AMQ 6 on OpenShift (which is based on ActiveMQ 5.x) then you're stuck on JMS 1.1. The javax.jms.Connection in JMS 1.1 doesn't extend java.lang.AutoCloseable. Red Hat AMQ 7 (based on ActiveMQ Artemis) implements JMS 2 and the javax.jms.Connection in JMS 2 does extend java.lang.AutoCloseable.

Red Hat JBoss EAP 7.2.3 ships with ActiveMQ Artemis so if you're using that (along with its JCA resource adapter) then you can use try-with-resources. However, if you've configured a JCA resource adapter for integration with a broker based on ActiveMQ 5.x then you can't.