Search code examples
.net-coremasstransitconsumerrouting-slipmasstransit-courier

'RoutingSlipCompleted' does not contain a definition for 'GetVariable'


after using massTransit (8.0.8) I got following error :

'RoutingSlipCompleted' does not contain a definition for 'GetVariable' and the best extension method overload 'RoutingSlipEventExtensions.GetVariable(ConsumeContext, string, Guid)' requires a receiver of type 'ConsumeContext' here is my code:

using MassTransit;
using MassTransit.Courier.Contracts;
using MassTransit.Courier;

public class CheckInventoriesConsumer: IConsumer<ICheckInventoryRequest>
        , IConsumer<RoutingSlipCompleted>
        , IConsumer<RoutingSlipFaulted>
    {
        private readonly IEndpointNameFormatter _formatter;
        public CheckInventoriesConsumer(IEndpointNameFormatter formatter)
        {
            _formatter = formatter;
        }
        public async Task Consume(ConsumeContext<ICheckInventoryRequest> context)
        {
            var routingSlip =  CreateRoutingSlip(context);
             await context.Execute(routingSlip);
        }
        private RoutingSlip CreateRoutingSlip(ConsumeContext<ICheckInventoryRequest> context)
        { // lot of code here
         }
        public async Task Consume(ConsumeContext<RoutingSlipCompleted> context)
        {
           // error is here
            context.Message.GetVariable<Guid>(nameof(ConsumeContext.RequestId));

            throw new NotImplementedException();
         }
    }

It is not going to find GetVariable method from MassTransit.Courier and I encounter with this error.


Solution

  • As you've already found based upon your comments:

    context.GetVariable<Guid>(nameof(ConsumeContext.RequestId));
    

    Is the right solution.

    MassTransit Version 8 has more extensive serialization support, and the SerializationContext (from ConsumeContext) is needed to properly deserialize the variable from the routing slip event.