MassTransit RPC (RabbitMQ) timeout up with multiple clients

I have two node types. A Server and a Client . There will be 1 or more Server or Client currently running.

Using MassTransit and RabbitMQ, I am getting a timeout when trying the RPC pattern described here.

The code for Server and Client is simple, for testing.

Code for Server

class Program
{
    static void Main(string[] args)
    {
        var serviceBus = ServiceBusFactory.New(sbc =>
        {
            sbc.UseRabbitMq();
            sbc.ReceiveFrom("rabbitmq://192.168.10.201/mybus_responder");

            sbc.Subscribe(x =>
            {
                x.Handler<TestEvent>((ctx, @event) =>
                {
                    Console.WriteLine("Received message " + @event.Message);
                    ctx.Respond(new TestEventResponse { Response = "Processed message "" + @event.Message + """ });
                });

                x.Handler<TestEvent2>((ctx, @event) =>
                {
                    Console.WriteLine("Received message " + @event.Message);
                    ctx.Respond(new TestEventResponse2 { Response = "Processed message "" + @event.Message + """ });
                });
            });
        });

        Console.WriteLine("Listening for events...");
        Console.ReadLine();
    }
}

Code for Client

class Program
{
    static void Main(string[] args)
    {
        var serviceBus = ServiceBusFactory.New(sbc =>
        {
            sbc.UseRabbitMq();
            sbc.ReceiveFrom("rabbitmq://192.168.10.201/mybus");
        });

        Console.WriteLine("Ready to send events...");

        var eventType = false;

        while (true)
        {
            eventType = !eventType;

            var message = Path.GetFileNameWithoutExtension(Path.GetRandomFileName());

            Console.WriteLine("Sending message " + message);

            if (eventType)
            {
                serviceBus.PublishRequest(new TestEvent {Message = message}, configurator =>
                {
                    configurator.Handle<TestEventResponse>(response =>
                    {
                        Console.WriteLine(response.Response);
                    });
                    configurator.SetTimeout(TimeSpan.FromSeconds(5));
                });
            }
            else
            {
                serviceBus.PublishRequest(new TestEvent2 {Message = message}, configurator =>
                {
                    configurator.Handle<TestEventResponse2>(response =>
                    {
                        Console.WriteLine(response.Response);
                    });
                    configurator.SetTimeout(TimeSpan.FromSeconds(5));
                });
            }
        }
    }
}

If I run exactly 1 of each node type, the commands/responses perform as expected. If I have more than 1 Server instances, the commmands/responses perform as expected, distributing Client requests evenly between each ```Server`` node.

However, if I have multiple Client instances running, I will get timeouts on the ```Client`` side.

Why is this? I require support for multiple ```Client`` instances, because this is my web-tier.


Do, I believe this is simply because you end up sharing a queue between instances and they gobble each other's messages. Each client and sever needs a unique queue to read from.

链接地址: http://www.djcxy.com/p/61226.html

上一篇: 最终消息中的RabbitMQ RPC关闭响应队列

下一篇: MassTransit RPC(RabbitMQ)与多个客户端超时