Skip to content

Commit

Permalink
Ensuring that wolverine never tries to route agent or internal messag…
Browse files Browse the repository at this point in the history
…es through rabbit or any other external transport. Closes GH-710
  • Loading branch information
jeremydmiller committed Jan 26, 2024
1 parent ed0ce33 commit 8f2b4cc
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System.Diagnostics;
using System.Runtime.CompilerServices;
using IntegrationTests;
using Marten;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Shouldly;
using TestMessages;
using Wolverine.Marten;
using Wolverine.Runtime;
using Xunit;

namespace Wolverine.RabbitMQ.Tests.Bugs;

public class Bug_710_rabbit_exchange_errorneously_used_for_system_queues : RabbitMQContext
{
[Fact]
public async Task start_system_with_declared_exchange()
{
using var host = await Host.CreateDefaultBuilder()
.UseWolverine(opts =>
{
opts.UseRabbitMq()
.DeclareExchange("NotControlExchange", ex =>
{
ex.BindQueue("NotControlQueue");
})
.AutoProvision();

opts.PublishMessage<Message1>().ToRabbitExchange("NotControlExchange");

opts.Services.AddMarten(Servers.PostgresConnectionString)
.IntegrateWithWolverine();
}).StartAsync();

var options = host.Services.GetRequiredService<IWolverineRuntime>().Options;

options.Transports.NodeControlEndpoint.Uri.Scheme.ShouldBe("dbcontrol");
}
}
30 changes: 30 additions & 0 deletions src/Wolverine/Runtime/WolverineRuntime.Routing.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using JasperFx.Core;
using JasperFx.Core.Reflection;
using Wolverine.Configuration;
using Wolverine.Runtime.Agents;
using Wolverine.Runtime.Routing;
using Wolverine.Transports;
using Wolverine.Transports.Sending;

namespace Wolverine.Runtime;
Expand All @@ -12,6 +14,34 @@ public interface IMessageRouteSource
bool IsAdditive { get; }
}

internal class InternalMessages : IMessageRouteSource
{
public IEnumerable<IMessageRoute> FindRoutes(Type messageType, IWolverineRuntime runtime)
{
if (messageType.CanBeCastTo<IInternalMessage>())
{
var queue = runtime.Endpoints.AgentForLocalQueue(TransportConstants.System);
yield return new MessageRoute(messageType, queue.Endpoint, runtime.Replies);
}
}

public bool IsAdditive => false;
}

internal class AgentMessages : IMessageRouteSource
{
public IEnumerable<IMessageRoute> FindRoutes(Type messageType, IWolverineRuntime runtime)
{
if (messageType.CanBeCastTo<IAgentCommand>())
{
var queue = runtime.Endpoints.AgentForLocalQueue(TransportConstants.Agents);
yield return new MessageRoute(messageType, queue.Endpoint, runtime.Replies);
}
}

public bool IsAdditive => false;
}

internal class ExplicitRouting : IMessageRouteSource
{
public IEnumerable<IMessageRoute> FindRoutes(Type messageType, IWolverineRuntime runtime)
Expand Down
2 changes: 2 additions & 0 deletions src/Wolverine/WolverineOptions.MessageTransformations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public sealed partial class WolverineOptions
internal readonly List<IMessageRouteSource> InternalRouteSources = new()
{
new TransformedMessageRouteSource(),
new InternalMessages(),
new AgentMessages(),
new ExplicitRouting(),
new LocalRouting(),
new MessageRoutingConventions()
Expand Down

0 comments on commit 8f2b4cc

Please sign in to comment.