Apache ActiveMQ

Using ActiveMQ core API

Apache ActiveMQ features also a core API which can be used to handle the JMS server and operations on the top of it, using its own non-JMS API. This is also known as the core API.

The core API provides all the functionality of JMS but without much of the complexity. It also provides features that are not available using JMS.

Here is an example, contained in the example/core/embedded folder which shows how you can connect to a remote Apache ActiveMQ Artemis Server using the default address, create a JMS Queue, send a message and consume it:

public class EmbeddedRemoteExample

   public static void main(final String[] args)
         // Step 3. As we are not using a JNDI environment we instantiate the objects directly

         Map<String,Object> map = new HashMap<String,Object>();
         map.put("host", "localhost");
         map.put("port", 61616);
         // -------------------------------------------------------

         ServerLocator serverLocator = ActiveMQClient.createServerLocatorWithoutHA(new TransportConfiguration(NettyConnectorFactory.class.getName(), map));
         ClientSessionFactory sf = serverLocator.createSessionFactory();

         // Step 4. Create a core queue
         ClientSession coreSession = sf.createSession(false, false, false);

         final String queueName = "queue.exampleQueue";

         coreSession.createQueue(queueName, queueName, true);


         ClientSession session = null;


            // Step 5. Create the session, and producer
            session = sf.createSession();

            ClientProducer producer = session.createProducer(queueName);

            // Step 6. Create and send a message
            ClientMessage message = session.createMessage(false);

            final String propName = "myprop";

            message.putStringProperty(propName, "Hello sent at " + new Date());

            System.out.println("Sending the message.");


            // Step 7. Create the message consumer and start the connection
            ClientConsumer messageConsumer = session.createConsumer(queueName);

            // Step 8. Receive the message.
            ClientMessage messageReceived = messageConsumer.receive(1000);
            System.out.println("Received TextMessage:" + messageReceived.getStringProperty(propName));
            // Step 9. Be sure to close our resources!
            if (sf != null)
      catch (Exception e)

Follow us on Twitter