c# - 如何添加自定义 header ,然后在兔子消息 header 中检索自定义 header

标签 c# .net-core rabbitmq rawrabbit

我需要找到一种方法在自定义 header 中添加原始值,然后在兔子消息 header 中检索自定义 header 。理想情况下,我们应该这样。

到目前为止,我没有成功地尝试找到一种方法来做到这一点。

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"}

最佳答案

直接来自the tutorial :

In the following example, we publish a message with custom headers:

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);

关于c# - 如何添加自定义 header ,然后在兔子消息 header 中检索自定义 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57218661/

相关文章:

c# - 如何检查/反汇编 Visual Studio 扩展

c# - C++程序输出数据到C#

.net-core - 无法使用 Fedora 31 安装 .NET Core 3.1

c# - 如何为 ActiveAuthenticationSchemes 设置默认值?

rabbitmq - 在哪里设置交换器和队列(生产者与消费者)的绑定(bind)?

c# - 当多个用户同时参加考试时,在线考试考试会分开

c# - 函数的 IDL 声明(在 C++ 中)将从 C# 获取 C 样式数组

C# - Blazor @onlick 如何单击 HTML 元素

Erlang 机器立即停止(发行版名称冲突?)。由于 OnFail 设置为忽略,因此服务未重新启动

javascript - RabbitMQ for NodeJS with Express 路由