RabbitMQ的基本使用

RabbitMQ的基本使用

引入程序集:RabbitMQ.Client

生产者

/// 
/// ProducerWrites 写入消息  ConsumerConsumption 消费消息
/// 
public class ProducerWrites
{
    public static void Send()
    {

        string path = AppDomain.CurrentDomain.BaseDirectory;
        string tag = path.Split('/', '\\').Last(s => !string.IsNullOrEmpty(s));
        Console.WriteLine($"这里是 {tag} 启动了。。");

        //创建链接:通过一个connection工厂来创建链接
        ConnectionFactory factory = new ConnectionFactory();
        factory.HostName = "localhost";//RabbitMQ服务在本地运行
        factory.UserName = "guest";//用户名
        factory.Password = "guest";//密码 
        //factory.VirtualHost = "/Richard";
        //创建链接
        using (IConnection connection = factory.CreateConnection())
       

你可能感兴趣的:(C#,.Net,rabbitmq,分布式,c#)