zoukankan      html  css  js  c++  java
  • 6.Header交换机之模拟验证用户身份

    标题 :
    6.Header交换机之模拟验证用户身份
    目录 :
    RabbitMQ
    序号 :
    6

            var channel = connection.CreateModel();
    


    //设置服务质量
    channel.BasicQos(0, 1, false);

    //定义一个类型为Headers的交换机
    channel.ExchangeDeclare(exchangeName, ExchangeType.Headers, true, false, null);


    //定义一个队列,将用于存放用户的信息
    channel.QueueDeclare(queue: queueName, durable: true, exclusive: false, autoDelete: false, arguments: null);


    //将队列绑定到交换机上
    channel.QueueBind(queueName, exchangeName, string.Empty, new Dictionary<string, object>()
    {
    {"x-match", "any"},
    {"username", "tangxiaobing"}
    });


    //定义消费者
    var consumer = new EventingBasicConsumer(channel);
    consumer.Received += (model, ea) =>
    {
    var body = ea.Body;
    var message = Encoding.UTF8.GetString(body);
    Console.WriteLine("用户名匹配,验证通过,信息:{0}", message);
    channel.BasicAck(ea.DeliveryTag, false);
    };
    channel.BasicConsume(queue: queueName, false, consumer: consumer);


    Console.WriteLine(" Press [enter] to exit.");
    Console.ReadLine();
    }
    }
    }

    - 在将队列绑定到交互机时,需要注意设置配置规则参数arguments
    ```csharp
        void QueueBind(
          string queue,
          string exchange,
          string routingKey,
          IDictionary<string, object> arguments);
    
    • x-match 取值为 any,表示arguments参数中指定的header只要有任意一个匹配,就会被路由到队列.

    引用链接

    [无]

    请尽量按照自己期望的生活 email:18980489167@189.cn
  • 相关阅读:
    Sql Server 2008学习之第二天
    Sql Server 2008学习之第一天
    Codeforce 1175 D. Array Splitting
    CF1105C Ayoub and Lost Array ——动态规划
    数据结构——并查集
    动态规划——01背包问题
    常用技巧——离散化
    动态规划——稀疏表求解RMQ问题
    基础算法—快速幂详解
    欧拉函数及其扩展 小结
  • 原文地址:https://www.cnblogs.com/gytangyao/p/11406098.html
Copyright © 2011-2022 走看看