I am trying to register multiple RabbitMQ's consumers using Steeltoe, but only one is "processing" the messages. For the other consumer I get:
"Dispatcher has no subscribers for channel 'myConsumer'"
Say below are my two consumers:
Consumer #1
[EnableBinding(typeof(ISink))]
public class LoggingConsumer
{
[StreamListener(ISink.INPUT)]
public void Handle(Person person)
{
Console.WriteLine("Received: " + person);
}
}
Consumer #2
[EnableBinding(typeof(IEnrollment))]
public class EnrollmentConsumer
{
[StreamListener(IEnrollment.INPUT)]
public void Handle(Enroll message)
{
Console.WriteLine("Received: " + message);
}
}
How can I register multiple Consumers since only one .AddStreamServices<LoggingConsumer>();
is allowed in Program.cs?
Thanks!
I have followed the sample provided by Steeltoe to register a Consumer. (https://docs.steeltoe.io/guides/stream/quick-start.html)
Also, if I add the second consumer as service.AddStreamBinding(); it only creates the consumer in RabbitMQ's Queue.
@DanielCCR, It is possible to subscribe to multiple producers and consumers in a couple of different ways. The simple way is to create one type with an EnableBinding Attribute on it and have multiple input/output destinations inside. See example here.
Alternatively, you can keep these separate but add a few extension methods to add multiple producers/consumers like in this example. which will allow you to do this:
builder.Host.AddStreamServices(typeof(SampleSource), typeof(SampleSink));