c# - 如何添加自定义标头,然后在兔子消息标头中检索自定义标头
问题描述
我需要找到一种方法在自定义标头中添加原始值,然后在兔子消息标头中检索自定义标头。理想情况下,我们应该这样。
到目前为止,我没有成功尝试找到一种方法来做到这一点。
Exchange Test.Exchange
Routing Key Test.Exchange.7752275b-2323-42bf-98a4
Redelivered ●
Properties user_id:fc4c-4d9c-9e4e-ad881040d0c1
type: Events.Exchange
message_id: b2aff0d2-c8f4-4627-9826-089799bab344
delivery_mode: 2
headers: global_execution_id: 7752275b-2323-42bf-98a4-ba7a8b96f2de
sent: 2019-04-30T13:54:24.4098945Z
**origin: Test_Origin**
content_encoding: UTF-8
content_type: application/json
Payload30 bytesEncoding: string {"$id":"2","tenantId":"3456"}
解决方案
直接来自教程:
在以下示例中,我们发布带有自定义标头的消息:
byte[] messageBodyBytes = System.Text.Encoding.UTF8.GetBytes("Hello, world!");
IBasicProperties props = model.CreateBasicProperties();
props.ContentType = "text/plain";
props.DeliveryMode = 2;
props.Headers = new Dictionary<string, object>();
props.Headers.Add("latitude", 51.5252949);
props.Headers.Add("longitude", -0.0905493);
model.BasicPublish(exchangeName,
routingKey, props,
messageBodyBytes);
推荐阅读
- javascript - ReactJS根据滚动到具有动态高度的部分更改导航栏颜色
- python - 用 Python 编写 Discord 机器人 - 如何让它过滤垃圾邮件?
- ip - 在 NextJS 上获取客户端 IP 并使用 SSR
- python - 在 Python 中列出所有 Google Drive 文件和文件夹并保存 ID
- python - 我正在学习 python 并按照教程进行操作,我制作了这个骰子函数,但是 continue = input() 被捕获
- azure-devops - 缺少选项:没有分叉、克隆、提交、分支
- excel - VBA通过函数将多个参数传递给SQL
- python - matplotlib.pyplot 的直方图
- python - Django:在 DetailView 类页面中使用 For 循环
- python - 在 Scrapy 蜘蛛中使用 TextResponse