在基于 nServiceBus pub/sub 示例的测试项目中,我已将服务器中的 bus.publish 替换为 bus.send。服务器发送 50 条消息,每 5 条消息等待 1 秒(即 5 条消息的 10 次突发)。客户端没有收到所有消息。
该解决方案有 3 个项目 - 服务器、客户端和公共消息。服务器和客户端通过 nServiceBus 通用主机托管。只定义了一个总线。
客户端和服务器都配置为使用 StructureMap 构建器和 BinarySerialisation。
服务器端点:
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();
}
}
客户代码:
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 个味精?
有任何想法吗?我假设配置或误用但是.....?