• RabbitMQ .net core 客户端 EasyNetQ 的使用


    依赖注入

                var connectionConfiguration = new ConnectionConfiguration
                {
                   
                    Hosts = new List<HostConfiguration>
                    {
                        new HostConfiguration 
                        { 
                            Host = hostName,
                            Port = Convert.ToUInt16(mqport) 
                        }
                    },
                    Port = Convert.ToUInt16(mqport),
                    VirtualHost = "/",
                    UserName = userName,
                    Password = password
                };
                services.AddSingleton(RabbitHutch.CreateBus(connectionConfiguration, x =>
                {
    
                }));

    接收消息

    IBus对象通过依赖注入获取

                var exchange = _bus.Advanced.ExchangeDeclare("ExchangeNAME", ExchangeType.Topic);
                var nickNameQu = _bus.Advanced.QueueDeclare("queuename");
                _bus.Advanced.Bind(exchange, nickNameQu, "RouterKey1");
                _bus.Advanced.Bind(exchange, nickNameQu, "RouterKey2");
                _bus.Advanced.Consume(nickNameQu, (data, properties, info) =>
                {
                    var msg = Encoding.UTF8.GetString(data);
                });

    消息发送

                        var exchange = this.Bus.Advanced.ExchangeDeclare("ExchangeNAME", ExchangeType.Topic);
                        this.Bus.Advanced.Publish(exchange, "RouterKey1", false, new MessageProperties(), Encoding.UTF8.GetBytes("消息内容"));
  • 相关阅读:
    删除链表的倒数第N个节点(java实现)
    Java多线程之volatile关键字《一》
    Utils
    分布式和集群
    java RMIC
    Log4j输出终端(Appender)详解
    使用存储过程并返回值与及返回值的获得方法
    groupBy
    group by java实现
    本机Font字体
  • 原文地址:https://www.cnblogs.com/IWings/p/13495486.html
Copyright © 2020-2023  润新知