zpjx 发表于 2017-7-2 16:08:41

RabbitMQ 记录

  RabbitMQ 中文文档 : http://rabbitmq.mr-ping.com/description.html
  官方教程译文:
  一 http://blog.csdn.net/xiaoxian8023/article/details/48679609
  二 http://blog.csdn.net/xiaoxian8023/article/details/48681987
  三 http://blog.csdn.net/xiaoxian8023/article/details/48710653
  四 http://blog.csdn.net/xiaoxian8023/article/details/48729479
  五 http://blog.csdn.net/xiaoxian8023/article/details/48733249
  六 http://blog.csdn.net/xiaoxian8023/article/details/48806871
  七 http://blog.csdn.net/xiaoxian8023/article/details/48826857
  1. BasicPublish发送久化消息  



       var properties = channel.CreateBasicProperties();
properties.SetPersistent(false);
channel.BasicPublish(exchange: "", routingKey: "task_queue", basicProperties: properties, body: body);
Console.WriteLine(" Sent {0}", message);

  BasicPublish方法的参数BasicProperties,SetPersistent为false的时候消息不能持久化,重启MQ会丢失。
  SetPersistent(false); 被标记为已过时,新方法为:properties.DeliveryMode = 2; 。
  2. QueueDeclare 和 QueueBind
  QueueDeclareOk QueueDeclare(string queue, bool durable, bool exclusive, bool autoDelete, IDictionary<string, object> arguments)
  void QueueBind(string queue, string exchange, string routingKey);
  从结果上看,两个方法都可以做Queue绑定之后读取Message。区别是,QueueDeclare 参数列表中所指定的 queue(实际是QueueName) 如果不存在,将会自动创建一个Queue,这种做法在实际研发中并不推荐。
  3. topic 模式绑定的用法(反复几次都记不住)
  首先将 exchange 设置为 topic 模式,然后在queue绑定的时候将 routingKey 设置为 #.exchange 或者 *.*.exchange 进行路由模糊匹配。
  4. 匿名 exchange 和匿名临时 queue
  日志系统比较适合匿名queue,参见 http://www.rabbitmq.com/tutorials/tutorial-three-dotnet.html 。
  有 consumer 的时候可以正常消费 message, 没有 consumer 连接的时候消息也不会保留。
  5. noAck = false 用于用于标记 consumer 接受到消息必须返回给 RabbitMQ 确认信息之后,消息才会被移除。如果 consumer 的 noAck = true ,则消息发送出去就立即被移除。
  6. exlusive 用于标记排他型队列,DeclareQueue 的时候,如果 exclusive:true ,则链接断开的时候 Queue 将被清除。
页: [1]
查看完整版本: RabbitMQ 记录