What is pro/cons of javax.enterprise.event vs. org.eclipse.microprofile.reactive.messaging?

94 views Asked by At

I try to learn reactive programming / reactive messaging with QUARKUS and SmallRye. But I still have some trouble to understand the advantages of org.eclipse.microprofile.reactive.messaging over javax.enterprise.event, if there is ?

On one side :

@Inject
MyEvent Event<String> myEvent;

public void someFunc(){
myEvent.fire("blabla");
}

//Elsewhere in the code :
public void aConsumer(@Observes @MyEvent String ev){
 //an event saying blabla has been received :)
}

On the other side :

@Inject
@Channel("myChannel")
Emitter<String> msgEmitter;

public void someFunc(){
msgEmitter.send("blabla");
}

//Elsewhere in the code :
@Incoming("myChannel")
public void aConsumer(String ev){
 //an event saying blabla has been received :)
}

I may miss something ....

1

There are 1 answers

0
Ladicek On

The main difference is that CDI events (javax.enterprise.event) are purely in-process, while with Reactive Messaging, you can consume messages from / produce messages to external messaging systems (such as Kafka, ActiveMQ Artemis, etc., using variety of protocols such as AMQP, MQTT, etc.). While it is possible to use Reactive Messaging for in-memory message passing, that's not its main strength.