Closed fiorenzino closed 6 years ago
If you did add the redpipe-cdi module, then perhaps I'm not registering the vertx-cdi integration properly.
I can reproduce, trying to understand why this happens.
OK, I'm pretty sure it's related to the CDI context, which is not associated with the thread which is doing the event sending. Not sure at all how to fix that, though.
Actually, I wonder if this is really about contexts and scopes. I'm pretty sure the resource bean is request-scoped by default, and the observer might need to be application scoped. If I make it application-scoped then it works. It also makes some sense, because observers don't make a lot of sense as request-scoped, no?
WDYT?
You are right, if the consumer is annotated with @ApplicationScoped, it work correctly. I created a branch for that: https://github.com/fiorenzino/redpipe/tree/REDPIPE12/redpipe-example-cdi
@ApplicationScoped public class HelloService {
static final String HELLO_QUEUE = "test-queue";
public HelloService() {
System.out.println("hello service construct");
}
public String name() {
return "flower";
}
void helloConsumer(@Observes @VertxConsumer(HELLO_QUEUE) VertxEvent event) {
System.out.println("hello " + event.getMessageBody());
}
}
OK, I'll push a test for this and then close then.
Done.
I created a simple project to test eventbus with cdi: https://github.com/fiorenzino/redpipe-eventbus
i created a subscriber using weld:
My events never be received from consumer.
Suggestions?