简体   繁体   English

是否可以向ServiceStack Redis消息中添加自定义标头?

[英]Is it possible to add custom headers to a ServiceStack Redis message?

When a message is sent to Redis using ServiceStack, the framework adds all the standard headers ( Priority , CreatedDate , ...). 使用ServiceStack将消息发送到Redis时,框架会添加所有标准标头( PriorityCreatedDate ,...)。 However, is it possible to add any custom headers to that message? 但是,是否可以在该消息中添加任何自定义标头? I've got a set of microservices that pass messages amongst each other, and I'd like to include a shared header. 我有一组在彼此之间传递消息的微服务,我想包括一个共享的标头。

So far, I have explored implementing my own version of IMessage or IMessageFactory, and I've looked at the different properties within RedisMqServer when boostrapping it in the IOC container, but I have yet to find anywhere I can add a new header. 到目前为止,我已经探索实施我自己的即时聊天或IMessageFactory的版本,我已经内看了一下不同的属性RedisMqServer在IOC容器boostrapping的时候,但我还没有找到任何地方,我可以添加一个新的头。

Thanks in advance! 提前致谢!

You could use the IMessage.Tag to send any user defined tag text, eg: 您可以使用IMessage.Tag发送任何用户定义的标签文本,例如:

using (var mqClient = mqServer.CreateMessageQueueClient())
{
    mqClient.Publish(new Message<HelloIntro>(new Hello { Name = "World" }) {
        Tag = "Custom"
    });
}

Otherwise I've just added support for sending Custom Headers in this commit which will now also let you send Custom Headers in the new IMessage.Meta string Dictionary, eg: 否则,我只是添加了对在此提交中发送自定义标头的支持,现在,它也使您可以在新的IMessage.Meta字符串字典中发送自定义标头,例如:

using (var mqClient = mqServer.CreateMessageQueueClient())
{
    mqClient.Publish(new Message<HelloIntro>(new Hello { Name = "World" }) {
        Meta = new Dictionary<string, string> { { "Custom", "Header" } }
    });
}

Which you can access in your MQ RegisterHandler , eg: 您可以在MQ RegisterHandler访问哪个,例如:

mqServer.RegisterHandler<Hello>(m =>
    new Message<HelloResponse>(new HelloResponse { 
        Result = "Hello, {0}!".Fmt(m.GetBody().Name) 
    }) { 
        Meta = m.Meta 
    });

Your MQ Handler can also now return an IMessage response which allows full round-tripping of any custom headers. 您的MQ处理程序现在还可以返回IMessage响应,该响应允许任何自定义标头的完全往返。

This change is available from v4.0.57 that's now available on MyGet . 从v4.0.57开始可以进行此更改,现在可以在MyGet上使用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM