Bee
BEE the Apache ActiveMQ JMS, TomEE/Tomcat JMS wrapper - Page 4
Example 1: initialize BEE

BEE initialize with a single external broadcast channel. The channel is called "ORDERS", probably because it concern the subject of the orders. The types of messages (or conversational words list) are three: "MODIFY", "CREATE", "DELETE".

Beepin beepin = null;
try {
  InitialContext context = new InitialContext();
  beepin = (Beepin)context.lookup("java:global/xxxx/Beepin"); // get a Beepin instance
  beepin.initialize("AppExample", "localhost", "66661", "login", "password"); // initialize BEE
  String[] msgTypes = {"MODIFY","CREATE","DELETE"};
  beepin.addChanel("ORDERS", ChannelType.FOREIGNCHANNEL, msgTypes); // add the foreign broadcast channel
} catch (NamingException | BeeParameterEmptyException e){
  logger.error(e.getMessage());
} catch (BeeChannelAlreadyExistsException e) {
  logger.error(e.getMessage());
}

 
Example 2: subscribe to listening to a channel

Subscribe to the broadcast channel "ORDERS" created at initialization time (cf. example 1).

1. We declare a class that implements a BeeListener interface:

@Stateless
@LocalBean
public class ClientListener implements BeeListener {
  @Override
  public void onStringMessage(String msg, String sndrID, String msgType) {
    // prosessing when a string message is received
  }
  @Override
  public void onObjectMessage(Object obj, String sndrID, String msgType) {
    // prosessing when an objet message is received
  }
}

2. We call the subscribe method of Beepin

@EJB
private ClientListener clientListener // listener bean declared in 1.
...
beepin.subscribe("AppExample", "ORDERS", clientListener); // subscribe to listen channel ORDERS