Apache ActiveMQ JMS service for AgentScape

This sections contains information about the ActiveMQ service. This is a proof-of-concept service that integrates the Apache ActiveMQ JMS. It starts an embedded JMS broker as a service, and allows agents to connect to the message broker using the service architecture.

  • Obtain the maven project from the downloads page

The project consists of 3 modules that each implement part of the functionality.

This project was created as a proof of concept to demonstrate how to integrate existing services with the service architecture from AgentScape. It is not officially supported yet and there has been no extensive testing. However, you are free to try and extend the example for yourself. Questions and remarks can always be posted at the agentscape forums.

ActiveMQ service

The main part of the service is implemented by the jms-service module. This service does not use the default ServiceAosProxy. The ActiveMQ does allow for custom transports, but these must be based on sockets. Therefore, the service uses the AosSockets library to offer client-broker interaction over sockets.

AgentScape only takes care of connecting clients and services using these sockets. Once a connection has been setup for the client by the service broker, the ActiveMQ libraries take care of all the interaction between client and service. This makes the service implementation relatively simple.

Because the AgentScape service broker is used, other mechanisms that are usually used to locate service (like JNDI) are not used here. Once the agent receives a socket connected to the service, the ActiveMQ libraries can be used to interact with the broker.

ActiveMQ library

The shared library contains some objects that have to be used both by clients and agents. The custom ActiveMQ transport (AosTransport) is used by the client and service to manager the connections. Both the agent and service refer to the jms-shared library in their manifest, so both can use the classes from this shared location.

The service can be accessed mostly by using the ActiveMQ provided connection API. Therefore, the service itself provides a relatively simple API.

public interface ActiveMQJmsService extends Service
{
  TopicConnection getTopicConnection() throws JMSException;
  TopicConnection getTopicConnection(String username, String password) throws JMSException;
  Connection getConnection() throws JMSException;
  Connection getConnection(String username, String password) throws JMSException;
}

The service API can be used to retrieve a (topic) connection, which can be used to handle (topic) subscriptions, messages, etc. using the ActiveMQ API. How this can be used is demonstrated by the example client.

ActiveMQ client agent

The client agent demonstrates how to use the ActiveMQ API to handle message exchange using the connections obtained from the service. The provided example shows how to exchange a message using a topic or a plain connection. For example, a topic connection is done using the ActiveMQ provided interface (Topic, TopicSession, etc).

private void handleTopicConnection (TopicConnection tc)
throws JMSException
{
  TopicSession tps = tc.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
  Topic topic = tps.createTopic(TOPIC_NAME);
  if (clientType == ClientType.PRODUCER)
  {
    getLog().info("Create publisher and publish text message");
    TopicPublisher pub = tps.createPublisher(topic);
    pub.publish(topic, tps.createTextMessage("Published message"));
    getLog().info("published text message..");
  }
}

This client agent can be used as a base to create more elaborate applications (multiple agents, multiple clients & producers, etc).

development/service/activemq_service.txt · Last modified: 2012/05/15 14:00 by reinier