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