Rebus中是否有任何机制可以指定在speficic处理程序处理消息后调用的操作?换句话说,回调?
我这样注册汉斯勒:
serviceCollection.AutoRegisterHandlersFromAssemblyOf<Handler1>()
serviceCollection.AddRebus(....);
var serviceProvider = serviceCollection.BuildProvider();
serviceProvider.UseRebus();
public class Handler1 : IHandleMessages<Message1>
{
public Task Handle(Message1 message)
{
Console.WriteLine($"Handler1 received : {message}");
return Task.CompletedTask;
}
}
现在,我想做这样的事情:
serviceProvider.GetService<IBus>(); //or whatever needed
//wait 2000ms until Handler1 handles Message1 with specific ID
await bus.WaitUntilHandled<Handler1, Message1>(
message => message.Id = id,
new TaskCancellationSource(2000));
答案 0 :(得分:1)
Rebus'内置的扩展机制(适用于the message pipelines)可以让你做任何你想做的事情,但在你的情况下,我认为更容易引入Rebus.Events并做类似的事情这样:
Configure.With(...)
.(...)
.Events(e =>
{
e.AfterMessageHandled += (bus, headers, message, context, args) =>
{
// do your thing in here
};
});