2
我正在与一个非常奇怪的问题斗争......我已经在WCF服务之间实现了服务总线通信(通过MassTransit + MSMQ),在Windows 7旗舰版上使用.NET 4.0。当服务启动时,一切工作正常,他们彼此接收消息,但在给定时刻,他们不会再收到它们,直到我手动删除计算机管理 - >服务和应用程序中的专用队列 - >消息队列 - >私人队列。MassTransit实现:有时候没有收到消息
每每个服务我有一个引导程序,我配置了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方法不再被调用。唯一的方法是手动删除专用队列并重新启动服务。然后系统正常工作再次,直到下一个麻烦的:-(。
任何建议将非常感激。
非常感谢! 亚历山德罗
任何建议家伙? – Alessandro 2013-03-21 08:55:20