我是个有点麻烦搞清楚如何做到与经销商正确以下内容:NServiceBus经销商只需2个步骤?有
- 创建它发送的命令,被工人分布服务(分销商)。如果我使用IWantToRunAtStartup实现启动分销商,则可以实现此行为。见下文。
- 创建一个处理这些命令的服务(worker)。然后,这个工作人员将启动X个扩展实例。
- 到目前为止,这些都在同一台机器上。
包含在NSB中的样本有点难以理解,或者只是我:)。
例子,我有一个经销商和工人:
经销商:
class MessageCreator: IWantToRunAtStartup
{
public IBus Bus { get; set; }
public void Run()
{
Thread.Sleep(5000); //Allow workers to checkin
for (int i = 0; i < 1000; i++)
{
Bus.Send(new DoWorkForCustomerCommand { CustomerID = i });
}
}
public void Stop() { }
}
...
public class EndpointConfig : IConfigureThisEndpoint, AsA_Server
{
public void Init()
{
Configure.Instance.RunDistributor();
}
}
的app.config
<configSections>
<section name="Logging" type="NServiceBus.Config.Logging, NServiceBus.Core" />
<section name="UnicastBusConfig" type="NServiceBus.Config.UnicastBusConfig, NServiceBus.Core" />
<section name="MessageForwardingInCaseOfFaultConfig" type="NServiceBus.Config.MessageForwardingInCaseOfFaultConfig, NServiceBus.Core" />
</configSections>
<MessageForwardingInCaseOfFaultConfig ErrorQueue="error"/>
<Logging Threshold="INFO" />
<UnicastBusConfig>
<MessageEndpointMappings>
<add Messages="Messages" Endpoint="Worker" />
</MessageEndpointMappings>
</UnicastBusConfig>
工人:
public class MessageHandler: IHandleMessages<DoWorkForCustomerCommand >
{
public void Handle(DoWorkForCustomerCommand message)
{
Console.WriteLine("Handled customer with Id: " + message.CustomerID);
}
}
...
public class EndpointConfig : IConfigureThisEndpoint, AsA_Publisher
{
public void Init()
{
Configure.Instance.EnlistWithDistributor();
// For some reason this: Configure.Instance.RunDistributor(); achieves the same thing.
}
}
的app.config
<configSections>
<section name="MessageForwardingInCaseOfFaultConfig" type="NServiceBus.Config.MessageForwardingInCaseOfFaultConfig, NServiceBus.Core" />
</configSections>
<MessageForwardingInCaseOfFaultConfig ErrorQueue="error" />
此工程在我的机器上,并很好地分配到任意数量的工人,我开始,但我我不想错过某些东西,ScaleOut示例似乎更复杂?
为什么我可以启动员工作为分销商,然后看到工人的行为,就好像它是一个工人时,实际上是作为分销商开始的?
如果我只是在worker app.config中添加一个队列名称/端点,这是否会在机器上运行?
谢谢你的答案。我实际上已经意识到,自从我发布了一个问题,我必须在自己的进程中托管NSB,所以已经改变了很多领域。防爆。我不能再使用IWantToRunAtStartup,但必须使用完全不同的解决方案,请参阅我的其他帖子http://stackoverflow.com/questions/15255880/nservicebus-distributor-how-to-split-application。我仍然发现ScaleOut示例非常错误,因为有更多的方式来实现分销商。我认为他们可以更多地展示分销商如何实施:)。 – 2013-03-08 21:42:50