我可以通过下面的代码使用nservicebus将消息添加到本地MSMQ
var endpointConfiguration = new EndpointConfiguration("Samples.Msmq.Simple");
var transport = endpointConfiguration.UseTransport<MsmqTransport>();
endpointConfiguration.SendFailedMessagesTo("error");
endpointConfiguration.EnableInstallers();
endpointConfiguration.UsePersistence<InMemoryPersistence>();
var endpointInstance = await Endpoint.Start(endpointConfiguration)
.ConfigureAwait(false);
var myMessage = new MyMessage();
await endpointInstance.SendLocal(myMessage)
.ConfigureAwait(false);
但我在某些地方读到我可以向远程MSMQ发送消息,请参阅下面的代码
FormatName:Direct=TCP:100.100.100.12\\private$\\remoteTxn
但我无法想象如何使用Nservicebus发送到远程MSMQ。谁能在这里投球?
你不需要使用SendLocal
,你需要在命令的情况下使用Send
,或者在事件的情况下使用Publish
。
使用Send
意味着您需要具有消息路由,因为它确定了消息的目的地。路由可以定义为using code,或者像external files这样的其他方法,这使得dev / ops在将来更容易在运行时更改路由。
Send
方法的重载也接受目标端点,但建议不要混淆问题并保持路由代码分离(因此不使用目标的重载)。更多信息here。