Hi Jonathan,
We do not have a tomee.xml file, we use resources.xml file instead. I pasted
its contents below.
BTW, my previous redacted code snippet omitted the following 2 lines from the
CustomJmsService class:
@Resource(name = "MyJmsConnectionFactory")
private ConnectionFactory connectionFactory;
(in case you wonder where connectionFactory is coming from)
Let me know if you see any problems with our resource configuration.
Thank you,
Ihsan.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<Resource id="j30DatabaseManaged" type="javax.sql.DataSource">
<!-- See http://tomee.apache.org/datasource-config.html for more
options and their meanings -->
jdbcDriver = org.postgresql.Driver
jdbcUrl =
jdbc:postgresql://${database_hostname}:${database_port}/${database_name}${jdbc_ssl_flag}
userName = ${database_username}
password = ${database_password}
</Resource>
<Resource id="MyJmsResourceAdapter" type="ActiveMQResourceAdapter">
# Connect to the external ActiveMQ broker running on localhost:61616
BrokerXmlConfig =
ServerUrl = nio://localhost:61616
</Resource>
<Resource id="MyJmsConnectionFactory" type="javax.jms.ConnectionFactory">
ResourceAdapter = MyJmsResourceAdapter
</Resource>
<Container id="MyJmsMdbContainer" ctype="MESSAGE">
ResourceAdapter = MyJmsResourceAdapter
</Container>
</resources>
> On Sep 30, 2019, at 13:08, Jonathan S. Fisher <[email protected]> wrote:
>
> Also, can you post your tomee.xml?
>
> On Mon, Sep 30, 2019 at 8:14 AM Jonathan Gallimore <
> [email protected]> wrote:
>
>> 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 <[email protected]> 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);
>>> }
>>> }
>>> }
>>>
>>>
>>>
>>
>
>
> --
> Jonathan | [email protected]
> Pessimists, see a jar as half empty. Optimists, in contrast, see it as half
> full.
> Engineers, of course, understand the glass is twice as big as it needs to
> be.