问题描述
我已经建立了一个简单的测试,该测试包括具有两个订阅者的发布者,所有订阅者均使用MSMQ和MassTransit(2.1.1)RuntimeServices在一台计算机上运行,后者使用本地Sql Server数据库.
I've set up a simple test comprising a publisher with two subscribers, all running on a single machine using MSMQ and MassTransit (2.1.1) RuntimeServices which is using a local Sql Server database.
我在下面包括了总线设置代码,因此您可以查看设置内容.我正在手动并独立地启动每个组件,以尝试锻炼如果订户没有运行时会发生什么.
I've included the Bus set up code below so you can see what's set up. I'm starting each component manually and independently to try to workout what happens if a subscriber ins't running.
我先运行了两个订阅者,因此队列和订阅都已设置,然后都退出了这两个订阅者,而不必取消订阅消息.然后,如果我自己运行发布者,它会尽可能快地在队列中转储400条消息,那么我将看到两个订阅者队列中等待消息的数量不同.
I ran the two subscribers first so the queues and subscriptions are all set up and then quit them both, without unsubscribing from the messages. If I then run the publisher on its own, which dumps 400 messages in the queues as fast as it can, I can see that the two subscriber queues have differing numbers of messages waiting.
我的假设是,我将在RuntimeServices能够自行设置两个目标队列之前进行发布.在总线设置和发布之间有5秒的延迟,我得到了两个订阅者队列中等待400条消息的消息,即某些消息没有同时发布到两个队列中.
My assumption is that I'm publishing before RuntimeServices has been able to set itself up both destination queues. With a 5 second delay between bus setup and publish, I get what I expect 400 messages waiting in both subscriber queues, i.e. some messages weren't published to both queues.
我的问题是这个;发布者启动时,是否有办法判断RuntimeServices是否已准备好其数据库中已存在订阅者?
My question is this; Is there a way to tell if RuntimeServices is ready with the subscribers already in its database when the publisher starts?
这是发布者代码
Bus.Initialize(sbc =>
{
sbc.SetCreateTransactionalQueues(true);
sbc.ReceiveFrom("msmq://localhost/andy_publisher");
sbc.UseSubscriptionService("msmq://localhost/mt_subscriptions");
sbc.UseMsmq();
sbc.VerifyMsmqConfiguration();
});
var bus = Bus.Instance;
Thread.Sleep(5000); // this makes it all work :)
int i = 0;
foreach (string filename in System.IO.Directory.EnumerateFiles(@"C:\Users\andy.baker\Pictures\", "*.*", SearchOption.AllDirectories))
{
Console.WriteLine(filename);
bus.Publish(new Messages.FileRegistered {FilePath = filename});
i++;
}
Console.WriteLine("Published {0} messages", i);
Console.ReadLine();
订阅者的配置如下;
Bus.Initialize(sbc => {
sbc.UseMsmq();
sbc.VerifyMsmqConfiguration();
sbc.ReceiveFrom("msmq://localhost/andy_subscriber1");
sbc.UseSubscriptionService("msmq://localhost/mt_subscriptions");
}
);
...和第二个订阅者...
...and the second subscriber...
Bus.Initialize(sbc =>
{
sbc.UseMsmq();
sbc.VerifyMsmqConfiguration();
sbc.ReceiveFrom("msmq://localhost/andy_subscriber2");
sbc.UseSubscriptionService("msmq://localhost/mt_subscriptions");
}
预先感谢您的任何建议.
Thanks in advance for any advice.
推荐答案
您如何订阅消费者?为了能够重新启动,它们应该是永久的. http://docs.masstransit-project.com/en/latest/configuration /sub_config_api.html
How are you subscribing your consumers?To survive restarts they should be permanent.http://docs.masstransit-project.com/en/latest/configuration/sub_config_api.html
s.Consumer<TConsumer>().Permanent();
这篇关于带有多订阅的MassTransit MSMQ Pub. RuntimeServices何时准备就绪?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!