首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Rebus消息变更器

Rebus消息变更器
EN

Stack Overflow用户
提问于 2020-07-02 22:56:11
回答 1查看 64关注 0票数 0

在某种程度上,Rebus支持消息变更器。在Rebus源代码中我似乎再也找不到它们了。它们被重命名了吗?它们还存在吗?

示例代码:

代码语言:javascript
复制
Configure.With(senderAdapter)
    .Transport(t => t.UseMsmq(SenderInputQueueName, "error"))
    .Events(e =>
        {
            e.MessageMutators.Add(new EvilMutator("first"));
            e.MessageMutators.Add(new EvilMutator("second"));
            e.MessageMutators.Add(new EvilMutator("third"));
        })
    .CreateBus().Start();
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-07-03 16:05:18

"Rebus 2“(从0.90.0开始的所有Rebus版本)没有消息变更器,因为它具有超强的可扩展性,并且使用传入/传出管道添加一些改变传入/传出消息的内容非常容易。

管道遵循“俄罗斯玩偶”模型,其中每个步骤负责调用管道的其余部分。

添加一个新的"mutator“步骤可以像这样完成--首先,我们创建一个能够改变传入/传出消息的步骤:

代码语言:javascript
复制
public class MyMutatorStep : IIncomingStep, IOutgoingStep
{
    public async Task Process(OutgoingStepContext context, Func<Task> next)
    {
        // here we have the message
        var message = context.Load<Message>();

        // mutate (or, more like "cripple", actually ?)
        context.Save(new Message(headers: message.Headers, body: new object()));

        await next();
    }

    public async Task Process(IncomingStepContext context, Func<Task> next)
    {
        // here we have the message again
        var message = context.Load<Message>();

        await next();
    }
}

然后我们装饰管道,分别注入序列化之前/反序列化之后的步骤:

代码语言:javascript
复制
Configure.With(...)
    .(...)
    .Options(o => o.Decorate<IPipeline>(c => {
        var pipeline = c.Get<IPipeline>();
        var step = new MyMutatorStep();

        return new PipelineStepInjector(pipeline)
            .OnReceive(step, PipelineStepRelativePosition.After, typeof(DeserializeIncomingMessageStep))
            .OnSend(step, PipelineStepRelativePosition.Before, typeof(SerializeOutgoingMessageStep));
    }))
    .Start();

在本例中,我通过用new object()替换消息体来改变传出消息,这可能不是您想要的?,但希望您能对这种可能性有所了解。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62699211

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档