Uploaded image for project: 'TomEE'
  1. TomEE
  2. TOMEE-2781

ActiveMQ producer not closed or destroyed

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Blocker
    • Resolution: Auto Closed
    • 8.0.0-Final, 8.0.1
    • None
    • TomEE Core Server
    • None

    Description

      Hello,

      This issue is linked to TOMEE-2770.

      We have the same kind of issue.

      Sample to repoduce the issue:

      @Stateless

      @Path("v1/notifications")

      public class NotificationResource {

      public static final String QUEUE_NAME = "jms/myQueue";

       

      @Resource(name = QUEUE_NAME)

      private Queue messageQueue;

       

      @Resourceprivate ConnectionFactory connectionFactory;

       

      @GET

      @Path("downloadInfo")

       public Response postDownloadInfoJMS() {

          try (final Connection connection = connectionFactory.createConnection()) {
              final Session session = connection.createSession();
              final MessageProducer messageProducer = session.createProducer(messageQueue);
              messageProducer.setDeliveryMode(DeliveryMode.PERSISTENT);


              final Message message = session.createTextMessage("Test");

             messageProducer.send(message);
             System.out.println("Message sent !");
          } catch (JMSException e) {        e.printStackTrace();     }

       return Response.accepted().build();

       }

      }

       

      And a beans.xml with bean-discovery-mode="all".

       

      Then perform several GET calls with a browser and you will see the number of Producer increasing (1 per call).

       

      We have the same issue if we change the postDownloadInfoJMS method implementation by:

          Connection connection = null;

          try {

             try {

                 connection = connectionFactory.createConnection();
                 final Session session = connection.createSession();
                 final MessageProducer messageProducer = session.createProducer(messageQueue);
                 messageProducer.setDeliveryMode(DeliveryMode.PERSISTENT);


                 final Message message = session.createTextMessage("Test");

                 messageProducer.send(message);
                System.out.println("Message sent !");
             } finally {

               connection.close();

             }

          } catch (JMSException e) {        e.printStackTrace();     }

       return Response.accepted().build();

       }

      }

       

      The only way to fix that is, in the finally bock to close everything

      messageProducer.close();
      session.close();

      connection.close();

       

      But it's not acceptable because the try with resource should work and closing a connection, as per spec, should close message producers and sessions. 

       

       Best Regards.

       

       

       

       

      Attachments

        Activity

          People

            Unassigned Unassigned
            fcourtau François Courtault
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: