RABBITMQ Learning (vii) Ubuntu environment installation and. NET Client Testing

Source: Internet
Author: User
Tags dotnet rabbitmq

1. Download the RABBITMQ Server installation package

installation package Rabbitmq-server_3.3.5-1_all.deb in Ubuntu environment is here: http://www.rabbitmq.com/install-debian.html

Ubuntu installs RABBITMQ by default since version 9.04, but the version is older, so we need to install the latest installation package.

Once downloaded, you can double-click the installation and the Erlang environment is all there.

After the installation, the Start command is:

INVOKE-RC.D rabbitmq-server Start
The Stop command is:
INVOKE-RC.D Rabbitmq-server Stop

2, write. NET Client test program

The sender Send.cs code is:

Namespace rabbitmq.sendreceive{    class program    {        static void Main (string[] args)        {            ConnectionFactory factory = new ConnectionFactory () {HostName = "192.168.1.103"};            using (iconnection conn = factory. CreateConnection ())            {                using (IModel channel = conn. Createmodel ())                {                    channel. Queuedeclare ("Hello", False, False, false, NULL);                    String mesg = "Hello RabbitMQ";                    byte[] BODY = Encoding.UTF8.GetBytes (MESG);                    Channel. Basicpublish ("", "Hello", null, body);                    Console.WriteLine ("[x] Sent {0}", MESG);}}}}    

The Receive.cs code for the receiving program is:

Using system;using system.collections.generic;using system.linq;using system.text;using RabbitMQ.Client;using        Rabbitmq.client.events;namespace rabbitmq.sendreceive{class Program {static void Main (string[] args)            {ConnectionFactory factory = new ConnectionFactory () {HostName = "192.168.1.103"}; using (iconnection conn = factory. CreateConnection ()) {using (IModel CHANNEL = conn. Createmodel ()) {channel.                    Queuedeclare ("Hello", False, False, false, NULL);                    Queueingbasicconsumer consumer = new Queueingbasicconsumer (channel); Channel.                    Basicconsume ("Hello", true, consumer);                    Console.WriteLine ("[*]waiting for Message ..."); while (true) {var Queueitem = (Basicdelivereventargs) consumer.                        Queue.dequeue ();                       byte[] BODY = queueitem.body; String MESG = Encoding.UTF8.GetString (body);                    Console.WriteLine ("[x] Received {0}", MESG); }                }            }        }    }}
Note You need to download rabbitmq-dotnet-client-3.3.5-dotnet-3.0 here (address) First, then introduce the RabbitMQ.Client.dll and RabbitMQ.ServiceModel.dll two DLLs.


3. Run the test code

My test code is running on Windows7, and RABBITMQ Broker is installed on the Ubuntu virtual machine, which is connected to the network in a bridged manner.

running the code will cause an access denied exception . There is a passage on the official website:

Default User Access

The broker creates a user guest with password guest. Unconfigured clients would in general use these credentials. By default, these credentials can is only being used when connecting to the broker as localhost so you'll need to tak e action before connecting fromn any other machine.

This means that a client that is not configured defaults to the authentication of the guest (the password is also guest) as the Access Message Center (RabbitMQ broker), but only when client and RabbitMQ broker are on the same machine, that is, access is available. If you cross the machine, you need to do other work.


3.1, first of all to see how to solve the guest user can only native access problems:

"Guest" user can only connect via localhost

By default, the guest user was prohibited from connecting to the broker remotely; It can only connect over a loopback interface (i.e. localhost). This applies both to AMQP and to any other protocols enabled via plugins. Any and users you create won't (by default) is restricted in the this-to.

This is configured via The loopback_users  item in the configuration file.

If You wish to allow The guest  user to connect from a remote host, you should set The LOOPBACK_USERS  configuration item To [] . A complete rabbitmq.config  which does this would look like:

[{rabbit, [{loopback_users, []}]}].

This has been made very clear, by default RABBITMQ configuration in loopback_users This configuration item needs to be modified to null [], because the default is configured as guest, after the modification is empty, there is no guest can only native access this limit.


Each release configuration file is located in a different location, following the common operating system configuration file location:

  • Generic UNIX - $RABBITMQ _home/etc/rabbitmq/
  • Debian/ubuntu - /etc/rabbitmq/
  • RPM - /etc/rabbitmq/
  • Mac OS X (macports) - ${install_prefix}/etc/rabbitmq/, the macports prefix is usually /opt /local
  • Windows - %appdata%\rabbitmq\
If there is no configuration file in the default location, create a new one yourself.

My Ubuntu has no configuration file, I created a new one, the content only need to write the configuration I want to modify the item.


So I WIndows7 the above test code will be able to run properly!!!


3.2 Other options:

It is advisable to delete the guest user or change the password to something Priva TE, particularly if your broker is accessible publicly.

You can see that it is generally recommended to delete the guest user or modify the guest user's code.

Not to be continued ...



3. Run the test code

RABBITMQ Learning (vii) Ubuntu environment installation and. NET Client Testing

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.