Home > Blockchain >  How to change RabbitMq informations after start a connection using MassTransit?
How to change RabbitMq informations after start a connection using MassTransit?

Time:12-16

I'm using the latest version of MassTransit nuget. I want to dynamically change the configuration of the RabbitMq that the server is using to communicate. The connection is being made by dependency injection in the Startup:

services.AddMassTransit(x =>
            {
                x.UsingRabbitMq((cxt, cfg) =>
                {
                    cfg.ConfigureEndpoints(cxt);

                    cfg.Host(address, port, virtualHost, h =>
                    {
                        h.Username(user);
                        h.Password(password);
                    });
                });
            });

If for some reason the user wants to connect to another RabbitMq, without the context of MultiBus, just stopping the actual bus and start a new one, how can I do that? How can I see in the RabbitMq interface when a bus is started or when it's killed(stopped)?

I've tried to stop the actual bus connection with the information saved in the database and start a new bus with the user input information, but I think that is not right.

actualBus.stopAsync(); 
newBus.startAsync();

I want to get a way to stop the bus I'm starting in the Startup and create a new one at some point in the application without a problem.

CodePudding user response:

There is no provision to change the bus configuration once it has been configured. You can stop and start it, but only the same bus with the same configuration.

You can use an IBusObserver registered in the container to observe bus start/stop events.

  • Related