admin 管理员组文章数量: 1086019
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();
//}
本文标签: cHow to consume message with Xml type using MassTransitKafkaStack Overflow
版权声明:本文标题:c# - How to consume message with Xml type using MassTransit.Kafka? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/p/1744010984a2518148.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论