是否可以有一个端点通过 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. 如果是,我该怎么做?
谢谢丹