I bind to an exchange with different routing keys for each type of message.
I would like to have only 1 consumer for all these types of messages.
private static void ConfigureEndpoint<TConsumer, TEvent>(
this IRabbitMqBusFactoryConfigurator bus,
IRegistrationContext registration,
Param param)
where TConsumer : class, IConsumer
where TEvent : class, IMessage =>
bus.ReceiveEndpoint(Param.Queue,
endpoint =>
{
endpoint.UseInMemoryOutbox();
endpoint.ConfigureConsumeTopology = false;
endpoint.ClearSerialization();
endpoint.UseRawJsonSerializer();
endpoint.Bind(
param.Exchange,
x =>
{
x.RoutingKey = param.RoutingKey;
x.ExchangeType = param.ExchangeType;
x.Durable = true;
});
endpoint.Bind<TEvent>(x =>
{
x.RoutingKey = param.RoutingKey;
x.ExchangeType = param.ExchangeType;
});
endpoint.ConfigureConsumer<TConsumer>(registration);
});
For each type of message I have a routing key. So I have this same configuration for MessageOne and MessageTwo
public class TesteConsumer :
IConsumer<MensageOne>,
IConsumer<MensageTwo>
When I receive the message, the Bind is occurring on the two types that are registered in the Consumer. Not only where Bind is configured by routing key and type.
I noticed on the rabbit mq portal that the binding created in Exchange for my queue is ok, the message is published in the exchange and routed to the queue related to the event, but when this message is consumed it is consumed by all ConsumeContext registered in the Consumer