Is it possible to observe a CDI event inside a WAR when it is packaged as an EAR

I have an Enterprise Application (EAR) archive containing several backend modules (EJB), as well as some web modules (WAR).

An event is fired inside one of the internal modules:

@Inject private Event<MyEvent> myEvent; ... public void fireEvent() { myEvent.fire(new MyEvent()); } ... 

This can be seen in any of the other backend modules with code similar to this:

 public void listener(@Observes MyEvent myEvent) { .. } 

But I can not get the event inside the WAR. Is it because of the visibility of the classloader (classes from WAR are not visible by EJB) or is CDI handling this?

If CDI cannot be used for large-scale application events, what are the alternatives?

  • Jms
  • Guava EventBus
  • ...

Is there anything that works with CDI? Maybe some CDI extension that combines events in a WAR?

----------- EDIT:

I can watch the event if it is fired inside the same WAR. I also tried using @Stateless bean as an event listener without success.

Packaging is as follows:

  • EAR
    • WAR (event must be marked here)
    • WAR
    • EJB (event triggered here)
+6
source share
1 answer

After some more research, it seems like its expected behavior, since WAR classes are not visible to EJB.

Think about it, this is good - in a clustered environment, a CDI event will only be accepted by WAR running on the same node as the EJB module that fires the event. But to reliably update the user experience, we need to get it on every instance.

JMS or another messaging system is definitely the way to go in this case. There is also a CDI extension for the CDI ↔ JMS bridge: Seam3 JMS

+4
source

All Articles