Reputation: 285
I'm trying to understand how CDI Events work in order to implement their usage in my application, that is structured like this: I have a JCA Resource Adapter that starts a Socket Server. Then I have a MDB that is mapped as the endpoint of this resource adapter. Now, when I receive a message through the socket server, I'd like to notify a pool of stateless beans of this message. This message contains data needed by the Stateless Session Beans to do some job upon some other requests coming from a Web Service.
I've created a Stateless session bean that implements a Local and a Remote interface. The local one declares a listenToRegistration method.
@Stateless(...)
public class myBean implements MyRemoteInterface,MyLocalInterface{
...
public void listenToEvent(@Observes EventMessage eventMessage){
logger.info("gotcha!");
}
}
The local interface is defined like this
@Local
public interface MyLocalInterface {
public void listenToEvent(@Observes EventMessage eventMessage);
}
The MDB that receives from the JCA Resource Adapter is like this
@MessageDriven(...)
public class messagerMDB implements MessageEndpoint {
@Inject
Event<EventMessage> events;
...
@Override
public void onMessage(String message) throws Exception {
...
events.fire(message);
}
}
Now, imagine that at a certain point in time I have 20 instances of myBean in a pool. When I receive a message I expect to read 20 times "gotcha". Am I right?
Upvotes: 0
Views: 1165
Reputation: 5378
No, just once. The server will pick one instance to use for the notification, not all of them. If they were different types then you should receive notifications in each type.
Upvotes: 3