我有一个非常简单的请求 - 响应架构,我得到了一个" Request timed out"例外。首先,我从Web API控制器向Windows服务发送消息,如下所示:
using (var messageBus = RabbitHutch.CreateBus("host=localhost;timeout=120"))
{
ReportData1 data = new ReportData1();
// Populate data
data.clientIds.Add(client.Id);
data.incidentIds.Add(incidentId);
data.clientNames.Add(client.Name);
data.clientNetworkPaths.Add(client.NetworkPath);
data.formatDescriptions.Add(EnumUtils.GetDescription(format));
data.reportFormats.Add(format.ToString());
messageBus.Publish(data);
}
ReportData1的位置:
public class ReportData1
{
public List<int> clientIds { get; set; }
public List<int> incidentIds { get; set; }
public List<string> clientNames { get; set; }
public List<string> clientNetworkPaths { get; set; }
public List<string> formatDescriptions { get; set; }
public List<string> reportFormats { get; set; }
public ReportData1()
{
this.clientIds = new List<int>();
this.incidentIds = new List<int>();
this.clientNames = new List<string>();
this.clientNetworkPaths = new List<string>();
this.formatDescriptions = new List<string>();
this.reportFormats = new List<string>();
}
}
然后在Windows服务应用程序中,我订阅ReportData1类型的消息,并向第二个Windows服务发送同步请求:
protected override void OnStart(string[] args)
{
Library.WriteErrorLog("Report Publish Service started", "PublisherLogFile");
this.bus = RabbitHutch.CreateBus("host=localhost;timeout=120");
this.bus.Subscribe<ReportData1>("reportHandling", this.Test);
}
private void Test(ReportData1 reportData1)
{
Library.WriteErrorLog(count + " report requests found.", "PublisherLogFile");
ReportData data1 = new ReportData();
data1.clientId = reportData1.clientIds[0];
data1.incidentId = reportData1.incidentIds[0];
data1.clientName = reportData1.clientNames[0];
data1.clientNetworkPath = reportData1.clientNetworkPaths[0];
data1.formatDescription = reportData1.formatDescriptions[0];
data1.reportFormat = reportData1.reportFormats[0];
Library.WriteErrorLog("Sending request for Client Id: " + data1.clientId + " and Incident Id: " + data1.incidentId, "PublisherLogFile");
var response = this.bus.Request<ReportData, TestResponse>(data1);
Library.WriteErrorLog("receiving request for " + response.Response, "PublisherLogFile");
}
我收到请求并发送回复的第二个Windows服务如下所示:
protected override void OnStart(string[] args)
{
Library.WriteErrorLog("Report Subscriber Service started", "SubscriberLogFile");
// Initialize the bus
this.bus = RabbitHutch.CreateBus("host=localhost;timeout=120");
this.bus.Respond<ReportData, TestResponse>(this.Response);
}
protected override void OnStop()
{
Library.WriteErrorLog("Exiting Report Subscribe Service", "SubscriberLogFile");
this.bus.Dispose();
}
private TestResponse Response(ReportData request)
{
int clientId = request.clientId;
int incidentId = request.incidentId;
string clientName = request.clientName;
string clientNetworkPath = request.clientNetworkPath;
string formatDescription = request.formatDescription;
string reportFormat = request.reportFormat;
Library.WriteErrorLog("Received report request for clientId: " + clientId + ", incident Id: " + incidentId + ", client: " + clientName + ", clientNetworkPath: " + clientNetworkPath + ", format description: " + formatDescription + ", and format: " + reportFormat, "SubscriberLogFile");
return new TestResponse { Response = " ***** Response to Request ***** " };
这就是全部。在我运行之后,我得到了这个例外:
System.AggregateException: One or more errors occurred. ---> System.TimeoutException: Request timed out. CorrelationId: 6efb3905-c2a2-4482-a758-a8ba42a5b4c4
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
at EasyNetQ.RabbitBus.Request[TRequest,TResponse](TRequest request)
at CMR.Messaging.PublisherService.CreateRequestService.Test(ReportData1 reportData1) in ..CreateRequestService.cs:line 63
at EasyNetQ.RabbitBus.<>c__DisplayClassc`1.<>c__DisplayClasse.<Subscribe>b__b()
at EasyNetQ.Internals.TaskHelpers.ExecuteSynchronously(Action action)
--- End of inner exception stack trace ---
第63行是:
var response = this.bus.Request<ReportData, TestResponse>(data1);
我的PublisherLogFile:
06/06/2016 13:49:57: Report Publish Service started
06/06/2016 13:50:14: 4 report requests found.
06/06/2016 13:50:14: Sending request for Client Id: 1 and Incident Id: 12345
SubscriberLogFile:
06/06/2016 13:49:55: Report Subscriber Service started
06/06/2016 13:50:14: Received report request for clientId: 1, incident Id: 12345, client: ABC, clientNetworkPath: \\Client Files\ABC\, format description: Image, and format: TIFF
所以看起来收到了请求并且发回了响应,但是没有任何反应。我刚刚在RabbitMQ管理控制台中收到错误。为什么我会收到此错误?