2

我有一个非常简单的请求响应体系结构,在该体系结构上出现“请求超时”异常。首先,我从 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

和订阅者日志文件:

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 管理控制台中收到一个错误。为什么我会收到此错误?

4

0 回答 0