RabbitMQ Common API Translation

Source: Internet
Author: User
Tags rabbitmq

1. First, the code that publishes the message

public class Mqpublisher {public static void main (string[] args) {try{ConnectionFactory factory =            New ConnectionFactory ();            Factory.sethost ("123.199.200.54");//129.199.200.54 factory.setusername ("Omsuser");            Factory.setpassword ("9AVXR2LLK2XSKCDQ7ZICCWKP");            Factory.setport (5672);            Connection Connection = Factory.newconnection ();            Channel channel = Connection.createchannel ();            Channel.queuedeclare ("Manufacturebill", True, False, false, NULL);            String bill = Getmanufacturebill ();            Mqmessage mqmsg=new mqmessage ();            Jsonobject Jso=json.parseobject (Bill);//json string converted to Jsonobject object Mqmsg.setobject (JSO);            Mqmsg.settype (0);            String Mqjson = json.tojsonstring (Mqmsg,serializerfeature.writemapnullvalue);           Channel.basicpublish ("", "Manufacturebill", NULL, Bill.getbytes ());          Channel.queuedelete ("Manufacturebill");  Channel.basicpublish ("", "Manufacturebill", NULL, Mqjson.getbytes ());            Channel.close ();        Connection.close ();        }catch (Exception e) {e.printstacktrace (); }    }

Defining channels

Amqp. Queue.declareok Queuedeclare (String queue,                                  Boolean durable,                                  Boolean exclusive,                                  boolean autodelete,                                  map<string,object> arguments)                           throws IOException
Declare a queue
Parameters:
-The name of the "the"
queue queue channel, the consumer wants to receive information, the name is the same, there may be multiple channels under the same connection
durable -True if we are declaring a durable queue (the queue would survive a server restart) defines a persistent queuing, typically set to True when the server is hung off After that, the queue still exists,
exclusive -True if we are declaring a exclusive queue (restricted to this connection) defines a unique queuing (do not allow others to connect) is generally set to false, otherwise How to accept the message
autoDelete -True if we are the declaring an Autodelete queue (the server will delete it when the no longer in using) when the server is not used in this queue, is it self- Delete the action. Generally set to false, consistent with durable
arguments -Other properties (construction arguments) for the queue this does not know
Returns:
a declaration-confirm method to indicate the queue was successfully declared
Throws:
IOException -If an error is encountered
See Also:
AMQP.Queue.Declare, AMQP.Queue.DeclareOk

RabbitMQ Common API Translation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.