我需要找到一种在自定义标头中添加原始值,然后在Rabbit消息标头中检索自定义标头的方法。理想情况下,我们应该采用这种方式。
到目前为止,我一直没有找到成功的方法。
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"}
答案 0 :(得分:0)
直接来自the tutorial:
在下面的示例中,我们发布带有自定义标头的消息:
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);