nServiceBus - 处理程序并未接收到所有命令

发布于 2024-08-25 18:08:16 字数 2007 浏览 3 评论 0原文

在基于 nServiceBus pub/sub 示例的测试项目中,我已将服务器中的bus.publish 替换为bus.send。服务器发送 50 条消息,每发送 5 条消息后等待 1 秒(即 10 次突发,每条消息 5 条)。客户端没有收到所有消息。

该解决方案有 3 个项目 - 服务器、客户端和公共消息。服务器和客户端通过 nServiceBus 通用主机托管。仅定义了一条总线。

客户端和服务器都配置为使用 StructureMap 构建器和 BinarySerialization。

服务器端点:

public class EndPointConfig : AsA_Publisher, IConfigureThisEndpoint, IWantCustomInitialization
{
    public void Init()
    {
        NServiceBus.Configure.With()
            .StructureMapBuilder()
            .BinarySerializer();
    }
}

服务器代码:

for (var nextId = 1; nextId <= 50; nextId++)
{
    Console.WriteLine("Sending {0}", nextId);

    IDataMsg msg = new DataMsg { Id = nextId, Body = string.Format("Batch Msg #{0}", nextId) };
    _bus.SendLocal(msg);
    Console.WriteLine("  ...sent {0}", nextId);

    if ((nextId % 5) == 0)
       Thread.Sleep(1000);
}

客户端端点:

public class EndPointConfig : AsA_Client, IConfigureThisEndpoint, IWantCustomInitialization
{
    public void Init()
    {
        NServiceBus.Configure.With()
            .StructureMapBuilder()
            .BinarySerializer();
    }
}

客户端 Clode:

public class DataMsgHandler : IMessageHandler<IDataMsg>
{
    public void Handle(IDataMsg msg)
    {
         Console.WriteLine("DataMsgHandler.Handle({0}, {1}) - ({2})", msg.Id, msg.Body, Thread.CurrentThread.ManagedThreadId);
     }
}

客户端和服务器 App.Config:

<MsmqTransportConfig InputQueue="nsbt02a" ErrorQueue="error" NumberOfWorkerThreads="1" MaxRetries="5" />
<UnicastBusConfig DistributorControlAddress="" DistributorDataAddress="">
    <MessageEndpointMappings>
      <add Messages="Test02.Messages" Endpoint="nsbt02a" />
    </MessageEndpointMappings>
</UnicastBusConfig>

全部通过 VisualStudio 2008 运行。

所有 50 条消息均已发送 - 但在第一批或第二批之后。每批次只发送 1 条消息?

有什么想法吗?我假设配置或误用,但是......?

In a test project based of the nServiceBus pub/sub sample, I've replace the bus.publish with bus.send in the server. The server sends 50 messages with a 1sec wait after each 5 (ie 10 burst of 5 messages). The client does not get all the messages.

The soln has 3 projects - Server, Client, and common messages. The server and client are hosted via the nServiceBus generic host. Only a single bus is defined.

Both client and server are configured to use StructureMap builder and BinarySerialisation.

Server Endpoint:

public class EndPointConfig : AsA_Publisher, IConfigureThisEndpoint, IWantCustomInitialization
{
    public void Init()
    {
        NServiceBus.Configure.With()
            .StructureMapBuilder()
            .BinarySerializer();
    }
}

Server Code :

for (var nextId = 1; nextId <= 50; nextId++)
{
    Console.WriteLine("Sending {0}", nextId);

    IDataMsg msg = new DataMsg { Id = nextId, Body = string.Format("Batch Msg #{0}", nextId) };
    _bus.SendLocal(msg);
    Console.WriteLine("  ...sent {0}", nextId);

    if ((nextId % 5) == 0)
       Thread.Sleep(1000);
}

Client Endpoint:

public class EndPointConfig : AsA_Client, IConfigureThisEndpoint, IWantCustomInitialization
{
    public void Init()
    {
        NServiceBus.Configure.With()
            .StructureMapBuilder()
            .BinarySerializer();
    }
}

Client Clode:

public class DataMsgHandler : IMessageHandler<IDataMsg>
{
    public void Handle(IDataMsg msg)
    {
         Console.WriteLine("DataMsgHandler.Handle({0}, {1}) - ({2})", msg.Id, msg.Body, Thread.CurrentThread.ManagedThreadId);
     }
}

Client and Server App.Config:

<MsmqTransportConfig InputQueue="nsbt02a" ErrorQueue="error" NumberOfWorkerThreads="1" MaxRetries="5" />
<UnicastBusConfig DistributorControlAddress="" DistributorDataAddress="">
    <MessageEndpointMappings>
      <add Messages="Test02.Messages" Endpoint="nsbt02a" />
    </MessageEndpointMappings>
</UnicastBusConfig>

All run via VisualStudio 2008.

All 50 messages are sent - but after the 1st or 2nd batch. only 1 msg per batch is sent?

Any ideas? I'm assuming config or misuse but ....?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

初雪 2024-09-01 18:08:16

您的主要问题是您已将两个进程配置为使用相同的输入队列。给每个人一个自己的队列。

Your main problem is that you've configured both processes to use the same input queue. Give each one their own queue.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文