2 Replies Latest reply on Dec 12, 2012 8:22 AM by Patrick M.

    Event Handling between two EJB-JARs (Observer Pattern?)

    Patrick M. Newbie



      I'm new to EJB development and currently search for the best/correct way to handle events between two EJB-JARs which are in one EAR.


      I tried to use the Observer Pattern. The event gets fired in BeanA but does not reach BeanB (as stated, two different EJB-JARs = two different Eclipse Projects in one Workspace / EAR).


      My Code currently looks kind of like this:


      Eclipse Project "beana"

      public class BeanA implements BeanARemote, BeanBLocal{ 
                private EntityManager em;
                private BeanA beanA;
              public void listenToReceivedEvent(@Observes ReceivedEvent events){
                Query query = em.Query("some query");


      Eclipse Project "beanb"

      public class BeanB implements BeanBLocal {
                Event<ReceivedEvent> events;
                public void fireEvent() {
                     ReceivedEvent e = new ReceivedEvent(stringList);
      public class ReceivedEvent  {
                private List<String> stringList;
                public ReceivedEvent(final List<String> stringList) {
                          this.stringList= stringList;
                public List<String> getStrings() {
                          return stringList;


      Currently, when on BeanB the event is fired at BeanA nothing happens. My question now is: is the Observer Pattern the correct pattern in this case? Did I forgot something in this sample why the BeanA does not gets the event? Is the Observer Pattern made for event communication between two differen EJB-JARs?