我在C#中使用MassTransit和rabbitMQ。如何獲得發佈商中的事件響應?
我向消費者發送命令,讓他們進入消費者並執行所需任務並嘗試向發佈者發送響應。
using MyCompany.Messaging;
using System;
using System.Threading.Tasks;
namespace MassTransit.Receiver
{
public class RegisterCustomerConsumer : IConsumer<IRegisterCustomer>
{
public Task Consume(ConsumeContext<IRegisterCustomer> context)
{
IRegisterCustomer newCustomer = context.Message;
Console.WriteLine("A new customer has signed up, it's time to register it in the command receiver. Details: ");
Console.WriteLine(newCustomer.Address);
Console.WriteLine(newCustomer.Name);
Console.WriteLine(newCustomer.Id);
Console.WriteLine(newCustomer.Preferred);
context.Publish<ICustomerRegistered>(new
{
Address = newCustomer.Address,
Id = newCustomer.Id,
RegisteredUtc = newCustomer.RegisteredUtc,
Name = newCustomer.Name
});
return Task.FromResult(context.Message);
}
}
}
我發現這個示例代碼,它正確地獲取消息並執行相關任務。話題 作者加入此評論:
Note that we didn’t have to specify a queue name here as opposed to sending a command to a single queue. We’ll see that the queue names are only provided in the consumers. MassTransit will create the necessary queues in the background.
現在,這裏將發表響應消息,以及如何獲得出版商對此有何反應?
感謝
貌似出版商應該訂閱'ICustomerRegistered'事件。 –