This example shows how to setup and run ActiveMQ Artemis embedded with remote clients connecting.
ActiveMQ Artemis was designed to use POJOs (Plain Old Java Objects), what makes embedding ActiveMQ Artemis as simple as instantiating a few objects.
ActiveMQ Artemis Embedded could be used from very simple use cases with only InVM support to very complex cases with clustering, persistence and fail over.
To run the example, simply type mvn verify -Pserver
from this directory to start the server and mvn verify -Pclient
to run the client example
In this we don't use any configuration files. (Everything is embedded). We simply instantiate ConfigurationImpl, ActiveMQServer, start it and operate on JMS regularly
Configuration configuration = new ConfigurationImpl(); configuration.setEnablePersistence(false); configuration.setSecurityEnabled(false);
ActiveMQServer server = ActiveMQ.newActiveMQServer(configuration); server.start();
ServerLocator serverLocator = ActiveMQClient.createServerLocatorWithoutHA(new TransportConfiguration(NettyConnectorFactory.class.getName())); ClientSessionFactory sf = serverLocator.createSessionFactory();
ClientSession coreSession = sf.createSession(false, false, false); final String queueName = "queue.exampleQueue"; coreSession.createQueue(queueName, queueName, true); coreSession.close();
session = sf.createSession(); ClientProducer producer = session.createProducer(queueName);
ClientMessage message = session.createMessage(false); message.putStringProperty(propName, "Hello sent at " + new Date()); System.out.println("Sending the message."); producer.send(message);
ClientConsumer messageConsumer = session.createConsumer(queueName); session.start();
ClientMessage messageReceived = messageConsumer.receive(1000); System.out.println("Received TextMessage:" + messageReceived.getProperty(propName));
if (sf != null) { sf.close(); }