1
我一直在研究基於消息傳遞啓動一些工作者角色的應用程序。使用C#中的Masstransit/RabbitMQ將消息發送到特定的通道/路由密鑰
這是我想要的應用程序的工作方式:
Client sends a request for work (RPC).
One of the worker roles accepts the work, generates a random id, and responds to the RPC with the new id.
The worker will post its debug logs on a log channel with the id.
The client will subscribe to this channel so users can see what's going on.
的RPC工作正常,但我似乎無法弄清楚如何實施日誌傳送。
這是接受工作的代碼(簡化)
var bus = Bus.Factory.CreateUsingRabbitMq(sbc =>
{
var host = sbc.Host(new Uri("rabbitmq://xxxxxx.nl"), h =>
{
h.Username("xxx");
h.Password("xxxx");
});
sbc.ReceiveEndpoint(host, "post_work_item", e =>
{
e.Consumer<CreateWorkItemCommand>();
});
sbc.ReceiveEndpoint(host, "list_work_items", e =>
{
e.Consumer<ListWorkItemsCommand>();
});
});
的CreateWorkItemCommand
將創建線程,做的工作,等等。現在,我將如何實現日誌發送帶有Masstransit?我的想法是這樣的:
bus.Publish(
obj: WorkUpdate{ Message = "Hello world!" },
channel: $"work/{work_id}"
)
而且客戶會做一些這樣的:
bus.ReceiveFromEvented($"work/{rpc.work_id}").OnMessage += { more_psuedo_code() }
我似乎無法找出如何做到這一點。
任何人都可以幫我嗎?
謝謝!