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