c# - 消息未到达公共(public)交通中的订阅者

标签 c# .net rabbitmq esb masstransit

我有两个项目在不同的进程中运行,RMQ 部署在不同的机器上。

这是我的发布者代码

Bus.Initialize(config =>
            {
                config.UseRabbitMq();
                config.UseRabbitMqRouting();
                config.UseControlBus();
                config.EnableMessageTracing();
                config.EnableRemoteIntrospection();
                config.ReceiveFrom("rabbitmq://debug:debug@data.sampleserver.com: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();

这是我的订阅者代码:

Bus.Initialize(config =>
            {
                config.UseRabbitMq();
                config.UseRabbitMqRouting();
                config.ReceiveFrom("rabbitmq://debug:debug@data.sampleserver.com: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);
                }
            });

在服务器中,我有以下订阅:

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);
        }

当我通过发布者发送一组消息时,只有少数消息成功到达订阅者。他们中的大多数都属于响应队列错误。

我是公共(public)交通的新手,我不明白里面发生了什么,也不明白我该如何解决。

在这种情况下,您有什么可以推荐的吗?

最佳答案

我注意到您示例中的发布者和订阅者正在监听同一个队列。通常,您应该将每个端点都放在一个单独的队列中。 MassTransit 将负责根据类型路由消息。

关于c# - 消息未到达公共(public)交通中的订阅者,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11406920/

相关文章:

docker - 如何使用 docker-compose 链接从另一个容器内访问用户名和密码详细信息

concurrency - 将 celery 并发设置为每个队列 1 个 worker

c# - .NET HttpClient 的 Http 连接变慢或死锁

c# - WCF 客户端切换和故障转移功能的设计模式?

c# - 使用 C# 将图像上传到 Web API

c# - Delphi DLL 从 C# 返回字符串 ... .NET 4.5 堆损坏但 .NET 4.0 有效?请解释?

python - celery 重复任务不执行

c# - 从 MS CRM 工作流事件调用 SQL Server Reporting Services

c# - 动态构建的正则表达式运行速度极慢!

c# - NETSDK1201 : For projects targeting . NET 8.0 及更高版本,默认情况下指定 RuntimeIdentifier 将不再生成自包含应用程序