This examples shows how to setup and run JBoss Messaging embedded.
JBoss Messaging was designed to use POJOs (Plain Old Java Objects), what makes embedding JBoss Messaging as simple as instantiating a few objects.
On this example, we only one jars (jbm-core.jar, jbm-jms.jar and jboss-javaee.jar).
JBoss Messaging 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 ant
from this directory
In this we don't use any configuration files. (Everything is embedded). We simply instantiate ConfigurationImpl, MessagingServer, start it and operate on JMS regularly
Configuration configuration = new ConfigurationImpl();
configuration.setEnablePersistence(false);
configuration.setSecurityEnabled(false);
configuration.getAcceptorConfigurations().add(new TransportConfiguration(InVMAcceptorFactory.class.getName()));
MessagingServer server = Messaging.newMessagingServer(configuration);
server.start();
Queue queue = new JBossQueue("exampleQueue");
JBossConnectionFactory cf = new JBossConnectionFactory (new TransportConfiguration(InVMConnectorFactory.class.getName()));
ClientSession coreSession = cf.getCoreFactory().createSession(false, false, false);
coreSession.createQueue("jms.queue.exampleQueue", "jms.queue.exampleQueue", true);
coreSession.close();
connection = cf.createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session.createProducer(queue);
TextMessage message = session.createTextMessage("Hello sent at " + new Date());
System.out.println("Sending the message.");
producer.send(message);
MessageConsumer messageConsumer = session.createConsumer(queue);
connection.start();
TextMessage messageReceived = (TextMessage)messageConsumer.receive(1000);
System.out.println("Received TextMessage:" + messageReceived.getText());
finally
{
if (connection != null)
{
connection.close();
}
}
server.stop();