MassTransit: how to send a message to specific consumers?

柔情痞子 提交于 2021-02-10 14:14:43

问题


Sorry if my question is dumb, I'm new to MassTransit.

My system consists of a server and multiple client devices. I'd like to send a message from the server to a specific client or to a group of clients. As far as I understand, IBusControl.Publish sends the message to all subscribers, and IBusControl.Send to the only one subscriber.

How can I achieve this using MassTransit? My transports are RabbitMQ / Azure Service Bus.

Thanks!


回答1:


MassTransit implements standard messaging patterns, which aren't MassTransit-specific. Point-to-point, publish-subscribe, invalid message channel, dead letter channel and so on:

You indeed have the choice between sending a message to one consumer using Send and to broadcast messages to all subscribers for that message type by using Publish.

Everything else can be easily done by adding code to consumers:

await bus.Publish(new MyMessage { ReceiverGroup = "group1", ... });

and

public async Task Consume(IContext<MyMessage> context)
{
    if (context.Message.ReceiverGroup != myGroup) return;

    ...
}


来源:https://stackoverflow.com/questions/55134113/masstransit-how-to-send-a-message-to-specific-consumers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!