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

HandlerNotFoundException with Quarkus kediatr-quarkus-starter #380

Open
blertzupfgut opened this issue Nov 27, 2024 · 5 comments
Open

HandlerNotFoundException with Quarkus kediatr-quarkus-starter #380

blertzupfgut opened this issue Nov 27, 2024 · 5 comments

Comments

@blertzupfgut
Copy link

blertzupfgut commented Nov 27, 2024

Hi,

I'm trying to use kediatR with Quarkus (version 3.16.3). I'm a Quarkus begginer, so maybe I'm some missing essential stuff ... but following the kediatr docs, I get com.trendyol.kediatr.HandlerNotFoundException: handler could not be found for <package>.GetUserByIdQuery on accessing a REST endpoint.

  • pom.xml contains <artifactId>kediatr-quarkus-starter</artifactId>.
  • application.yml contains the index-dependency entry.
  • I couldn't inject private val mediator: mediator into UserResource (type mediator not found compile error), so I used Mediator.

Here is my code:

@Path("users")
class UserResource(private val mediator: Mediator) {
    @GET
    @Path("/{id}")
    @Produces(MediaType.APPLICATION_JSON)
    suspend fun find(id: String) = mediator.send(GetUserByIdQuery(id))
}

class GetUserByIdQuery(val id: String) : Query<Login?>

@ApplicationScoped
class GetUserByIdQueryHandler(private val repository: LoginRepository) : QueryHandler<GetUserByIdQuery, Login?> {
    override suspend fun handle(query: GetUserByIdQuery): Login? {
        return repository.findById(query.id)
    }
}
  1. Do I need to register my handlers manually? But where/how?
  2. Is the compile error regarding the unknown injected mediator a hint that kediatr-quarkus-starter wasn't picked up or initialized? Probably Mediator is the wrong type, because kediatR isn't enrichting that with the handlers. But then, how do I make the mediator from KediatRBeanProvider known to my code?

Thanks for your help!
Tobi

@osoykan
Copy link
Collaborator

osoykan commented Nov 27, 2024

Hi,

Did you try adding/editing the properties file as mentioned here: https://trendyol.github.io/kediatR/#quarkus

Your application.properties file content should contain:

  quarkus:
    index-dependency:
      kediatr:
        group-id: com.trendyol
        artifact-id: kediatr-quarkus-starter

With this configuration, quarkus is able to detect the beanprovider.


I see, you did it already.

The next question is, you get build errors right? Mediatr is not present?

@osoykan
Copy link
Collaborator

osoykan commented Nov 27, 2024

Could also be your JDK version is < 17

@osoykan
Copy link
Collaborator

osoykan commented Nov 27, 2024

Do I need to register my handlers manually? But where/how?

You don't need that, Quarkus DI should discover them automagically

Is the compile error regarding the unknown injected mediator a hint that kediatr-quarkus-starter wasn't picked up or initialized?

Indeed there is something wrong with the build system, kediatr-quarkus-starter might not be picked up. To be sure, you're referring kediatr version 3.1.2, right?

@blertzupfgut
Copy link
Author

Yes indeed, version 3.1.2.

For a test, I copied the kediatr files into my project, and then everything is found - but the handler(s) need to be annotated not only with @ApplicationScope, but also with @Startup.

Anyway ... shame on me: Just realized yesterday that kediatr is async-only. And as some of my code / libs is blocking, and I still have to master how to call blocking code from async code, I just removed the async stuff for now from the in-project kediatr files. So now I have a nice, working, blocking kediatr - but I guess that's not the intended use case ...

@osoykan
Copy link
Collaborator

osoykan commented Nov 29, 2024

Your Quarkus version is worth checking, since KediatR uses a specific version in that release.

need to be annotated not only with @ApplicationScope, but also with @startup.

That might be the case, indeed.

Just realized yesterday that kediatr is async-only. And as some of my code / libs is blocking,

You can keep the entrance points (such as controllers, Kafka consumers, etc...) sync if that's the direction you want to take, but you can mix the async behavior by using runBlocking that bridges non-async-->async.

Plus, some Quarkus packages support coroutines: https://quarkus.io/guides/kotlin#coroutines-support

So now I have a nice, working, blocking kediatr

So, I wouldn't advise it:)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants