RABBITMQ Remote Access

Source: Internet
Author: User

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 + "'");}}


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.