-
-
Notifications
You must be signed in to change notification settings - Fork 258
Closed
Description
Describe the bug
When configuring an MQTT sender with a custom IMessageSerializer via ConfigureSenders(...).DefaultSerializer(...), the specified serializer is never invoked when publishing messages. Instead, Wolverine appears to bypass the sender configuration entirely.
To Reproduce
- Steps to reproduce the behavior:
- Create a new Wolverine project with MQTT support.
- Configure an MQTT sender with
.DefaultSerializer(new Serializer())inConfigureSenders. - Implement a simple
IMessageSerializerthat throws in Write so you can see if it’s called. - Publish any message through the bus.
- Observe that the serializer’s methods are never invoked.
- Change configuration to use
.PublishMessagesToMqttTopic(...).DefaultSerializer(new Serializer())and see that it works as expected.
Repro code:
using Wolverine;
using Wolverine.MQTT;
using Wolverine.Runtime.Serialization;
var builder = Host.CreateApplicationBuilder(args);
builder.Services.AddWolverine(cfg =>
{
// cfg.PublishMessagesToMqttTopic((Event e) => e.Id).DefaultSerializer(new Serializer());
cfg.PublishMessagesToMqttTopic((Event e) => e.Id);
cfg.UseMqttWithLocalBroker()
.ConfigureSenders(sub => sub.DefaultSerializer(new Serializer()));
});
builder.Services.AddHostedService<Worker>();
var host = builder.Build();
host.Run();
public record Event(string Id);
public class Worker(IServiceProvider services) : IHostedService
{
public async Task StartAsync(CancellationToken cancellationToken)
{
using var scope = services.CreateScope();
var bus = scope.ServiceProvider.GetRequiredService<IMessageBus>();
await bus.PublishAsync(new Event("123"));
}
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
}
public class Serializer : IMessageSerializer
{
public byte[] Write(Envelope envelope) => throw new NotImplementedException();
public object ReadFromData(Type messageType, Envelope envelope) => throw new NotImplementedException();
public object ReadFromData(byte[] data) => throw new NotImplementedException();
public byte[] WriteMessage(object message) => throw new NotImplementedException();
public string ContentType => "text/plain";
}Expected behavior
The custom serializer passed into .DefaultSerializer(...) should be invoked when publishing messages over MQTT.
Metadata
Metadata
Assignees
Labels
No labels