RabbitMQ.Client.Core.DependencyInjection icon indicating copy to clipboard operation
RabbitMQ.Client.Core.DependencyInjection copied to clipboard

Can't Produce and Consume messages in same application

Open danieliu456 opened this issue 4 years ago • 4 comments

I Have use case where I need to consume message, make some work and push it back to other queues. The problem is that DI container have some strange behavior in Worker application.

services
    //.AddRabbitMqClient(rabbitConnection)
    .AddRabbitMqConsumingClientSingleton(rabbitConnection)
    .AddConsumptionExchange("exchange", consumption.ExchangeOptions)
    .AddMessageHandlerSingleton<MessageHandler>("RKey", "exchange");

services.AddHostedService<ConsumingService>();

When I try to use AddRabbitMqClient(rabbitConnection) It will inject IQueueService, but application wont start,

image

managed to make work around by injecting .AddRabbitMqConsumingClientSingleton(rabbitConnection), because it injects only IConsuming service and then application starts successfully (MessageHandlerSingleton)

image

But when I Added .AddRabbitMqProducingClientSingleton(rabbitConnection) It fails. First of all it will not inject IQueueService we can check that in IServiceCollection List, so I can reach produce methods only by injecting IProduceService to send some messages to rabbit.

services
    .AddRabbitMqConsumingClientSingleton(rabbitConnection)
    .AddRabbitMqProducingClientSingleton(rabbitConnection)
     .AddProductionExchange("exchange", production.ExchangeOptions)
    .AddConsumptionExchange("exchange", consumption.ExchangeOptions)
    .AddMessageHandlerSingleton<MessageHandler>("RKey", "exchange");

Consuming still works after adding ProducingClientSingleton

But When I try to inject IProducingService producingService to Message Handler application freezes and DI container do not construct MessageHandler Singleton and ConsumingService anymore and there is no any error messages. :/

I am trying to make connection to the same server but different exchanges, maybe I have missed something in the documentation ?

RabbitMQ.Client.Core.DependencyInjection V4.3.0

.Net core 3.1

danieliu456 avatar Dec 17 '20 11:12 danieliu456

I am seeing this too. Interested to hear the outcome!

virtualas10 avatar Dec 17 '20 12:12 virtualas10

any updates on this issue?

MaslovD avatar Jun 03 '21 02:06 MaslovD

I'll try to take a look at this next week

antonyvorontsov avatar Jun 04 '21 18:06 antonyvorontsov

@AntonyVorontsov any update?

remotenode avatar Oct 20 '21 21:10 remotenode