Architecture

The following section walks through the main parts of Apache ActiveMQ and links to the code to help you understand the layout

JMS Client

The org.apache.activemq package defines the core JMS client.

Transport

The JMS client and the message broker use the Transport abstraction for sending around command objects (like a distributed Command Pattern). A TransportChannel typically deals with some kind of networking mechanism (TCP sockets using BIO, using NIO, UDP / multicast, SSL over sockets, JXTA, EmberIO etc). See the org.apache.activemq.transport package for more details

So the TransportChannel is basically concerned with sending and receiving Command objects (each instance represents some kind of command). Packet is defined in the org.apache.activemq.command package which defines all the JMS Message implementations classes (which are Commands) along with a number of other kinds of packets, like subsciptions, message acknowledgements, transactions and so forth.

WireFormat

There are various possible ways of encoding messages onto a stream. We may wish to adapt to various different encoding mechanisms - such as to provide simpler wire formats for talking to C / JavaScript or to make a C# friendly encoding.

So all the Transport  implementations take a pluggable WireFormat implementation class - which is a Strategy Pattern for deciding how to write the Command to a DataIn / DataOut stream or Datagram.

So if you wish to provide your own binary, on the wire protocol then we just need a WireFormat implementation of your protocol, then we can use this with any transport (TCP BIO, NIO, JXTA etc).

We use OpenWireFormat by default which is the most efficient & easiest format to use from Java code - so if both ends of the wire are Java then its highly recommended. Though other WireFormats are most welcome.

Default Wire Format

The default wire format writes a byte which indicates the kind of Command which is being sent (see the Command interface which defines all the int constants for each type of command.

The core JMS Message types each have a unique byte ID for

  • Message
  • ObjectMessage
  • TextMessage
  • MapMessage
  • BytesMessage
  • StreamMessage

Then in addition there are various other types of command such as

There are a few others; the org.apache.activemq.command package describes them in their gory detail.

Basically the DefaultWireFormat has a default encoding of each of these commands. So after the first byte which indicates the type of packet is written, there is a specific wire format per packet type.

For new wire formats it may be that you only need to support a small subset of these types. e.g. you might just have a simple publish message, consume message & message ack.

Message Broker

The APIs for the message broker (server side of the JMS client) are defined in the org.apache.activemq.broker. There are various other packages which define different parts, from the message stores to the message routing and so forth.

To see an overview of these packages try the JavaDocs

Graphic Design By Hiram