diff --git a/src/Transports/MQTT/Wolverine.MQTT.Tests/Bugs/Bug_1634_not_using_default_serializer_correctly.cs b/src/Transports/MQTT/Wolverine.MQTT.Tests/Bugs/Bug_1634_not_using_default_serializer_correctly.cs new file mode 100644 index 000000000..5d41401f1 --- /dev/null +++ b/src/Transports/MQTT/Wolverine.MQTT.Tests/Bugs/Bug_1634_not_using_default_serializer_correctly.cs @@ -0,0 +1,47 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Shouldly; +using Wolverine.MQTT.Internals; +using Wolverine.Runtime.Serialization; +using Wolverine.Tracking; + +namespace Wolverine.MQTT.Tests.Bugs; + +public class Bug_1634_not_using_default_serializer_correctly +{ + [Fact] + public async Task try_it_out() + { + using var host = await Host.CreateDefaultBuilder() + .UseWolverine(opts => + { + // cfg.PublishMessagesToMqttTopic((Event e) => e.Id).DefaultSerializer(new Serializer()); + opts.PublishMessagesToMqttTopic((Event e) => e.Id); + + opts.UseMqttWithLocalBroker() + .ConfigureSenders(sub => sub.DefaultSerializer(new Serializer())); + }).StartAsync(); + + var runtime = host.GetRuntime(); + var topic = runtime.Options.Transports.GetOrCreate().Topics["One"]; + + // This would have been done by creating a sender anyway + topic.Compile(runtime); + topic.DefaultSerializer.ShouldBeOfType(); + } +} + +public record Event(string Id); + +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"; +} \ No newline at end of file diff --git a/src/Transports/MQTT/Wolverine.MQTT/MqttTopic.cs b/src/Transports/MQTT/Wolverine.MQTT/MqttTopic.cs index 862cd60d6..68192fb3a 100644 --- a/src/Transports/MQTT/Wolverine.MQTT/MqttTopic.cs +++ b/src/Transports/MQTT/Wolverine.MQTT/MqttTopic.cs @@ -11,7 +11,7 @@ namespace Wolverine.MQTT; -public class MqttTopic : Endpoint, ISender +public class MqttTopic : Endpoint, ISender, ITopicEndpoint { public const string WolverineTopicsName = "wolverine/topics"; @@ -44,6 +44,8 @@ public override bool AutoStartSendingAgent() public override async ValueTask BuildListenerAsync(IWolverineRuntime runtime, IReceiver receiver) { + Compile(runtime); + _cancellation = runtime.Cancellation; MessageTypeName = MessageType?.ToMessageTypeName(); @@ -60,6 +62,7 @@ public override async ValueTask BuildListenerAsync(IWolverineRuntime protected override ISender CreateSender(IWolverineRuntime runtime) { + Compile(runtime); return this; } diff --git a/src/Transports/MQTT/Wolverine.MQTT/MqttTransportExpression.cs b/src/Transports/MQTT/Wolverine.MQTT/MqttTransportExpression.cs index 32ef4d5a6..b8b559870 100644 --- a/src/Transports/MQTT/Wolverine.MQTT/MqttTransportExpression.cs +++ b/src/Transports/MQTT/Wolverine.MQTT/MqttTransportExpression.cs @@ -1,6 +1,7 @@ using JasperFx.Core.Reflection; using Wolverine.Configuration; using Wolverine.MQTT.Internals; +using Wolverine.Runtime; namespace Wolverine.MQTT; @@ -59,7 +60,7 @@ public MqttTransportExpression ConfigureSenders(Action +/// Marker interface that just tells Wolverine this endpoint +/// is a topic for brokers that support topic-based routing. +/// +/// Tells Wolverine that this endpoint *might* have subscriptions +/// later +/// +public interface ITopicEndpoint; \ No newline at end of file