I have two projects run in different processes and RMQ deployed on a separate machine.
Here is my publisher code
Bus.Initialize(config =>
{
config.UseRabbitMq();
config.UseRabbitMqRouting();
config.UseControlBus();
config.EnableMessageTracing();
config.EnableRemoteIntrospection();
config.ReceiveFrom("rabbitmq://debug:[email protected]:5672/bus/response-queue");
});
Console.ReadLine();
int i = 0;
while (i < 20)
{
i += 1;
Console.WriteLine("Publishing...");
Bus.Instance.Publish(new Message
{
Body = String.Format("Body = {0}", i)
});
Console.ReadLine();
}
Console.ReadLine();
Here is my subscriber code:
Bus.Initialize(config =>
{
config.UseRabbitMq();
config.UseRabbitMqRouting();
config.ReceiveFrom("rabbitmq://debug:[email protected]:5672/bus/response-queue");
config.UseControlBus();
config.EnableMessageTracing();
config.UseHealthMonitoring(10);
});
var service = HostFactory.New(config =>
{
config.SetServiceName("survey");
config.SetDisplayName("survey");
config.SetDescription("Survey service");
config.Service<Service>(s =>
{
s.ConstructUsing(sv => new Service(Bus.Instance));
s.WhenStarted(sv => sv.Start());
s.WhenStopped(sv => sv.Stop());
});
});
Task.Factory.StartNew(() =>
{
try
{
service.Run();
}
catch (Exception e)
{
Console.WriteLine(e);
}
});
In the server, I've the following subscription:
public Service(IServiceBus serviceBus)
{
_serviceBus = serviceBus;
_serviceBus.SubscribeHandler<Message>(Handle);
}
void Handle(Message message)
{
Console.WriteLine("Receive a new message with body {0}", message.Body);
}
When I send a set of messages by publisher, only few of them successfully reach subscriber. Most of them fall in response-queue-error.
I am new with masstransit and I do not understand what's going on inside it and do not understand how I can figure it out.
Anything you can recommend in this situation?
I notice that the publisher and subscriber in your example are listening on the same queue. In general, you should have every endpoint on a separate queue. MassTransit will take care of routing the messages based on the type.