Nservicebus msmq to azure queue using gateway

2019-08-19 16:49发布

问题:

I'm getting an error when using Bus.SendToQueues, detailed error at end of question.

I have an azure queue set up with a storage account and key and I'm trying to use Bus.SendToSites to have an on premise servicebus handler using msmq send a message to the azure site.

Trying to get a gateway going, as per: http://support.nservicebus.com/customer/portal/articles/859548-the-gateway-and-multi-site-distribution, and I'm using this configuration:

App.config: (Am I setting up the site correctly?)

<section name="GatewayConfig" type="NServiceBus.Config.GatewayConfig, NServiceBus.Core" />
<GatewayConfig>
  <Sites>
    <Site Key="Azure" Address="http://<!--STORAGE ACCOUNT NAME-->.queue.core.windows.net/<!--STORAGE ACCOUNT KEY-->" ChannelType="Http"/>
  </Sites>
</GatewayConfig>

Handler:

Bus.SendToSites(new[] { "Azure" }, message);

At runtime, I'm getting the following:

error: Failed to send message to address: The distributor's data address, used as the return address of messages sent by this endpoint..gateway@HFORTE

Inner Exception: {"Format name is invalid."}

Stacktrace: at System.Messaging.MessageQueue.MQCacheableInfo.get_WriteHandle() at System.Messaging.MessageQueue.StaleSafeSendMessage(MQPROPS properties, ITransaction transaction) at System.Messaging.MessageQueue.StaleSafeSendMessage(MQPROPS properties, IntPtr transaction) at System.Messaging.MessageQueue.SendInternal(Object obj, MessageQueueTransaction internalTransaction, MessageQueueTransactionType transactionType) at System.Messaging.MessageQueue.Send(Object obj, MessageQueueTransactionType transactionType) at NServiceBus.Transports.Msmq.MsmqMessageSender.Send(TransportMessage message, Address address) in :line 0

I see that the transport is MSMQ - is that the problem, that MSMQ and Azure are different transport protocols, and if so, how is this remedied?

回答1:

To use gateways you must have NSB hosted on both sides - sender and receiver. Gateways just open WCF service for NSB endpoint so you can send messages using HTTP protocol.

MSMQ and Azure queue transports cannot be combined in one solution because the IBus instance is a singleton per ce. We had to develop our own "bridge" service using RavenDb. We chose Raven since it has RX-driven event subscription mechanism that is also easy to use. We are also able to save messages (wrapped in some containers) as-is without much dance around since RavenDb is a document database.



回答2:

The address of your site should not be the address of your Azure queue. It should be the address of the NServiceBus receiving gateway channel.

In this case, it's just a coincidence that both Azure queues and the NSB gateway use HTTP.

Your sender (hosted on premise) will have this config

<GatewayConfig>
<Sites>
<Site Key="Azure" Address="https://some.address.com" ChannelType="Http"/>
</Sites>
</GatewayConfig>

Your NSB endpoint hosted on Azure will have this gateway config

<GatewayConfig>
<Channels>
<Channel ChannelType="Http" Address="https://some.address.com" Default="True"/>
</Channels>
</GatewayConfig>