admin管理员组

文章数量:1278910

I'm trying to use MassaTransit on a single queue (Azure) and dispatch the message to the correct IService based on the type but I'm unable.

If I use a string property called Type and I switch over it, that's fine. Instead if I try to switch on the interface implementation it does not work.

Here's my snippet of code

public class KlaviyoMessageConsumer(IKlaviyoReviewSubmittedService klaviyoReviewSubmittedService)
     : IConsumer<IKlaviyoBaseMessage>
 {
     public async Task Consume(ConsumeContext<IKlaviyoBaseMessage> context)
     {
         var messageType = context.Headers.Get<string>("MessageType"); //Using this workss

         switch (context.Message)
         {
             case ReviewSubmittedRequestMessage reviewMessage:
                 await klaviyoReviewSubmittedService.SendReviewSubmittedEventAsync(
                     reviewMessage.ProductReviewGuid,context.CancellationToken);
                 break;
         }
     }
 }

In the other app, the item is sent correctly

  await endpoint.Send<ReviewSubmittedRequestMessage>( new
      ReviewSubmittedRequestMessage
      {
          ProductReviewGuid = Guid.NewGuid(),
      });

If I look at the type while running it's {MassTransit.DynamicInternal.omiss.Packages.Contracts.MassTransit.Klaviyo.IKlaviyoBaseMessage}

Any suggestion? Thanks

本文标签: Using Interface in a MassTransit consume messageStack Overflow