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
33 changes: 32 additions & 1 deletion src/Transports/RabbitMQ/Wolverine.RabbitMQ.Tests/end_to_end.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using JasperFx;
using JasperFx.CommandLine.Descriptions;
using JasperFx.Core;
using JasperFx.Core.Reflection;
using Marten;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
Expand Down Expand Up @@ -77,6 +78,31 @@ public async Task rabbitmq_transport_is_exposed_as_a_resource()
}
}

[Fact]
public async Task find_endpoints_through_conventions_as_part_of_find_resources()
{
using var host = Host.CreateDefaultBuilder()
.UseWolverine(opts =>
{
opts.ApplicationAssembly = GetType().Assembly;
opts.UseRabbitMq().UseConventionalRouting();
}).Build();

var sources = host.Services.GetServices<ISystemPart>().OfType<WolverineSystemPart>();
foreach (var source in sources)
{
var resources = await source.FindResources();
}

var transport = host.GetRuntime().Options.Transports.GetOrCreate<RabbitMqTransport>();
transport.Exchanges.Contains(typeof(OM1).FullNameInCode()).ShouldBeTrue();
transport.Exchanges.Contains(typeof(OM2).FullNameInCode()).ShouldBeTrue();
transport.Exchanges.Contains(typeof(OM3).FullNameInCode()).ShouldBeTrue();
transport.Exchanges.Contains(typeof(OM4).FullNameInCode()).ShouldBeTrue();
}



[Fact]
public async Task rabbitmq_transport_is_NOT_exposed_as_a_resource_if_external_transports_are_stubbed()
{
Expand Down Expand Up @@ -905,4 +931,9 @@ public static async Task HandleAsync(RequestColors message, IMessageBus bus)
response.Color.ShouldBe(message.Colors[i]);
}
}
}
}

public record OM1 : IMessage;
public record OM2 : IMessage;
public record OM3 : IMessage;
public record OM4 : IMessage;
3 changes: 2 additions & 1 deletion src/Wolverine/Transports/BrokerResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using JasperFx.Resources;
using Spectre.Console;
using Spectre.Console.Rendering;
using Wolverine.Configuration;
using Wolverine.Runtime;

namespace Wolverine.Transports;
Expand All @@ -28,7 +29,7 @@ public async Task Check(CancellationToken token)
var missing = new List<Uri>();
await _transport.ConnectAsync(_runtime);

foreach (var endpoint in _transport.Endpoints().OfType<IBrokerEndpoint>())
foreach (var endpoint in _transport.Endpoints().OfType<IBrokerEndpoint>().Where(x => x.Role == EndpointRole.Application))
{
try
{
Expand Down
6 changes: 6 additions & 0 deletions src/Wolverine/Transports/IBrokerEndpoint.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.Extensions.Logging;
using Wolverine.Configuration;

namespace Wolverine.Transports;

Expand All @@ -8,4 +9,9 @@ public interface IBrokerEndpoint
ValueTask<bool> CheckAsync();
ValueTask TeardownAsync(ILogger logger);
ValueTask SetupAsync(ILogger logger);

/// <summary>
/// Is the endpoint controlled and configured by the application or Wolverine itself?
/// </summary>
public EndpointRole Role { get; }
}
46 changes: 33 additions & 13 deletions src/Wolverine/WolverineSystemPart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,27 +190,47 @@ public void WriteErrorHandling()

public override async ValueTask<IReadOnlyList<IStatefulResource>> FindResources()
{
var list = new List<IStatefulResource>();

// These have to run first. Right now, the only options are for building multi-tenanted
// databases with EF Core
list.AddRange(_runtime.Services.GetServices<IResourceCreator>());
WithinDescription = true;

if (!_runtime.Options.ExternalTransportsAreStubbed)
try
{
foreach (var transport in _runtime.Options.Transports)
var list = new List<IStatefulResource>();

// These have to run first. Right now, the only options are for building multi-tenanted
// databases with EF Core
list.AddRange(_runtime.Services.GetServices<IResourceCreator>());

if (!_runtime.Options.ExternalTransportsAreStubbed)
{
if (transport.TryBuildStatefulResource(_runtime, out var resource))
foreach (var transport in _runtime.Options.Transports)
{
if (transport.TryBuildStatefulResource(_runtime, out var resource))
{
await transport.InitializeAsync(_runtime);
list.Add(resource!);
}
}

// Force Wolverine to find all message types...
var messageTypes = _runtime.Options.Discovery.FindAllMessages(_runtime.Options.HandlerGraph);

// ...and force Wolverine to *also* execute the routing, which
// may discover new endpoints
foreach (var messageType in messageTypes.Where(x => x.Assembly != GetType().Assembly))
{
list.Add(resource!);
_runtime.RoutingFor(messageType);
}
}
}

var stores = await _runtime.Stores.FindAllAsync();
var stores = await _runtime.Stores.FindAllAsync();

list.AddRange(stores.Select(store => new MessageStoreResource(_runtime.Options, store)));
list.AddRange(stores.Select(store => new MessageStoreResource(_runtime.Options, store)));

return list;
return list;
}
finally
{
WithinDescription = false;
}
}
}
Loading