Http://www.blogjava.net/qileilove/archive/2014/09/04/417662.html
Http://qaseven.github.io
Http://www.linuxidc.com/Linux/2014-10/107917.htm
Package com.mq.rabbitmq.rabbitmqtest;
Import Java.util.Date;
Import Com.rabbitmq.client.ConnectionFactory;
Import com.rabbitmq.client.Connection;
Import Com.rabbitmq.client.Channel;
Import Com.rabbitmq.client.QueueingConsumer; public class Receivetest {private final static string queue_name = "Ftpagent"; private final static string userName = "ad
Min ";
Private final static String password = "admin";
Private final static String VirtualHost = "/";
Private final static int portnumber = 5672;
Private final static String HostName = "Master";
Private final static String host = "192.168.174.132"; public static void Main (string[] argv) throws Java.io.IOException, java.lang.InterruptedException {connectionfactory
Factory = new ConnectionFactory ();
Factory.sethost ("192.168.174.160");
Factory.setusername (UserName);
Factory.setpassword (password);
Factory.setvirtualhost (VirtualHost);
Factory.sethost (host);
Factory.setport (PortNumber); Connection Connection = Factory.newconnection ();
Channel Channel = Connection.createchannel ();
Channel.queuedeclare (Queue_name, False, False, false, NULL); SYSTEM.OUT.PRINTLN ("[*] waiting for messages.
To exit Press CTRL + C ");
Queueingconsumer consumer = new Queueingconsumer (channel);
Channel.basicconsume (Queue_name, true, consumer);
Date Nowtime = new Date ();
while (true) {Queueingconsumer.delivery Delivery = Consumer.nextdelivery ();
String message = new String (Delivery.getbody ());
System.out.println ("Recievetime:" + nowtime); System.out.println ("[X] Received '" + Message + "'");}}
Receivetest:
Package com.mq.rabbitmq.rabbitmqtest;
Import Java.util.Date;
Import Com.rabbitmq.client.ConnectionFactory;
Import com.rabbitmq.client.Connection;
Import Com.rabbitmq.client.Channel;
Import Com.rabbitmq.client.QueueingConsumer; public class Receivetest {private final static string queue_name = "Ftpagent"; private final static string userName = "ad
Min ";
Private final static String password = "admin";
Private final static String VirtualHost = "/";
Private final static int portnumber = 5672;
Private final static String HostName = "Master";
Private final static String host = "192.168.174.132"; public static void Main (string[] argv) throws Java.io.IOException, java.lang.InterruptedException {connectionfactory
Factory = new ConnectionFactory ();
Factory.sethost ("192.168.174.160");
Factory.setusername (UserName);
Factory.setpassword (password);
Factory.setvirtualhost (VirtualHost);
Factory.sethost (host);
Factory.setport (PortNumber); Connection Connection = Factory.newconnection ();
Channel Channel = Connection.createchannel ();
Channel.queuedeclare (Queue_name, False, False, false, NULL); SYSTEM.OUT.PRINTLN ("[*] waiting for messages.
To exit Press CTRL + C ");
Queueingconsumer consumer = new Queueingconsumer (channel);
Channel.basicconsume (Queue_name, true, consumer);
Date Nowtime = new Date ();
while (true) {Queueingconsumer.delivery Delivery = Consumer.nextdelivery ();
String message = new String (Delivery.getbody ());
System.out.println ("Recievetime:" + nowtime); System.out.println ("[X] Received '" + Message + "'");}}