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 are only using one jar (jbm-core.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();
ClientSessionFactory sf = new ClientSessionFactoryImpl (new TransportConfiguration(InVMConnectorFactory.class.getName()));
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.createClientMessage(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));
finally
{
if (connection != null)
{
connection.close();
}
}
server.stop();