Proton qpid java example

HornetQ can be configured to accept requests from any AMQP client that supports the 1.0 version of the protocol. This example shows a simply qpid java 1.0 client example

To run the example simply run the command mvn verify

To configure HornetQ to accept AMQP client connections you need to add an Acceptor like so:

     
         <acceptor name="proton-acceptor">
         <factory-class>org.hornetq.core.remoting.impl.netty.NettyAcceptorFactory</factory-class>
         <param key="protocol" value="AMQP"/>
         <param key="port" value="5672"/>
         </acceptor>
     
     

Example step-by-step

  1. Create an amqp qpid 1.0 connection.
  2.            connection= new Connection("localhost", 5672, null, null);
            
  3. Create a session
  4.            Session session = connection.createSession();
            
  5. Create a sender
  6.            Sender sender = session.createSender("testQueue");
            
  7. send a simple message
  8.            sender.send(new Message("I am an amqp message"));
            
  9. create a moving receiver, this means the message will be removed from the queue
  10.            Receiver rec = session.createMovingReceiver("testQueue");
            
  11. set some credit so we can receive
  12.           rec.setCredit(UnsignedInteger.valueOf(1), false);
            
  13. receive the simple message
  14.           Message m = rec.receive(5000);
                    System.out.println("message = " + m.getPayload());
            
  15. acknowledge the message
  16.           rec.acknowledge(m);
            
  17. close the connection
  18.           connection.close();