Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Named Redis client injection not working when used in separate JAR #15581

Closed
abutic opened this issue Mar 9, 2021 · 8 comments · Fixed by #15589
Closed

Named Redis client injection not working when used in separate JAR #15581

abutic opened this issue Mar 9, 2021 · 8 comments · Fixed by #15589
Labels
area/redis kind/bug Something isn't working
Milestone

Comments

@abutic
Copy link

abutic commented Mar 9, 2021

Describe the bug
We have an application scoped bean, defined in our common project and being used by other services, that utilizes RedisClient:

@ApplicationScoped
public class Service {

    @Inject
    @RedisClientName("second")
    RedisClient redisClient;
    ...
}

This common project is packaged as JAR and then used as a Maven dependency from other services.

We keep getting this error when starting those other services:

javax.enterprise.inject.spi.DeploymentException:
  javax.enterprise.inject.UnsatisfiedResolutionException: Unsatisfied dependency for type io.quarkus.redis.client.RedisClient and qualifiers [@RedisClientName(value = "second")]

We've defined an alternate Redis connection like this:

quarkus.redis.second.hosts=redis://localhost:6379

and made sure it's being used as expected by a Redis client defined in our service (not the common JAR!) like this:

    @Inject
    @RedisClientName("second")
    RedisClient redisClient;

Should it be possible to have a bean class contained in a dependency JAR and make it use Redis connection defined in the project that uses that JAR?

Expected behavior
Bean defined in a dependency JAR, which uses a Redis client annotated by @RedisClientName, properly using Redis connection defined in containing service.

@abutic abutic added the kind/bug Something isn't working label Mar 9, 2021
@quarkus-bot
Copy link

quarkus-bot bot commented Mar 9, 2021

@quarkus-bot quarkus-bot bot added area/arc Issue related to ARC (dependency injection) area/redis labels Mar 9, 2021
@manovotn
Copy link
Contributor

manovotn commented Mar 9, 2021

This common project is packaged as JAR

Does the JAR contain beans.xml? Empty one should do the trick.

@abutic
Copy link
Author

abutic commented Mar 9, 2021

This common project is packaged as JAR

Does the JAR contain beans.xml? Empty one should do the trick.

Unfortunately, yes, the JAR contains an empty META-INF\beans.xml file.

@manovotn
Copy link
Contributor

manovotn commented Mar 9, 2021

Hmm, not sure why you cannot see it then.
You could try to make the bean @Unremovable (or just check in dev mode that it wasn't removed) to make double sure something isn't going wrong there.
Besides that, a reproducer project would be nice so that we can check what's going on close up.

@mkouba
Copy link
Contributor

mkouba commented Mar 9, 2021

It seems that the redis client extension only considers classes from the application root (i.e. src/main/java) when collecting the client names and registering the relevant synthetic beans: https://github.com/quarkusio/quarkus/blob/master/extensions/redis-client/deployment/src/main/java/io/quarkus/redis/client/deployment/RedisClientProcessor.java#L89-L93

CC @machi1990

@mkouba mkouba removed the area/arc Issue related to ARC (dependency injection) label Mar 9, 2021
@glefloch
Copy link
Member

glefloch commented Mar 9, 2021

If this consists of looking in all archive classes and adding a test, I can take care or it :)

@machi1990
Copy link
Member

machi1990 commented Mar 9, 2021

It seems that the redis client extension only considers classes from the application root (i.e. src/main/java) when collecting the client names and registering the relevant synthetic beans: https://github.com/quarkusio/quarkus/blob/master/extensions/redis-client/deployment/src/main/java/io/quarkus/redis/client/deployment/RedisClientProcessor.java#L89-L93

CC @machi1990

Thanks for spotting this @mkouba . What archive should have been used instead? I think the same problem can occur for the mongo-extension-

public void mongoClientNames(ApplicationArchivesBuildItem applicationArchivesBuildItem,

/cc @glefloch

@manovotn
Copy link
Contributor

manovotn commented Mar 9, 2021

I'd try with BeanArchiveIndexBuildItem.

@quarkus-bot quarkus-bot bot added this to the 1.13 - master milestone Mar 10, 2021
@gsmet gsmet modified the milestones: 1.13 - master, 1.12.2.Final Mar 10, 2021
This was referenced Mar 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/redis kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants