0

是否可以有一个端点通过 Msmq 传输处理消息,然后作为处理程序的一部分,然后使用 AzureStorageQueue 传输发送。

我的设置是一个本地端点,它通过 msmq 处理“通知”消息。我的处理程序从数据库中检索一些信息,然后我想将此数据发送到 AzureStorageQueue。

我的 EndpointConfig.cs 看起来像这样:

public class EndpointConfig : IConfigureThisEndpoint, AsA_Server, IWantCustomInitialization
{
    private IWindsorContainer container;

    public void Init()
    {
        this.InitialiseContainer();

        Configure.With()
                 .Log4Net()
                 .CastleWindsorBuilder(this.container)
                 .UseTransport<Msmq>()
                 .PurgeOnStartup(false)
                 .UnicastBus();
    }

    private void InitialiseContainer()
    {
        this.container = new WindsorContainer();
        this.container.Install(FromAssembly.Named("Notifications"));
        this.container.Register(Component.For<IWindsorContainer>()
                                         .Instance(this.container));
    }
}

我的处理程序如下所示:

public class NotificationHandler : IHandleMessages<NotificationV1>
{
    private readonly IWindsorContainer container;

    public NotificationHandler(IWindsorContainer container)
    {
        this.container = container;
    }

    public void Handle(NotificationV1 message)
    {
        if (message != null && message.CorrelationId != Guid.Empty)
        {
            var thingToPublish = new DataAccess.GetThingToPublish(message.Id);

            var publishMessage = new PublishV1
                {
                    CorrelationId = message.CorrelationId,
                    Timestamp = message.Timestamp,
                    Id = message.Id,
                    ThingToPublish = thingToPublish
                };

            // Here I intend to resolve the AzureStorageBus Queue and send the publishMessage to it
            var bus = this.container.Resolve<IBus>(); //Not I know this bit is wrong as it is sending it to the Msmq
            bus.Send("PublishQueue", publishMessage);
        }
    }
}

我的 app.config 中的一些片段如下

<configSections>
    <section name="AzureQueueConfig" type="NServiceBus.Config.AzureQueueConfig, NServiceBus.Azure.Transports.WindowsAzureStorageQueues" />
    <section name="MessageForwardingInCaseOfFaultConfig" type="NServiceBus.Config.MessageForwardingInCaseOfFaultConfig, NServiceBus.Core" />
    <section name="TransportConfig" type="NServiceBus.Config.TransportConfig, NServiceBus.Core" />
    <section name="UnicastBusConfig" type="NServiceBus.Config.UnicastBusConfig, NServiceBus.Core" />
    <section name="AuditConfig" type="NServiceBus.Config.AuditConfig, NServiceBus.Core" />
</configSections>

<UnicastBusConfig>
    <MessageEndpointMappings>
        <add Messages="Messages.NotificationV1, Messages" Endpoint="notification.endpoint" />
    </MessageEndpointMappings>
</UnicastBusConfig>

<AuditConfig QueueName="Notifications.Audit" />

<AzureQueueConfig QueueName="PublishQueue" ConnectionString="UseDevelopmentStorage=true" />

综上所述: 1. 是否可以处理来自 msmq 的消息,然后向 AzureStorageQueue 发送消息?2. 如果是,我该怎么做?

谢谢丹

4

2 回答 2

1

NServicebus 目前不支持多种传输,因此从 msmq 接收的端点也必须发送到 msmq。但是,如果您稍微尝试一下内部结构,则可以创建从一种传输类型到另一种传输类型的桥梁。不久前,我为带有 msmq 和 azure servicebus 的 poc 执行了此操作,您可以对 azure 存储执行相同操作。见https://github.com/yvesgoeleven/NServiceBus.MsmqAsbBridge

于 2014-06-11T12:49:58.570 回答
0

扩展并回答我是如何解决这个问题的:

  1. 使用 NServiceBus 的本地服务处理消息,
  2. 丰富了一些数据,然后需要将消息添加到 azure 中的队列中。
  3. 要将消息发送到 azure 托管队列,我创建了一个 API,然后将其托管在 azure
  4. 本地服务/消息处理程序将消息发布到 api。
  5. 然后,api 使用 NServiceBus 将消息添加到队列中。

这种使用网桥的方法是许多其他人为了解决这个问题而不得不做的事情。

于 2014-08-20T07:06:04.780 回答