RabbitMQ随手笔记(六)发送消息(.netCore2.0)

发送消息源码:

               string message = "Hello Word!";
                var body = Encoding.UTF8.GetBytes(message);
                //消息属性
                var properties = channel.CreateBasicProperties();
                properties.Persistent = true; //消息持久化
                properties.Priority = 1;//设置优先级
                properties.ContentType = "";//MIME类型
                //包含消息头
                IDictionary<string, object> Headers = new Dictionary<string, object>();
                Headers.Add("localtion", "here");
                Headers.Add("time", "today");
                properties.Headers = Headers;
                //消息过期规范
                properties.Expiration = "60000";
                //发送消息01
                channel.BasicPublish(EXCHANGE_NAME, ROUTING_KEY, properties, body); 

public static void BasicPublish(this IModel model, string exchange, string routingKey, IBasicProperties basicProperties, byte[] body);

参数说明:

exchange:交换器名称

routingKey:路由键

basicProperties:消息属性

body:消息体

其中basicProperties消息属性主要介绍如下:

properties.Persistent = true; //true为消息持久化,false为非持久化

properties.Priority = 1;//设置优先级,可以只是0-9

properties.ContentType = "text/plain";//可以设置MIME类型

properties.Headers = Headers;// //包含消息头

properties.Expiration = "60000";//消息过期规范



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值