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();
//}