quarkiverse / quarkus-artemis

Quarkus Artemis extensions
Apache License 2.0
12 stars 12 forks source link

NullPointerException while creating shared durable consumer #17

Closed m-sarac closed 2 years ago

m-sarac commented 2 years ago

Hi, I noticed an error when I was doing a migration from Quarkus 2.2.x to 2.6.0.Final. My application creates some shared durable consumers to be able to subscribe on some topics on Artemis server. Here is my consumer creation: context = connectionFactory.createContext(JMSContext.AUTO_ACKNOWLEDGE); Topic topic = context.createTopic("my-topic"); JMSConsumer consumer = context.createSharedDurableConsumer(topic, "subscription");

Auto create queue and auto create topic are already enabled in Artemis server. If the topic (my-topic) is not present yet in Artemis I get this NPE ERROR [io.quarkus.runtime.Application] (Quarkus Main Thread) [] Failed to start application (with profile prod): java.lang.NullPointerException at org.apache.activemq.artemis.jms.client.ActiveMQSession.internalCreateSharedConsumer(ActiveMQSession.java:749) at org.apache.activemq.artemis.jms.client.ActiveMQSession.createSharedDurableConsumer(ActiveMQSession.java:687) at org.apache.activemq.artemis.jms.client.ActiveMQSession.createSharedDurableConsumer(ActiveMQSession.java:667) at org.apache.activemq.artemis.jms.client.ActiveMQJMSContext.createSharedDurableConsumer(ActiveMQJMSContext.java:452)

When I dived into the Artemis client codes, I noticed subResponse.isConfigurationManaged() always returns null since the related parameter is null as a constant in the constructor. if ((!subResponse.isExists() || !Objects.equals(subResponse.getAddress(), dest.getSimpleAddress()) || !Objects.equals(subResponse.getFilterString(), coreFilterString)) && !subResponse.isConfigurationManaged()) {

My application was working on Quarkus 2.2.x version which has artemis-core-client v2.17.0. So I think this is a bug of v2.19.0 but I couldn't find any issue of Artemis about it. Please investigate this, thanks in advance.

middagj commented 2 years ago

I tried to reproduce this with a simple application, but did not succeed. It worked both with Quarkus 2.2.3 (Artemis client 2.17.0) and Quarkus 2.6.0 (Artemis client 2.19.0). Could you perhaps create a small example? Also which Artemis server version are you using? I tested with Artemis server 2.17.0.

m-sarac commented 2 years ago

Artemis server version is 2.10.1. I'll create an example. Thanks.

middagj commented 2 years ago

I also tested with 2.10.1, still no NPE. But I do see now a small difference between 2.17.0 and 2.19.0. The 2.19.0 client does not receive messages from an auto created topic. Most likely this is more an Artemis problem, than a Quarkus one.

m-sarac commented 2 years ago

Hi @middagj, I've created an example project to demonstrate the problem. https://github.com/m-sarac/jms-example You can use the docker command in read.me file to run an Artemis server. When you run the quarkus app you'll see the NPE at startup.

But if you create the topic and a subscription through the Artemis web console (http://localhost:8161/console/login) before running my quarkus app then you'll see the consumer works. image

middagj commented 2 years ago

Thanks, I see now the NPE. Got it also confirmed with Artemis 2.17.0 server. When I switch the client to a 2.17.0 version the NPE is gone. So that might be a workaround for you:

    <dependency>
      <groupId>org.apache.activemq</groupId>
      <artifactId>artemis-jms-client</artifactId>
      <version>2.17.0</version>
    </dependency>
m-sarac commented 2 years ago

Yes, indeed I already applied this workaround :) I think we should inform this bug to Artemis team for a long term solution. Maybe reverting back to 2.17.0 version in quarkus-artemis could be a short term solution for a while. Thanks.

middagj commented 2 years ago

I created a PR upstream. Nothing to do with this extension. I don't think downgrading makes sense as it is a limited use case and there is an easy workaround for those cases.

m-sarac commented 2 years ago

I saw you PR. Thank you for it. I am looking forward to see a new patch including you fix.