RABBITMQ Installation with Hello word!

Source: Internet
Author: User

  

Environment: CentOS6.4

Erlang must be installed

Go to the official website first download

Under Linux source version otp_src_18.1

And then./configure will make a small mistake. makefile:248:/usr/local/otp_src_18.1/make/x86_64-unknown-linux-gnu/otp_ded.mk:no such file or Directory Error:no curses library functions found

Then you need to install sudo yum install ncurses-devel.x86_64

And then continue./configure

Make

Make install

All right

Next install the very inconvenient RABBITMQ

Also the official website download version rabbitmq_server-3.5.6

Then unzip

CD rabbitmq_server-3.5.6

Start SH sbin/rabbitmq-server

Help SH Sbin/rabbitmqctl

SH sbin/rabbitmqctl add_user hyy hyy

SH sbin/rabbitmqctl set_permissions-p/hyy ". *" ". *" ". *"

And then the very simple Java code of the other to go to the official website to see it

Send side:

ImportCom.rabbitmq.client.connection;importCom.rabbitmq.client.channel;importcom.rabbitmq.client.connectionfactory;/** * @author Blazer He * @__date November 9, 2015 */public class Send {private fi    nal static String queue_name = "Hello"; public static void Main (string[] args) throws Exception {connectionfactory factory = new connectionfactory (); FAC Tory.sethost ("192.168.0.57"); Factory.setusername ("Hyy"); Factory.setpassword ("hyy"); Factory.setvirtualhost ("/"); Factory.setport (5672); Connection Connection = factory.newconnection (); Channel channel = Connection.createchannel (); Channel.queuedeclare (Queue_name, False, False, false, null); String message = "Hello world!" ; Channel.basicpublish ("", queue_name, null, Message.getbytes ()); System.out.println ("[X] Sent '" + Message + "'"); Channel.close (); Connection.close (); }}

Receiving end:

Import Java.util.date;import Com.rabbitmq.client.channel;import Com.rabbitmq.client.connection;import Com.rabbitmq.client.connectionfactory;import Com.rabbitmq.client.queueingconsumer;public class Consume {private    Final static String queue_name = "Hello";        public static void Main (string[] argv) throws Exception {ConnectionFactory factory = new ConnectionFactory ();        Factory.sethost ("192.168.0.57");        Factory.setusername ("Hyy");        Factory.setpassword ("Hyy");        Factory.setvirtualhost ("/");        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); while (true) {Queueingconsumer.delivery Delivery = Consumer.nextdelivery ();           String message = new String (Delivery.getbody ());        System.out.println (New Date () + "[x] Received '" + Message + "'"); }    }}

  

Well, the preliminary can be run up, there are more features need to go deep.

RABBITMQ Installation with Hello word!

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.