Sai Siva
Sai Siva

Reputation: 11

Using Masstransit Exchange is getting created for contract and implementing , even though ConfigureConsumeTopology = false

Implementation of Masstransit using RabbitMQ

In Publisher

 cfg.Message\<IEntityMessage\>(x =\> x.SetEntityName("ExchangeName"));
public class EntityMessage: IEntityMessage

In Consumer

    cfg.ReceiveEndpoint("QueueName", c =\>   
    {
        c.ConfigureConsumeTopology = false;
        c.ConfigureConsumer\<EntityMessage\>(context);
        c.Bind("ExchangeName");
    });

How can i set the same exchange name for all my entitites.

========= Updated

My Event Bus has IEntityMessage interface and has properties. In publisher Iam having implementation of this IEntityMessage as EntityMessage and my publishing project has a configuration as below,

services.AddMassTransit(config =>
            {
                config.UsingRabbitMq((context, cfg) =>
                {
                    cfg.Host(configuration["RabbitMQConnection:Host"], "/", h =>
                    {
                        h.Username(configuration["RabbitMQConnection:Username"]);
                        h.Password(configuration["RabbitMQConnection:Password"]);
                    });

                    cfg.Message<IEntityMessage>(x => x.SetEntityName("ExchangeName"));
                                     
                    
                    cfg.ReceiveEndpoint("QueueName", c =>    //In order to subscribe the queue.
                    {
                        c.ConfigureConsumeTopology = false;
                        c.ConfigureConsumer<OtherEntityConsumer>(context);
                        c.Bind("ExchangeName");
                    });
                });
            });
            return services;

Consumer has,

services.AddMassTransit(config =>
            {
                config.AddConsumer<EntityMessageConsumer>(typeof(IEquipmentCreatedMessage));
}

cfg.Host(configuration["RabbitMQConnection:Host"], "/", h =>
                    {
                        h.Username(configuration["RabbitMQConnection:Username"]);
                        h.Password(configuration["RabbitMQConnection:Password"]);
});
                    cfg.ReceiveEndpoint("ExchangeName", c =>    //In order to subscribe the queue.
                    {
                        c.ConfigureConsumeTopology = false;
                        c.ConfigureConsumer<EntityMessageConsumer>(context);
                        c.Bind("ExchangeName");
                    });

Upvotes: 1

Views: 728

Answers (1)

Chris Patterson
Chris Patterson

Reputation: 33288

You should not set the same exchange name for all of your message types, and even if you somehow decide to try and do it anyway, you can't have a message type exchange name that is the same as the receive endpoint name (QueueName in your example).

Upvotes: 0

Related Questions