Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we use RabbitMQ and Mediatr together using masstransit?

I created a microservice application that microservices using MassTransit and RabbitMQ for communication.
Each microservice developed using clean architecture, so we have MediatR inside each microservice.
Is it possible to use MassTransit for inside communication as well? so I can use the same signature for all services and when I want to expose a service to be used inter-microservice, it will be doable with ease. So MediatR used for intra-communication and RabbitMQ used for inter-communication, and whole universe is on MassTransit system.
[Update] My question is how we can configure consumers so some can be used for inside communication (via MediatR) and some can be used for external communication (via RabbitMQ) and easily change them from inside to outside.
[Update2] for example here is my MassTransit registration:

services.AddMassTransit(x =>
        {
            x.AddConsumers(Assembly.GetExecutingAssembly());

            x.AddBus(provider =>
                Bus.Factory.CreateUsingRabbitMq(cfg =>
                {
                    cfg.Host(new Uri(config.RabbitMQ.Address), h =>
                    {
                        h.Username(config.RabbitMQ.Username);
                        h.Password(config.RabbitMQ.Password);
                    });

                    cfg.ReceiveEndpoint("my-queue", ep => { ep.ConfigureConsumers(provider); });
                }));


            x.AddMediator((provider, cfg) => { cfg.ConfigureConsumers(provider); });
        });

How can I differ in internal communication and external communication? in other words, how can I register some consumers to MediatR and some to RabbitMQ?

like image 680
Mahdi Avatar asked Dec 31 '22 01:12

Mahdi


1 Answers

They can be used together, and MassTransit has its own Mediator implementation as well so you can write your handlers once and use them either via the mediator or via a durable transport such as RabbitMQ.

There are videos available that take you through the capabilities, starting with mediator and moving to RabbitMQ.

like image 71
Chris Patterson Avatar answered Jan 30 '23 13:01

Chris Patterson