【发布时间】:2022-01-15 07:47:42
【问题描述】:
在测试项目中我想执行CallbackReceivedEventHandler中的代码
所以我试图向这个消费者“发布”一些东西,但最终消费者没有被调用。我做错了什么?
我必须让消费者响应一些东西,然后在测试项目中使用 RequestClient...这不是一个好的解决方法...消费者不应该响应任何东西
请帮忙
应用项目
public class CallbackReceivedEventHandler : IConsumer<CallbackReceivedEvent>
{
public async Task Consume(ConsumeContext<CallbackReceivedEvent> context)
{
//Breakpoint is here
...
await context.RespondAsync(new CallbackReceivedEventResponse()); // I want to remove this thing
}
测试项目
provider = new ServiceCollection()
.AddMassTransitInMemoryTestHarness(cfg =>
{
configurator.AddConsumers(typeof(CallbackReceivedEventHandler));
})
.AddGenericRequestClient()
.BuildServiceProvider(true);
var harness = provider.GetRequiredService<InMemoryTestHarness>();
await harness.Start();
var bus = provider.GetRequiredService<IBus>();
CallbackReceivedEvent input = new()
// NOT WORK
await bus.Publish(input); //KO! the consumer is not called (breakpoint in Consume is not hit)
// WORK!
var requester = bus.CreateRequestClient<CallbackReceivedEvent>();
await requester.GetResponse<CallbackReceivedEventResponse>(input); //OK! the consumer is called (breakpoint in Consume is hit)
【问题讨论】:
标签: c# masstransit