2014-12-11 07:17:29 -05:00
|
|
|
# Architecture
|
2014-12-04 10:25:29 -05:00
|
|
|
|
2015-03-03 11:12:34 -05:00
|
|
|
In this section we will give an overview of the Apache ActiveMQ high level
|
2014-12-04 10:25:29 -05:00
|
|
|
architecture.
|
|
|
|
|
2014-12-11 07:17:29 -05:00
|
|
|
## Core Architecture
|
2014-12-04 10:25:29 -05:00
|
|
|
|
2015-03-03 11:12:34 -05:00
|
|
|
Apache ActiveMQ core is designed simply as set of Plain Old Java Objects
|
2014-12-04 10:25:29 -05:00
|
|
|
(POJOs) - we hope you like its clean-cut design.
|
|
|
|
|
|
|
|
We've also designed it to have as few dependencies on external jars as
|
2015-03-03 11:12:34 -05:00
|
|
|
possible. In fact, Apache ActiveMQ core has only one jar dependency, netty.jar,
|
2014-12-04 10:25:29 -05:00
|
|
|
other than the standard JDK classes! This is because we use some of the
|
|
|
|
netty buffer classes internally.
|
|
|
|
|
2015-03-03 11:12:34 -05:00
|
|
|
This allows Apache ActiveMQ to be easily embedded in your own project, or
|
2015-01-23 09:28:07 -05:00
|
|
|
instantiated in any dependency injection framework such as Spring or
|
2014-12-11 07:17:29 -05:00
|
|
|
Google Guice.
|
2014-12-04 10:25:29 -05:00
|
|
|
|
2015-03-03 11:12:34 -05:00
|
|
|
Each Apache ActiveMQ server has its own ultra high performance persistent
|
2014-12-04 10:25:29 -05:00
|
|
|
journal, which it uses for message and other persistence.
|
|
|
|
|
|
|
|
Using a high performance journal allows outrageous persistence message
|
|
|
|
performance, something not achievable when using a relational database
|
|
|
|
for persistence.
|
|
|
|
|
2015-03-03 11:12:34 -05:00
|
|
|
Apache ActiveMQ clients, potentially on different physical machines interact
|
|
|
|
with the Apache ActiveMQ server. Apache ActiveMQ currently provides two APIs for
|
2014-12-04 10:25:29 -05:00
|
|
|
messaging at the client side:
|
|
|
|
|
2015-02-25 15:29:36 -05:00
|
|
|
1. Core client API. This is a simple intuitive Java API that allows the
|
2014-12-04 10:25:29 -05:00
|
|
|
full set of messaging functionality without some of the complexities
|
|
|
|
of JMS.
|
|
|
|
|
2015-02-25 15:29:36 -05:00
|
|
|
2. JMS client API. The standard JMS API is available at the client
|
2014-12-04 10:25:29 -05:00
|
|
|
side.
|
|
|
|
|
2015-03-03 11:12:34 -05:00
|
|
|
Apache ActiveMQ also provides different protocol implementations on the server so you can use respective clients for these protocols:
|
2015-02-25 15:29:36 -05:00
|
|
|
|
|
|
|
1. Stomp
|
|
|
|
2. OpenWire
|
|
|
|
3. AMQP
|
|
|
|
|
|
|
|
|
|
|
|
JMS semantics are implemented by a JMS facade layer on the client
|
2014-12-04 10:25:29 -05:00
|
|
|
side.
|
|
|
|
|
2015-03-03 11:12:34 -05:00
|
|
|
The Apache ActiveMQ server does not speak JMS and in fact does not know
|
2014-12-04 10:25:29 -05:00
|
|
|
anything about JMS, it is a protocol agnostic messaging server designed
|
|
|
|
to be used with multiple different protocols.
|
|
|
|
|
|
|
|
When a user uses the JMS API on the client side, all JMS interactions
|
2015-03-03 11:12:34 -05:00
|
|
|
are translated into operations on the Apache ActiveMQ core client API before
|
|
|
|
being transferred over the wire using the Apache ActiveMQ wire format.
|
2014-12-04 10:25:29 -05:00
|
|
|
|
|
|
|
The server always just deals with core API interactions.
|
|
|
|
|
|
|
|
A schematic illustrating this relationship is shown in figure 3.1 below:
|
|
|
|
|
|
|
|
![ActiveMQ architecture1](images/architecture1.jpg)
|
|
|
|
|
2015-03-03 11:12:34 -05:00
|
|
|
Figure 3.1 shows two user applications interacting with an Apache ActiveMQ
|
2014-12-04 10:25:29 -05:00
|
|
|
server. User Application 1 is using the JMS API, while User Application
|
|
|
|
2 is using the core client API directly.
|
|
|
|
|
|
|
|
You can see from the diagram that the JMS API is implemented by a thin
|
|
|
|
facade layer on the client side.
|
|
|
|
|
2015-03-03 11:12:34 -05:00
|
|
|
## Apache ActiveMQ embedded in your own application
|
2014-12-04 10:25:29 -05:00
|
|
|
|
2015-03-03 11:12:34 -05:00
|
|
|
Apache ActiveMQ core is designed as a set of simple POJOs so if you have an
|
2014-12-04 10:25:29 -05:00
|
|
|
application that requires messaging functionality internally but you
|
2015-03-03 11:12:34 -05:00
|
|
|
don't want to expose that as an Apache ActiveMQ server you can directly
|
|
|
|
instantiate and embed Apache ActiveMQ servers in your own application.
|
2014-12-04 10:25:29 -05:00
|
|
|
|
2015-03-03 11:12:34 -05:00
|
|
|
For more information on embedding Apache ActiveMQ, see [Embedding Apache ActiveMQ](embedding-Apache activemq.md).
|
2014-12-04 10:25:29 -05:00
|
|
|
|
2015-03-03 11:12:34 -05:00
|
|
|
## Apache ActiveMQ integrated with a JEE application server
|
2014-12-04 10:25:29 -05:00
|
|
|
|
2015-03-03 11:12:34 -05:00
|
|
|
Apache ActiveMQ provides its own fully functional Java Connector Architecture
|
2014-12-04 10:25:29 -05:00
|
|
|
(JCA) adaptor which enables it to be integrated easily into any JEE
|
|
|
|
compliant application server or servlet engine.
|
|
|
|
|
|
|
|
JEE application servers provide Message Driven Beans (MDBs), which are a
|
|
|
|
special type of Enterprise Java Beans (EJBs) that can process messages
|
|
|
|
from sources such as JMS systems or mail systems.
|
|
|
|
|
|
|
|
Probably the most common use of an MDB is to consume messages from a JMS
|
|
|
|
messaging system.
|
|
|
|
|
|
|
|
According to the JEE specification, a JEE application server uses a JCA
|
|
|
|
adapter to integrate with a JMS messaging system so it can consume
|
|
|
|
messages for MDBs.
|
|
|
|
|
|
|
|
However, the JCA adapter is not only used by the JEE application server
|
|
|
|
for *consuming* messages via MDBs, it is also used when sending message
|
|
|
|
to the JMS messaging system e.g. from inside an EJB or servlet.
|
|
|
|
|
|
|
|
When integrating with a JMS messaging system from inside a JEE
|
|
|
|
application server it is always recommended that this is done via a JCA
|
|
|
|
adaptor. In fact, communicating with a JMS messaging system directly,
|
|
|
|
without using JCA would be illegal according to the JEE specification.
|
|
|
|
|
|
|
|
The application server's JCA service provides extra functionality such
|
|
|
|
as connection pooling and automatic transaction enlistment, which are
|
|
|
|
desirable when using messaging, say, from inside an EJB. It is possible
|
|
|
|
to talk to a JMS messaging system directly from an EJB, MDB or servlet
|
|
|
|
without going through a JCA adapter, but this is not recommended since
|
|
|
|
you will not be able to take advantage of the JCA features, such as
|
|
|
|
caching of JMS sessions, which can result in poor performance.
|
|
|
|
|
|
|
|
Figure 3.2 below shows a JEE application server integrating with a
|
2015-03-03 11:12:34 -05:00
|
|
|
Apache ActiveMQ server via the Apache ActiveMQ JCA adaptor. Note that all
|
2014-12-04 10:25:29 -05:00
|
|
|
communication between EJB sessions or entity beans and Message Driven
|
2015-03-03 11:12:34 -05:00
|
|
|
beans go through the adaptor and not directly to Apache ActiveMQ.
|
2014-12-04 10:25:29 -05:00
|
|
|
|
|
|
|
The large arrow with the prohibited sign shows an EJB session bean
|
2015-03-03 11:12:34 -05:00
|
|
|
talking directly to the Apache ActiveMQ server. This is not recommended as
|
2014-12-04 10:25:29 -05:00
|
|
|
you'll most likely end up creating a new connection and session every
|
|
|
|
time you want to interact from the EJB, which is an anti-pattern.
|
|
|
|
|
|
|
|
![ActiveMQ architecture2](images/architecture2.jpg)
|
|
|
|
|
2014-12-11 07:17:29 -05:00
|
|
|
For more information on using the JCA adaptor, please see [Application Server Integration and Java EE](appserver-integration.md).
|
2014-12-04 10:25:29 -05:00
|
|
|
|
2015-03-03 11:12:34 -05:00
|
|
|
## Apache ActiveMQ stand-alone server
|
2014-12-04 10:25:29 -05:00
|
|
|
|
2015-03-03 11:12:34 -05:00
|
|
|
Apache ActiveMQ can also be deployed as a stand-alone server. This means a
|
2014-12-04 10:25:29 -05:00
|
|
|
fully independent messaging server not dependent on a JEE application
|
|
|
|
server.
|
|
|
|
|
|
|
|
The standard stand-alone messaging server configuration comprises a core
|
2014-12-11 07:17:29 -05:00
|
|
|
messaging server and a JMS service.
|
2014-12-04 10:25:29 -05:00
|
|
|
|
|
|
|
The role of the JMS Service is to deploy any JMS Queue, Topic and
|
2015-01-20 10:54:49 -05:00
|
|
|
ConnectionFactory instances from any server side JMS
|
|
|
|
configuration. It also provides a simple management API for
|
2014-12-11 07:17:29 -05:00
|
|
|
creating and destroying Queues and Topics
|
2014-12-04 10:25:29 -05:00
|
|
|
which can be accessed via JMX or the connection. It is a separate
|
|
|
|
service to the ActiveMQ core server, since the core server is JMS
|
2015-01-23 09:28:07 -05:00
|
|
|
agnostic. If you don't want to deploy any JMS Queue or Topic via
|
|
|
|
server side XML configuration and don't require a JMS management
|
2014-12-11 07:17:29 -05:00
|
|
|
API on the server side then you can disable this service.
|
2014-12-04 10:25:29 -05:00
|
|
|
|
2014-12-16 05:27:08 -05:00
|
|
|
The stand-alone server configuration uses [Airline](https://github.com/airlift/airline)
|
|
|
|
for bootstrapping the Broker.
|
2014-12-04 10:25:29 -05:00
|
|
|
|
|
|
|
The stand-alone server architecture is shown in figure 3.3 below:
|
|
|
|
|
|
|
|
![ActiveMQ architecture3](images/architecture3.jpg)
|
|
|
|
|
2014-12-11 07:17:29 -05:00
|
|
|
For more information on server configuration files see [Server Configuration](server-configuration.md)
|