从 MT 2.9.5 迁移到 4.0.1 并获得 "The routingSlip must contain at least one activity log"

Migrating from MT 2.9.5 to 4.0.1 and getting "The routingSlip must contain at least one activity log"

我们已经开始从 MassTransit 2.9.5(使用 Courier 插件)迁移到 MassTransit 4.0.1 的旅程。事情进展缓慢,但还好,我对(对我们来说)新功能感到兴奋...但我在使用 Courier 时遇到了瓶颈。

这是一个既有执行又有补偿行为的脑残简单 Activity:

public class AdditionActivity : Activity<AdditionActivity.Args, AdditionActivity.CompLog>
{
    private readonly ILogger _logger;

    public AdditionActivity(ILogger logger)
    {
        _logger = logger;
    }

    public class Args : CorrelatedBy<Guid>
    {
        public Guid CorrelationId { get; set; }
        public int First { get; set; }
        public int Second { get; set; }
    }

    public class CompLog : CorrelatedBy<Guid>
    {
        public Guid CorrelationId { get; set; }
        public int Result { get; set; }
    }

    public async Task<ExecutionResult> Execute(ExecuteContext<Args> context)
    {
        var compLog = new CompLog
        {
            CorrelationId = context.Arguments.CorrelationId,
            Result = context.Arguments.First + context.Arguments.Second
        };

        _logger.Info($"{nameof(AdditionActivity)}[{context.Arguments.CorrelationId} - Adding [{context.Arguments.First}] and [{context.Arguments.Second}] = [{compLog.Result}]");
        await Task.CompletedTask;
        return context.Completed(compLog);
    }

    public async Task<CompensationResult> Compensate(CompensateContext<CompLog> context)
    {
        _logger.Warn($"{nameof(AdditionActivity)}[{context.Log.CorrelationId}] - Ruh roh...  must compensate for add that resulted in [{context.Log.Result}]");
        await Task.CompletedTask;
        return context.Compensated();
    }
}

当我执行包含此 activity 的路由清单时,它会执行(我看到了日志,并且可以单步执行代码)。但是在 return context.Completed(compLog) 之后,我们在控制台(此处的错误队列消息中也已捕获):

Exchange    Procedure.Service.Activities.AdditionActivity.Execute_error
Routing Key 
Redelivered ●
Properties  
message_id: 4ded0000-47b0-38d5-3ae8-08d5701751d5
correlation_id: 924899da-7a61-4b80-819f-f66f166c72e4
delivery_mode:  2
headers:    
Content-Type:   application/vnd.masstransit+json
publishId:  1
MT-Reason:  fault
MT-Fault-ExceptionType: System.ArgumentException
MT-Fault-Message:   The routingSlip must contain at least one activity log
MT-Fault-Timestamp: 2018-02-09T23:46:20.3953028Z
MT-Fault-StackTrace:    at MassTransit.Courier.Hosts.HostCompensateContext`1..ctor(HostInfo host, ConsumeContext`1 context) 
at MassTransit.Courier.Hosts.CompensateActivityHost`2.<Send>d__4.MoveNext() 
at MassTransit.Courier.Hosts.CompensateActivityHost`2.<Send>d__4.MoveNext() 
at GreenPipes.Filters.TeeFilter`1.<Send>d__5.MoveNext() 
at GreenPipes.Filters.OutputPipeFilter`2.<GreenPipes-IFilter<TInput>-Send>d__6.MoveNext() 
at GreenPipes.Filters.OutputPipeFilter`2.<GreenPipes-IFilter<TInput>-Send>d__6.MoveNext() 
at MassTransit.Pipeline.Filters.DeserializeFilter.<Send>d__4.MoveNext() 
at GreenPipes.Filters.RescueFilter`2.<GreenPipes-IFilter<TContext>-Send>d__5.MoveNext()
MT-Host-MachineName:    TYLER-XPS13
MT-Host-ProcessName:    Procedure.Service.vshost
MT-Host-ProcessId:  13040
MT-Host-Assembly:   Procedure.Service
MT-Host-AssemblyVersion:    1.0.0.0
MT-Host-MassTransitVersion: 4.0.1.1390
MT-Host-FrameworkVersion:   4.0.30319.42000
MT-Host-OperatingSystemVersion: Microsoft Windows NT 6.2.9200.0
content_type:   application/vnd.masstransit+json
Payload
1844 bytes
Encoding: string
{

  "messageId": "4ded0000-47b0-38d5-3ae8-08d5701751d5",

  "correlationId": "924899da-7a61-4b80-819f-f66f166c72e4",

  "conversationId": "4ded0000-47b0-38d5-a350-08d570175173",

  "initiatorId": "924899da-7a61-4b80-819f-f66f166c72e4",

  "sourceAddress": "rabbitmq://localhost/Procedure.Service",

  "destinationAddress": "rabbitmq://localhost/Procedure.Service.Activities.AdditionActivity.Execute",

  "messageType": [

    "urn:message:MassTransit.Courier.Contracts:RoutingSlip"

  ],

  "message": {

    "trackingNumber": "924899da-7a61-4b80-819f-f66f166c72e4",

    "createTimestamp": "2018-02-09T23:46:20.1847429Z",

    "itinerary": [

      {

        "name": "AdditionActivity",

        "address": "rabbitmq://localhost/Procedure.Service.Activities.AdditionActivity.Execute",

        "arguments": {

          "correlationId": "00000000-0000-0000-0000-000000000000",

          "first": 3,

          "second": 5

        }

      },

      {

        "name": "LogActivity",

        "address": "rabbitmq://localhost/Procedure.Service.Activities.LogActivity.Execute",

        "arguments": {

          "theLogMessage": "NewStyleConsumer - Consumed SomeFunMessage[924899da-7a61-4b80-819f-f66f166c72e4] - Procedure [924899da-7a61-4b80-819f-f66f166c72e4 has begun... - gonna trigger a routing slip!"

        }

      }

    ],

    "activityLogs": [],

    "compensateLogs": [],

    "variables": {},

    "activityExceptions": [],

    "subscriptions": []

  },

  "headers": {},

  "host": {

    "machineName": "TYLER-XPS13",

    "processName": "Procedure.Service.vshost",

    "processId": 13040,

    "assembly": "Procedure.Service",

    "assemblyVersion": "1.0.0.0",

    "frameworkVersion": "4.0.30319.42000",

    "massTransitVersion": "4.0.1.1390",

    "operatingSystemVersion": "Microsoft Windows NT 6.2.9200.0"

  }

}

我已经通读了此处的文档 (http://masstransit-project.com/MassTransit/advanced/courier/),但我没有发现任何错误(除了文档代码示例和当前 MT 4.0 之间在命名方面存在一些差异之外) .1).

在 MT 4.0.1 中 activity 完成后存储补偿日志条目的正确方法是什么? and/or 即使我提供了补偿日志值,是否还有其他我可能做错的事情显示为此异常?

谢谢,

泰勒

您似乎将 CompensateHost 注册在与执行 activity 主机相同的端点上,这导致在收到路由清单时两个主机都被执行。

ExecuteActivityHost 和 CompensateActivityHost 必须在不同的端点上(我猜您已经知道,但在移植到 4.0.1 后不知何故错误地连接了它们)。