Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. Create a custom proxy service with the following configuration. For more information on creating proxy services, see Working with Proxy Services.

    Code Block
    <?xml version="1.0" encoding="UTF­8"?>
    <proxy xmlns="http://ws.apache.org/ns/synapse" name="AMQPProducerSample" transports="http" statistics="disable" trace="disable" startOnLoad="true">
    <target>
     <inSequence>
        <property name="OUT_ONLY" value="true"/>
        <property name="FORCE_SC_ACCEPTED" value="true" scope="axis2"/>
         <send>
          <endpoint>
           <address uri="rabbitmq:/AMQPProducerSample?rabbitmq.server.host.name=localhost&amp;rabbitmq.server.port=5672&amp;rabbitmq.queue.name=queue&amp;rabbitmq.queue.route.key=route&amp;rabbitmq.exchange.name=exchange"/>
          </endpoint>
        </send>
     </inSequence>
     <outSequence>
            <send/>
     </outSequence>
    </target>
    <description/>
    </proxy> 
  2. Use the following as a RabbitMQ consumer that will consume and display the incoming messages to the RabbitMQ queue.

    Code Block
    languagejava
    ConnectionFactoryfactory =newConnectionFactorynew ConnectionFactory();
    factory.setHost(“localhost”"localhost");
    factory.setUsername(“guest”"guest");
    factory.setPassword(“guest”"guest");
    factory.setPort(5672);
     
    Connectionconnection =factory.newConnection();
    Channelchannel =connection.createChannel();
    channel.queueDeclare(“queue”"queue",false,false,false,null);
    channel.exchangeDeclare(“exchange”"exchange","direct",true);
    channel.queueBind(“queue”,“exchange”,“route”"queue","exchange","route");
     
    //Createtheconsumer
    QueueingConsumerconsumer =newQueueingConsumernew QueueingConsumer(channel);
    channel.basicConsume(“queue”"queue",true,consumer);
     
    //Startconsumingmessages
    while(true)
     {
     QueueingConsumer.Deliverydelivery =consumer.nextDelivery();
     Stringmessage =newStringnew String(delivery.getBody());
     } 	

Execute the sample client

...