Example Micro Container


This examples shows how to setup and run JBoss Messaging through the Micro Container.

Refer to the user's manual for the list of required Jars, since JBoss Micro Container requires a few jars.

Example step-by-step

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


  1. Start the server
  2.          jbm = new JBMBootstrapServer("./server0/jbm-jboss-beans.xml");
             jbm.run();
            
  3. As we are not using a JNDI environment we instantiate the objects directly
  4.            ClientSessionFactory sf = new ClientSessionFactoryImpl (new TransportConfiguration(NettyConnectorFactory.class.getName()));
            
  5. Create a Core Queue
  6.            
             ClientSession coreSession = sf.createSession(false, false, false);
             final String queueName = "queue.exampleQueue";
             coreSession.createQueue(queueName, queueName, true);
             coreSession.close();
               
            
  7. Create the session and producer
  8.            
                session = sf.createSession();
                                       
                ClientProducer producer = session.createProducer(queueName);
                
            
  9. Create and send a Message
  10. 
                ClientMessage message = session.createClientMessage(false);
                message.putStringProperty(propName, "Hello sent at " + new Date());
                System.out.println("Sending the message.");
                producer.send(message);
           
  11. Create the message consumer and start the connection
  12. 
                ClientConsumer messageConsumer = session.createConsumer(queueName);
                session.start();
  13. Receive the message
  14. 
                            ClientMessage messageReceived = messageConsumer.receive(1000);
                System.out.println("Received TextMessage:" + messageReceived.getProperty(propName));
  15. Be sure to close our resources!
  16.            
               finally
               {
                  if (connection != null)
                  {
                     connection.close();
                  }
               }
            
  17. Stop the server
  18.            
               jbm.shutdown();