Skip to content

Commit

Permalink
asserting on mediator only mode. Closes GH-830
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremydmiller committed Apr 22, 2024
1 parent e7cc312 commit 50bef17
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Wolverine/Runtime/MessageBus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ public MessageBus(IWolverineRuntime runtime, string? correlationId)
Storage = runtime.Storage;
CorrelationId = correlationId;
}

private void assertNotMediatorOnly()
{
if (Runtime.Options.Durability.Mode == DurabilityMode.MediatorOnly)
{
throw new InvalidOperationException(
$"This operation is not allowed with Wolverine is bootstrapped in {nameof(DurabilityMode.MediatorOnly)} mode");
}
}

public string? CorrelationId { get; set; }

Expand Down Expand Up @@ -133,6 +142,7 @@ public ValueTask SendAsync<T>(T message, DeliveryOptions? options = null)
}

Runtime.AssertHasStarted();
assertNotMediatorOnly();

// Cannot trust the T here. Can be "object"
var outgoing = Runtime.RoutingFor(message.GetType()).RouteForSend(message, options);
Expand All @@ -149,6 +159,7 @@ public ValueTask PublishAsync<T>(T message, DeliveryOptions? options = null)
}

Runtime.AssertHasStarted();
assertNotMediatorOnly();

// You can't trust the T here.
var outgoing = Runtime.RoutingFor(message.GetType()).RouteForPublish(message, options);
Expand All @@ -172,6 +183,7 @@ public ValueTask BroadcastToTopicAsync(string topicName, object message, Deliver
}

Runtime.AssertHasStarted();
assertNotMediatorOnly();

var outgoing = Runtime.RoutingFor(message.GetType()).RouteToTopic(message, topicName, options);
return PersistOrSendAsync(outgoing);
Expand Down

0 comments on commit 50bef17

Please sign in to comment.