Hi,

I'm wondering if this is because your send method isn't closing the
producer and the session? I did try your code and I saw the issue. I turned
it into an example, and added an Arquillian test:
https://github.com/apache/tomee/pull/578

Note that I added the session, producer and consumer into the
try-with-resources block so they are auto-closed at the end of the method.

Can you take a look and let me know what you think?

Jon

On Fri, Sep 27, 2019 at 6:05 PM Ihsan Ecemis <miece...@gmail.com> wrote:

>
> Hello Everyone,
>
> We recently upgraded our staging environment from TomEE 8.0.0-M3 to 8.0.0
> and things started to break.
>
> After some troubleshooting, we realized that we cannot dequeue JMS
> messages from our ActiveMQ server using MessageConsumers.
>
>
> We dequeue messages in 2 different ways:  We use MessageDriven beans for
> most of our queues.  But with some others, we periodically poll by creating
> a MessageConsumer (please see the code below for that second case)
>
> MessageDriven beans work without any problems but we cannot receive any
> messages via MessageConsumers.  That same backend code is working fine with
> 8.0.0-M3.
>
>
> We tested this with different versions of ActiveMQ server (5.15.6, 5.15.9,
> 5.15.10) but TomEE  8.0.0 did not work with any of them.
>
>
> Below is redacted code snippets showing where we have the problem.
>
> Any help will be greatly appreciated.   Please let me know if you have any
> questions about our setup.
>
> Thanks,
>
> Ihsan.
>
>
>
> @Stateless
> public class LogService {
>
>     @EJB
>     private CustomJmsService customJmsService;
>
>     @javax.ejb.Schedule(second = "*/30", minute = "*", hour = "*")
>     public void pollLogQueue() throws Exception {
>         final TextMessage logMessage =
> customJmsService.receiveLogMessage(1000);
>         if (logMessage != null) {
>             persistLogMessages(logMessages);
>         }
>     }
> }
>
> @Stateless
> public class CustomJmsService {
>
>     @Resource(name = "logQueue")
>     private Queue logQueue;
>
>     public void sendLogMessage(final LogMessage message) {
>         sendMessage(logQueue, message);
>     }
>
>     private void sendMessage(final Queue queue, final CustomJmsMessage
> message) {
>         try (final Connection connection =
> connectionFactory.createConnection()) {
>             connection.start();
>
>             final Session session = connection.createSession(true,
> Session.AUTO_ACKNOWLEDGE);
>             final MessageProducer producer = session.createProducer(queue);
>             final String serializedMessage =
> CustomJsonProvider.toJson(message);
>             final Message jmsMessage =
> session.createTextMessage(serializedMessage);
>
>             // This enqueues messages successfully with both 8.0.0-M3 and
> 8.0.0
>             producer.send(jmsMessage);
>         } catch (final Exception e) {
>             throw new RuntimeException("Caught exception from JMS when
> sending a message", e);
>         }
>     }
>
>     public TextMessage receiveLogMessage(final long receiveTimeoutMillis) {
>         return receiveMessage(logQueue, receiveTimeoutMillis);
>     }
>
>     private TextMessage receiveMessage(final Queue queue, final long
> receiveTimeoutMillis) {
>         try (final Connection connection =
> connectionFactory.createConnection()) {
>             connection.start();
>
>             final Session session = connection.createSession(true,
> Session.AUTO_ACKNOWLEDGE);
>             final MessageConsumer messageConsumer =
> session.createConsumer(queue);
>             final Message jmsMessage =
> messageConsumer.receive(receiveTimeoutMillis);
>
>             // PROBLEM: jmsMessage is always null with 8.0.0. This was
> working with 8.0.0-M3
>             if (jmsMessage == null) {
>                 return null;
>             }
>
>             return (TextMessage) jmsMessage;
>         } catch (final Exception e) {
>             throw new RuntimeException("Caught exception from JMS when
> receiving a message", e);
>         }
>     }
> }
>
>
>

Reply via email to