I'm using MassTransit and Azure Service Bus as transport. I have created IAlert and IAlertExt that implements IAlert. I'm trying to publish two messages:
busControl.Publish<IAlert>(new Alert(customerId));
busControl.Publish<IAlertExt>(new AlertExt(customerId));
And write consumers to handle messages:
public class AlertConsumer : IConsumer<IAlert>
{
public async Task Consume(ConsumeContext<IAlert> context){
...
}
}
public class AlertExtConsumer : IConsumer<IAlertExt>
{
public async Task Consume(ConsumeContext<IAlertExt> context){
...
}
}
Now after publish both consumers retrieve one message that was published with generic interface.
How to force AlertExtConsumer retrieve messages not only published with IAlertExt and also with IAlert?
You can put both interfaces in the same consumer, as shown below.
public class AlertConsumer :
IConsumer<IAlert>,
IConsumer<IAlertExt>
{
public async Task Consume(ConsumeContext<IAlert> context){
...
}
public async Task Consume(ConsumeContext<IAlertExt> context){
...
}
}
Both interfaces will be bound to the same consumer queue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With