You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by "turing85 (via GitHub)" <gi...@apache.org> on 2025/07/29 15:57:42 UTC

[I] Integration of beans annotated with @Identifier only partially works [camel-quarkus]

turing85 opened a new issue, #7558:
URL: https://github.com/apache/camel-quarkus/issues/7558

   ### Bug description
   
   Support for beans annotated with `@Identifier(...)` instead of `@Named(...)` was added in https://github.com/apache/camel-quarkus/issues/4374.
   
   This integration only partially works. As of now, it is unclear whether this is a regression, or never fully worked.
   
   ---
   
   A case that works:
   - application uses `quarkus-artemis` and `camel-quarkus-jms`
   - application defines a connection factory programmatically through a `@Produces` method:
   ```java
   public class ConnectionFactoryProducer {
     public static final String EXTERNALLY_DEFINED = "externally-defined";
   
     @Produces
     @Identifier(EXTERNALLY_DEFINED)
     @Unremovable
     public ConnectionFactory createConnectionFactory(
         @ConfigProperty(name = "quarkus.artemis.url") String url) {
       return new ActiveMQConnectionFactory(url);
     }
   }
   ```
   - both connection factories are used in camel routes:
   ```java
   public class JmsRoutes extends RouteBuilder {
     @Override
     public void configure() {
       // @formatter:off
       from(jms("default").connectionFactory(ArtemisUtil.DEFAULT_CONFIG_NAME))
           .log("body: ${body}");
       from(jms("external").connectionFactory(ConnectionFactoryProducer.EXTERNALLY_DEFINED))
           .log("body: ${body}");
       // @formatter:on
     }
   }
   ```
     messages send to queue `default` and `externally-defined` are received (verified with JMSToolBox)
   
   ---
   
   A case that does not work:
   - application defines an interface `Greeter`:
   ```java
   public interface Greeter {
     String greet();
   }
   ```
   -  one implementation `HelloGreeter` of said interface:
   ```java
   public class HelloGreeter implements Greeter {
     @Override
     public String greet() {
       return "Hello";
     }
   }
   ```
   - and a `@Produces`-method for `HelloGreeter`:
   ```java
   public class GreeterProducer {
     public static final String NAME_HELLO_GREETER = "hello-greeter";
   
     @Produces
     @Singleton
     @Identifier(NAME_HELLO_GREETER)
     public Greeter helloGreeter() {
       Log.info("Hello greeter initialized");
       return new HelloGreeter();
     }
   }
   ```
   - Route `GreeterRoute` looks up the `Greeter`-instance by its name programmatically:
   ```java
   public class GreeterRoute extends RouteBuilder {
     public static final String HTTP_PATH = "/hello";
     public static final String ROUTE_ID = "hello";
   
     @Override
     public void configure() {
       // @formatter:off
       from(
           platformHttp(HTTP_PATH)
               .httpMethodRestrict("GET"))
           .id(ROUTE_ID)
           .setBody(exchange -> Objects.requireNonNull(exchange.getContext().getRegistry()
                   .findByTypeWithName(Greeter.class)
                   .get(GreeterProducer.NAME_HELLO_GREETER))
               .greet());
       // @formatter:on
     }
   }
   ```
   - When the route is triggered, the `Objects.requireNonNull(...)`, wrapping the registry lookup, throws a `NullPointerException`
   - Debugging the route by setting a breakpoint in the processor and calling `exchange.getContext().getRegistry().findByTypeWithName(Greeter.class)` shows that a map with a single entry is returned. The key of the entry, however is `null` instead of `GreeterProducer.NAME_HELLO_GREETER` (`= "hello-greeter"`)
   
   - If we replace `@Identifier` in `GreeterProducer` with `@Named`, everything works as expected. The following patch can be applied to realize this change:
   ```diff
   Subject: [PATCH] Switch from @Identifier to @Named
   ---
   Index: src/main/java/de/turing85/quarkus/camel/identifier/GreeterProducer.java
   IDEA additional info:
   Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
   <+>UTF-8
   ===================================================================
   diff --git a/src/main/java/de/turing85/quarkus/camel/identifier/GreeterProducer.java b/src/main/java/de/turing85/quarkus/camel/identifier/GreeterProducer.java
   --- a/src/main/java/de/turing85/quarkus/camel/identifier/GreeterProducer.java	(revision 54c79975f55301b0f98adba59a6aaf18ed566819)
   +++ b/src/main/java/de/turing85/quarkus/camel/identifier/GreeterProducer.java	(date 1753804135797)
   @@ -1,17 +1,17 @@
    package de.turing85.quarkus.camel.identifier;
    
    import jakarta.enterprise.inject.Produces;
   +import jakarta.inject.Named;
    import jakarta.inject.Singleton;
    
    import io.quarkus.logging.Log;
   -import io.smallrye.common.annotation.Identifier;
    
    public class GreeterProducer {
      public static final String NAME_HELLO_GREETER = "hello-greeter";
    
      @Produces
      @Singleton
   -  @Identifier(NAME_HELLO_GREETER)
   +  @Named(NAME_HELLO_GREETER)
      public Greeter helloGreeter() {
        Log.info("Hello greeter initialized");
        return new HelloGreeter();
   ```
   
   ---
   
   The sample code can be found [here (`github.com`)](https://github.com/turing85/quarkus-camel-identifier). The project holds a test for the `GretterRoute`.
   
   Furthermore, the devmode is configured to pin the artemis port on the host to `61616`, so if you want to play around with the setup, you can connect your JMS tool to `localhost:61616`, username `artemis`, password `artemis`.
   
   The issue exists at least since quarkus `3.8.4`.
   
   ---
   
   Relevant zulip chat discussions:
   - [For this issue (`camel.zulipchat.com`)](https://camel.zulipchat.com/#narrow/channel/257302-camel-quarkus)
   - [For issue #4374`camel.zulipchat.com`)](https://camel.zulipchat.com/#narrow/channel/257302-camel-quarkus/topic/Supporting.20.40Identifier.20annotation.20for.20named.20beans/with/319190010)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Integration of beans annotated with @Identifier only partially works [camel-quarkus]

Posted by "jamesnetherton (via GitHub)" <gi...@apache.org>.
jamesnetherton commented on issue #7558:
URL: https://github.com/apache/camel-quarkus/issues/7558#issuecomment-3135882528

   > Can we get this downstreamed to the current lts versions (quarkus 3.15 and 3.20)?
   
   Backport for 3.20.x should be ok. Unless you **_really_** need it for 3.15.x, I'd prefer to not backport there, given that the bean registry code has diverged a lot compared to `main`.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Integration of beans annotated with @Identifier only partially works [camel-quarkus]

Posted by "turing85 (via GitHub)" <gi...@apache.org>.
turing85 commented on issue #7558:
URL: https://github.com/apache/camel-quarkus/issues/7558#issuecomment-3135994191

   > > Can we get this downstreamed to the current lts versions (quarkus 3.15 and 3.20)?
   > 
   > Backport for 3.20.x should be ok. Unless you **_really_** need it for 3.15.x, I'd prefer to not backport there, given that the bean registry code has diverged a lot compared to `main`.
   
   okay, backporting to just 3.20 is fine by me 🙂 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Integration of beans annotated with @Identifier only partially works [camel-quarkus]

Posted by "turing85 (via GitHub)" <gi...@apache.org>.
turing85 commented on issue #7558:
URL: https://github.com/apache/camel-quarkus/issues/7558#issuecomment-3133141181

   /cc @jamesnetherton 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Integration of beans annotated with @Identifier only partially works [camel-quarkus]

Posted by "jamesnetherton (via GitHub)" <gi...@apache.org>.
jamesnetherton closed issue #7558: Integration of beans annotated with @Identifier only partially works
URL: https://github.com/apache/camel-quarkus/issues/7558


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Integration of beans annotated with @Identifier only partially works [camel-quarkus]

Posted by "turing85 (via GitHub)" <gi...@apache.org>.
turing85 commented on issue #7558:
URL: https://github.com/apache/camel-quarkus/issues/7558#issuecomment-3135738984

   Thanks @jamesnetherton for the fast fix 🙂
   Can we get this downstreamed to the current lts versions (quarkus 3.15 and 3.20)?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org