如何向特定消费者发送消息

如何向特定消费者发送消息

本文介绍了MassTransit:如何向特定消费者发送消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对不起,如果我的问题很愚蠢,我是MassTransit的新手.

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

我的系统由一台服务器和多个客户端设备组成.我想从服务器向特定客户端或一组客户端发送消息.据我了解, IBusControl.Publish 将消息发送给所有订阅者,而 IBusControl.Send 发送给唯一的订阅者.

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.

如何使用MassTransit实现此目的?我的交通工具是RabbitMQ/Azure服务总线.

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

谢谢!

推荐答案

MassTransit实现标准的消息传递模式,该模式不是MassTransit特定的.点对点,发布-订阅,无效的消息通道,死信通道等:

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

您确实可以选择使用 Send 向一个使用者发送消息,以及使用 Publish 将消息广播给该消息类型的所有订阅者.

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", ... });

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

    ...
}

这篇关于MassTransit:如何向特定消费者发送消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 05:34