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,75 @@
using IntegrationTests;
using Marten;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Shouldly;
using Wolverine.ComplianceTests;
using Wolverine.Configuration;
using Wolverine.Marten;
using Wolverine.Runtime;
using Wolverine.Runtime.Routing;
using Xunit;

namespace Wolverine.RabbitMQ.Tests.Bugs;

public class Bug_2304_conventional_routing_ignores_durable_outbox_policy : IDisposable
{
private readonly IHost _host;

public Bug_2304_conventional_routing_ignores_durable_outbox_policy()
{
_host = WolverineHost.For(opts =>
{
opts.Services.AddMarten(m =>
{
m.Connection(Servers.PostgresConnectionString);
m.DisableNpgsqlLogging = true;
})
.IntegrateWithWolverine();

opts.UseRabbitMq()
.UseConventionalRouting()
.AutoProvision()
.AutoPurgeOnStartup();

opts.Policies.UseDurableOutboxOnAllSendingEndpoints();

opts.DisableConventionalDiscovery();
});
}

[Fact]
public void conventionally_routed_endpoint_should_be_durable()
{
var runtime = _host.Services.GetRequiredService<IWolverineRuntime>();

var routes = runtime.RoutingFor(typeof(Bug2304Message))
.ShouldBeOfType<MessageRouter<Bug2304Message>>()
.Routes;

routes.Length.ShouldBeGreaterThan(0);

var route = routes.Single().ShouldBeOfType<MessageRoute>();
var endpoint = route.Sender.Endpoint;

// The endpoint should be Durable because of UseDurableOutboxOnAllSendingEndpoints()
endpoint.Mode.ShouldBe(EndpointMode.Durable);
}

public void Dispose()
{
_host?.Dispose();
}
}

public class Bug2304Message;

public class Bug2304Response;

public static class Bug2304Handler
{
public static void Handle(Bug2304Message message)
{
// no-op
}
}
8 changes: 8 additions & 0 deletions src/Wolverine/Transports/MessageRoutingConvention.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,14 @@ IEnumerable<Endpoint> IMessageRoutingConvention.DiscoverSenders(Type messageType
var (configuration, endpoint) = FindOrCreateSubscriber(corrected, transport);
endpoint.EndpointName = destinationName;

// Register the subscription so that endpoint policies like
// UseDurableOutboxOnAllSendingEndpoints() recognize this as a sender
// endpoint when Compile() applies policies. See GH-2304.
if (!endpoint.Subscriptions.Any(s => s.Matches(messageType)))
{
endpoint.Subscriptions.Add(Subscription.ForType(messageType));
}

_configureSending(configuration, new MessageRoutingContext(messageType, runtime));

configuration.As<IDelayedEndpointConfiguration>().Apply();
Expand Down
Loading