在某种程度上,Rebus支持消息变更器。在Rebus源代码中我似乎再也找不到它们了。它们被重命名了吗?它们还存在吗?
示例代码:
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();发布于 2020-07-03 16:05:18
"Rebus 2“(从0.90.0开始的所有Rebus版本)没有消息变更器,因为它具有超强的可扩展性,并且使用传入/传出管道添加一些改变传入/传出消息的内容非常容易。
管道遵循“俄罗斯玩偶”模型,其中每个步骤负责调用管道的其余部分。
添加一个新的"mutator“步骤可以像这样完成--首先,我们创建一个能够改变传入/传出消息的步骤:
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();
}
}然后我们装饰管道,分别注入序列化之前/反序列化之后的步骤:
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()替换消息体来改变传出消息,这可能不是您想要的?,但希望您能对这种可能性有所了解。
https://stackoverflow.com/questions/62699211
复制相似问题