Skip to content

Conversation

mkouba
Copy link
Contributor

@mkouba mkouba commented Feb 4, 2019

@cescoffier @FroMage This is what I have so far. Let me know what you think about the API...

    @Dependent
    class SimpleBean {

        @ConsumeMessage("foo") // -> EventBus.consumer("foo").handler(m -> m.reply(m.body().toUpperCase()))
        String send(String message) {
            return message.toUpperCase();
        }

        @ConsumeMessage("pub") // -> EventBus.consumer("pub").handler(m -> System.out.println(message.body()))
        void pub(String message) {
          System.out.println(message);
        }

        @ConsumeMessage(value = "pub", local = true) // -> EventBus.localConsumer("pub").handler(m -> System.out.println(message.body()))
        void pub(Message<String> message) {
          System.out.println(message.body());
        }
        
        @ConsumeMessage("foo-async") // -> EventBus.consumer("foo-async").handler(m -> CompletableFuture.completedFuture(message.toUpperCase()).thenAccept(r -> m.reply(r)))
        CompletionStage<String> sendAsync(String message) {
            return CompletableFuture.completedFuture(message.toUpperCase());
        }
    }

WRT the annotation name - we cannot use @Consumes because of JAX-RS. I don't like @Address. And I find @ConsumeMessage quite self-explanatory.

@kenfinnigan
Copy link
Member

It might open us up to unintended typos, but what about @Consume without the "s"?

@mkouba
Copy link
Contributor Author

mkouba commented Feb 5, 2019

It might open us up to unintended typos...

I'm afraid this would not help much. We should try to avoid problems like CDI @Produces VS JAX-RS @Produces. Maybe @Consuming, @MessageConsumer or even @VertxConsumer?

@cescoffier
Copy link
Member

I would use @Consumes.

For the rest, it looks very good!

@mkouba
Copy link
Contributor Author

mkouba commented Feb 5, 2019

Well, I can see the users asking why it does not work and then realizing they use javax.ws.rs.Consumes. We had many similar questions about javax.ws.rs.Produces in CDI ;-)

@cescoffier
Copy link
Member

You are right! Forgot about @Consumes. I would avoid message as it would confuse with reactive messaging. Maybe event something?

@Event
@EventHandler

...naming is hard....

@mkouba
Copy link
Contributor Author

mkouba commented Feb 5, 2019

@ConsumeEvent sounds quite good... there will always be plenty of Event types on the class path.

@ConsumeEvent("foo.address")
String send(String message) {
    return message.toUpperCase();
}

@cescoffier
Copy link
Member

+1 for @ConsumeEvent

@cescoffier
Copy link
Member

Thinking loudly...

A few years back (in 2005), I've read a paper about using the class name to identify event recipient. Obviously, it was making the assumption that consumer would be "unique".

Now let's imagine a @ConsumeEvent without a value. Could we imagine to be the fully classified name of the bean class? Of course for a @Dependant bean it can be tricky but for an @ApplicationScoped bean it would work no?

@mkouba
Copy link
Contributor Author

mkouba commented Feb 5, 2019

Like this?

package foo;
class SimpleBean { 
   @ConsumeMessage // -> EventBus.consumer("foo.SimpleBean").handler(m -> m.reply(m.body().toUpperCase())) 
   String send(String message) { return message.toUpperCase(); }
}

I think this would work for any scope. @Dependent bean instances exist to service a single delivery only.

@cescoffier
Copy link
Member

Exactly.

@mkouba
Copy link
Contributor Author

mkouba commented Feb 5, 2019

@cescoffier FQCN as the default address should work now.

@mkouba mkouba changed the title WIP: Vertx CDI integration - introduce ConsumeMessage annotation Vertx CDI integration - introduce ConsumeEvent annotation Feb 5, 2019
Copy link
Member

@cescoffier cescoffier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few comments inline.

Copy link
Member

@cescoffier cescoffier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good!

@mkouba mkouba merged commit 2728ea7 into quarkusio:master Feb 5, 2019
@cescoffier cescoffier added this to the 0.8.0 milestone Feb 6, 2019
maxandersen pushed a commit to maxandersen/quarkus that referenced this pull request Nov 5, 2022
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

Successfully merging this pull request may close these issues.

3 participants