简体   繁体   中英

How I can subscribe to one queue by multiple consumers using MassTransit?

I'm using Azure Service Bus as transport for MassTransit and I'm trying to send message(command) to queue:

var sendEndpoint = await busControl.GetSendEndpoint(sericeUri);
sendEndpoint.Send<ISimpleRequest>(new SimpleRequest(customerId));

Also I try to connect to this queue by two consumers:

var _busControl = Bus.Factory.CreateUsingAzureServiceBus(cfg =>
            {
                var host =  cfg.Host("...", h =>
                {
                    h.OperationTimeout = TimeSpan.FromMinutes(1);
                });
                cfg.ReceiveEndpoint(host, "queueName",
                    e => { e.Consumer<RequestConsumer>(); });
                cfg.UseServiceBusMessageScheduler();
            });

The same code with same queue name for second consumer. After I send message only one consumer get the response. So how I can config this to work with two or more consumers?

If you want to get two copies of the message, one for each consumer, you should use two separate queues and Publish the message. In this case, MassTransit will send it to the topic, and each queue will receive a copy forwarded from the topic.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM