最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - How to consume message with Xml type using MassTransit.Kafka? - Stack Overflow

programmeradmin1浏览0评论

I used the following configuration code for consuming raw message in MassTransit with MassTransit.Newtonsoft library. For XML, the root element will be the same but the children properties will vary. How to consume message with Xml type that having variable number of properties using MassTransit.Kafka (version 8.3.6)?

All register settings in Program

services.AddMassTransit(configurator =>
    {
        configurator.UsingInMemory((context, config) =>
        {
            config.ConfigureEndpoints(context);
        });
        configurator.AddRider(riderConfig =>
        {
            riderConfig.AddConsumer<EventConsumer>();
    
            riderConfig.UsingKafka((riderContext, kafkaConfig) =>
            {
                kafkaConfig.SecurityProtocol = consumerConfig.SecurityProtocol;
                kafkaConfig.Host(consumerConfig.BootstrapServers);

                kafkaConfig.TopicEndpoint<string>(topicName, consumerConfig.GroupId, topicConfig =>
                {
                    topicConfig.ClearMessageDeserializers();

                    //topicConfig.DefaultContentType = new ContentType("application/xml");
                    // topicConfig.SerializerContentType = new ContentType("application/xml");
                    topicConfig.UseRawXmlDeserializer();
                    topicConfig.UseRawXmlSerializer();
                    topicConfig.SetValueDeserializer(Deserializers.Utf8);
                    topicConfig.AutoOffsetReset = consumerConfig.AutoOffsetReset;
                    topicConfig.ConfigureConsumer<EventConsumer>(riderContext);
                    topicConfig.UseMessageRetry(r => r.Interval(MESSAGE_RETRY_COUNT, TimeSpan.FromSeconds(MESSAGE_RETRY_INTERVAL)));
                });
            });
        });
    });

And Consumer:

  public class EventConsumer : IConsumer<string>
    {
        public async Task Consume(ConsumeContext<string> context) 
        {
        }
    }

But no message comes to Consumer. What I doing wrong? Using "Offset Explorer 3.0" for send messages. Other message types with json settings work perfectly. As well as using Confluent.Kafka library for xml type:

  //using var consumer = new ConsumerBuilder<Null, string>(consumerConfig)
  //    .SetValueDeserializer(Deserializers.Utf8)
  //    .Build();

  //consumer.Subscribe(topicName);

  //while (true)
  //{
  //    var result = consumer.Consume();
  //}

发布评论

评论列表(0)

  1. 暂无评论