2.RabbitMQ的quick start

Posted wholeworld

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2.RabbitMQ的quick start相关的知识,希望对你有一定的参考价值。

1.首先要安装 RabbitMQ Client

2.创建一个控制台项目 取名 Publisher代码如下:

using RabbitMQ.Client;
using System;
using System.Text;

namespace Publisher
{
    class Program
    {
        static void Main(string[] args)
        {
            ConnectionFactory factory = new ConnectionFactory()
            {
                HostName = "127.0.0.1",
                UserName = "mytest",
                Password="mytest"
            };
            //第一步:创建connection
            var connection = factory.CreateConnection();
            //第二步:创建channel
            var channel = connection.CreateModel();
            //第三步:申明交换机

            //第四步:声明一个队列
            channel.QueueDeclare("manQueue", true, false, false, null);
            var msg = Encoding.UTF8.GetBytes("希望!");
            //第五步:发布消息
            channel.BasicPublish(string.Empty, routingKey: "manQueue", basicProperties: null, body: msg);

            Console.WriteLine("完成");
        }
    }
}

3.创建一个控制台项目 取名 Consumer代码如下:

using RabbitMQ.Client;
using System;
using System.Text;

namespace Consumer
{
    class Program
    {
        static void Main(string[] args)
        {
            ConnectionFactory factory = new ConnectionFactory()
            {
                HostName = "127.0.0.1",
                UserName = "mytest",
                Password = "mytest"
            };
            //第一步:创建connection
            var connection = factory.CreateConnection();
            //第二步:创建channel
            var channel = connection.CreateModel();
            //第三步:申明交换机

            //第四步:获取消息
            var result = channel.BasicGet("manQueue", true);
            var msg = Encoding.UTF8.GetString(result.Body);

            Console.WriteLine(msg);
        }
    }
}

 

以上是关于2.RabbitMQ的quick start的主要内容,如果未能解决你的问题,请参考以下文章

javascript 来自http://mongodb.github.io/node-mongodb-native/3.1/quick-start/quick-start/

etherlime-1-Quick Start

Commons Configuration2 - Quick start guide

sass quick start

eslint quick start

[转]TypeScript Quick start