AKA
AKA

Reputation: 1

Consume raw JSON with custom JsonConverter with MassTransit

I am looking for a way to consume raw JSON with custom JsonConverter in MassTransit. My messages has format like this:

{
  "data": {
    "Id": "e826891e-7da3-4915-b95a-3167a74c3101",
    "TransactionId": "79609d90-e67f-4f2a-af25-ba77373375ea"
  }
}

with its' C# representation, MyClass, containing only fields within data node of the message.

My current MassTransit setup looks like this:

                services.AddMassTransit(opt =>
                {
                    opt.AddConsumer(consumerType);

                    opt.UsingAzureServiceBus((context, cfg) =>
                    {
                        cfg.ClearSerialization();
                        cfg.UseRawJsonSerializer();
                        cfg.UseRawJsonDeserializer(isDefault: true);

                        cfg.ConfigureJsonSerializerOptions(options =>
                        {
                            options.Converters.Insert(0, new MyClassMessageConverter());
                            return options;
                        });

                        cfg.Host(config.GetConnectionString("ServiceBus"));

                        cfg.Message<MyClass>(x => x.SetEntityName(config["Messaging:MembershipEndpoint"]!));

                        cfg.SubscriptionEndpoint<MyClass>(config["Messaging:MembershipEndpoint"]!, e =>
                        {
                            e.ConfigureConsumer(context, consumerType);
                        });

                        cfg.ConfigureEndpoints(context);
                    });
                });

From I can tell MyClassMessageConverter is never called. How can I enforce it?

Upvotes: 0

Views: 24

Answers (0)

Related Questions