Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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<MqttTransport>().Topics["One"];

// This would have been done by creating a sender anyway
topic.Compile(runtime);
topic.DefaultSerializer.ShouldBeOfType<Serializer>();
}
}

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";
}
5 changes: 4 additions & 1 deletion src/Transports/MQTT/Wolverine.MQTT/MqttTopic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Wolverine.MQTT;

public class MqttTopic : Endpoint, ISender
public class MqttTopic : Endpoint, ISender, ITopicEndpoint
{
public const string WolverineTopicsName = "wolverine/topics";

Expand Down Expand Up @@ -44,6 +44,8 @@ public override bool AutoStartSendingAgent()

public override async ValueTask<IListener> BuildListenerAsync(IWolverineRuntime runtime, IReceiver receiver)
{
Compile(runtime);

_cancellation = runtime.Cancellation;

MessageTypeName = MessageType?.ToMessageTypeName();
Expand All @@ -60,6 +62,7 @@ public override async ValueTask<IListener> BuildListenerAsync(IWolverineRuntime

protected override ISender CreateSender(IWolverineRuntime runtime)
{
Compile(runtime);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using JasperFx.Core.Reflection;
using Wolverine.Configuration;
using Wolverine.MQTT.Internals;
using Wolverine.Runtime;

namespace Wolverine.MQTT;

Expand Down Expand Up @@ -59,7 +60,7 @@ public MqttTransportExpression ConfigureSenders(Action<MqttSubscriberConfigurati
return;
}

if (!e.Subscriptions.Any())
if (!e.Subscriptions.Any() && e is not ITopicEndpoint)
{
return;
}
Expand Down
10 changes: 10 additions & 0 deletions src/Wolverine/Runtime/ITopicEndpoint.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Wolverine.Runtime;

/// <summary>
/// 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
/// </summary>
public interface ITopicEndpoint;
Loading