问题
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