You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by GitBox <gi...@apache.org> on 2022/05/19 10:24:44 UTC

[GitHub] [camel-quarkus] jamesnetherton opened a new issue, #3797: Overriding autowirable `DefaultBean` types does not work

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

   The Quarkus Qpid JMS Extension exposes a `ConnectionFactory` `DefaultBean` which can be overridden by users.
   
   If you try to do this in conjunction with the JMS extension, autowiring of the `ConnectionFactory` fails with:
   
   ```
   IllegalArgumentException: connectionFactory must be specified
   ```
   
   And the root cause is that the JMS component cannot figure out which `ConnectionFactory` bean to use:
   
   ```
   Cannot autowire ConnectionFactory as 2 instances found in registry.
   ```
   
   It seems that the Camel registry [lookup](https://github.com/apache/camel-quarkus/blob/ddf4d9fd2d05ec302deb95354da4063f8138b50a/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/RuntimeBeanRepository.java#L44) for the `ConnectionFactory` returns both the original `DefaultBean` instance and the overridden one.
   
   Not sure if that's a bug or intended behavior from the `BeanManager`. I noticed some alternate lookup methods on `Arc.container` and  `BeanManager` correctly return only the overridden bean. 
   


-- 
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


[GitHub] [camel-quarkus] JiriOndrusek commented on issue #3797: Registry lookup for overridden `DefaultBean` types does not work

Posted by GitBox <gi...@apache.org>.
JiriOndrusek commented on issue #3797:
URL: https://github.com/apache/camel-quarkus/issues/3797#issuecomment-1140895767

   This is intended behavior. Quarkus returns `javax.enterprise.inject.spi.BeanManager`. We are calling method [getBeans](https://docs.oracle.com/javaee/7/api/javax/enterprise/inject/spi/BeanManager.html#getBeans-java.lang.String-) from our [lookup](https://github.com/apache/camel-quarkus/blob/ddf4d9fd2d05ec302deb95354da4063f8138b50a/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/RuntimeBeanRepository.java#L44).
   This method functionality is to return all beans which matches requirements.
   
   ```
   Return the set of beans which have the given EL name and are available for injection in the module or library containing the class into which the BeanManager was injected or the Java EE component from whose JNDI environment namespace the BeanManager was obtained, according to the rules of EL name resolution.
   ```
   
   To apply ambiguous dependency resolution (to remove @DefaultBeans), we need to call method [resolve](https://docs.oracle.com/javaee/7/api/javax/enterprise/inject/spi/BeanManager.html#resolve-java.util.Set-) afterwards.
   
   ```
   Apply the ambiguous dependency resolution rules to a set of [beans](https://docs.oracle.com/javaee/7/api/javax/enterprise/inject/spi/Bean.html).
   ``` 
   
   There is a catch, method `resolve` returns only 1 bean - not set (see [code](https://github.com/quarkusio/quarkus/blob/main/independent-projects/arc/runtime/src/main/java/io/quarkus/arc/impl/ArcContainerImpl.java#L583)). There is another method - which is not accessible through the javax interface, which does almost everything we need (see [code](https://github.com/quarkusio/quarkus/blob/main/independent-projects/arc/runtime/src/main/java/io/quarkus/arc/impl/ArcContainerImpl.java#L596)).
   
   I see several options how to solve the problem:
   
   1. In case that we want to solve only `@DefaultBeans`, we should add similar [code](https://github.com/quarkusio/quarkus/blob/main/independent-projects/arc/runtime/src/main/java/io/quarkus/arc/impl/ArcContainerImpl.java#L604-L612) into [RuntimeBeanRepository](https://github.com/jboss-fuse/camel-quarkus/blob/camel-quarkus-2.7.1-product/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/RuntimeBeanRepository.java#L44)
   2. In case we want also consider priorities and alternative beans, we have to incorporate more [code](https://github.com/quarkusio/quarkus/blob/main/independent-projects/arc/runtime/src/main/java/io/quarkus/arc/impl/ArcContainerImpl.java#L614-L630). 
   3. Unfortunately I don't see a way of using existing code from Quarkus. (It is not-public)
   
   From my PoV option 2 should allow users the maximum flexibility.
   We might want to remove only `@DefaultBeans` and possibly `@Alternative`, but i'm not sure about it.
   
   WDYT? @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


[GitHub] [camel-quarkus] JiriOndrusek commented on issue #3797: Registry lookup for overridden `DefaultBean` types does not work

Posted by GitBox <gi...@apache.org>.
JiriOndrusek commented on issue #3797:
URL: https://github.com/apache/camel-quarkus/issues/3797#issuecomment-1140960687

   I think that obvious solution is this one:
   On our lookup methodwe will call `resolve` method form Quarkus, which will remove ambiguous.
   If it fails (there are ambiguous beans),  we will return original set (back compatibility. ensured).
   If it succeeds, we will return set with the only bean which was returned.
   
   -> there will be no need to copy/paste some code and it won't cause any problem


-- 
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


[GitHub] [camel-quarkus] jamesnetherton closed issue #3797: Registry lookup for overridden `DefaultBean` types does not work

Posted by GitBox <gi...@apache.org>.
jamesnetherton closed issue #3797: Registry lookup for overridden `DefaultBean` types does not work
URL: https://github.com/apache/camel-quarkus/issues/3797


-- 
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