我正在与一个非常奇怪的问题作斗争......我已经在 WCF 服务之间实现了服务总线通信(通过 MassTransit + MSMQ),在 Windows 7 Ultimate 上使用 .NET 4.0。当服务启动时,一切正常并且它们互相接收消息,但是在给定的点上,它们不再接收它们,直到我手动删除计算机管理中的私有队列 -> 服务和应用程序 -> 消息队列 - > 私人队列。
对于每项服务,我都有一个引导程序,我在其中配置了 MassTransit:
// Bootstrapper configuration
public void Configure(IUnityContainer container)
{
// Service bus configuration
var config = ConfigurationDataAccess.GetSupervisionServiceConfig();
// Cleaning up the former Private Queues before to start the service
var privateQueues = MessageQueue.GetPrivateQueuesByMachine(System.Environment.MachineName);
foreach (var messageQueue in privateQueues)
{
try
{
if (messageQueue.QueueName.Contains("supervisionservice"))
{
MessageQueue.Delete(messageQueue.Path);
}
}
catch (MessageQueueException)
{
// An exception has occurred trying to remove a private message queue.
}
}
// Initializing MassTransit
var bus = ServiceBusFactory.New(sbc =>
{
sbc.UseMsmq();
sbc.VerifyMsmqConfiguration();
sbc.UseMulticastSubscriptionClient();
sbc.ReceiveFrom(config.ServiceBusReceiveFromAddress);
});
container.RegisterInstance(bus);
//Start the service...
}
}
然后服务主类扩展了 MassTransit,这里是一个例子:
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
public class DataService : Consumes<ServiceMessage>.Selected
{
public DataService()
{
// The service bus object takes the instance from the bootstrapper through the dependency
// injection of the Unity.
ServiceBus.SubscribeInstance(this);
}
public bool Accept(ServiceMessage message)
{
// For an easy explanation
return true;
}
public void Consume(ServiceMessage message)
{
// Treat the message
}
public void SendMessage(ServiceMessage message)
{
// Publish the message over the service bus
ServiceBus.Publish(message);
}
}
正如我所解释的,在给定的点上,不再调用 Accept 方法。唯一的方法是手动删除私有队列并重新启动服务。然后系统再次正常工作,直到下一个麻烦:-(。
任何建议将不胜感激。
非常感谢!亚历山德罗