Skip to content

Commit

Permalink
Modifying the routing to persist the topic name into the envelope so …
Browse files Browse the repository at this point in the history
…it will be part of the envelope persisted in the message store. Closes GH-1100
  • Loading branch information
jeremydmiller committed Oct 26, 2024
1 parent 2f6ca46 commit 8e5078b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/Transports/RabbitMQ/Wolverine.RabbitMQ.Tests/send_by_topics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Wolverine.ComplianceTests.Compliance;
using Wolverine.Attributes;
using Wolverine.Marten;
using Wolverine.Runtime.Routing;
using Wolverine.Tracking;
using Xunit;

Expand Down Expand Up @@ -70,6 +71,20 @@ public void Dispose()
theThirdReceiver?.Dispose();
}

[Fact]
public void topic_name_needs_to_be_set_on_envelope_as_part_of_routing()
{
// Really a global Wolverine behavior test, but using Rabbit MQ as the subject
// Caused by https://github.com/JasperFx/wolverine/issues/1100
var runtime = theSender.GetRuntime();

var router = runtime.RoutingFor(typeof(PurpleMessage));
var envelopes = router.RouteForPublish(new PurpleMessage(), null);

var envelope = envelopes.Single();
envelope.TopicName.ShouldBe(TopicRouting.DetermineTopicName(typeof(PurpleMessage)));
}

internal async Task send_by_topic_sample()
{
#region sample_send_to_topic
Expand Down
6 changes: 6 additions & 0 deletions src/Wolverine/Runtime/Routing/MessageRoute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ public Envelope CreateForSending(object message, DeliveryOptions? options, ISend
// Delivery options win
options?.Override(envelope);

// Will need the topic persisted, see https://github.com/JasperFx/wolverine/issues/1100
if (Sender.Endpoint.RoutingType == RoutingMode.ByTopic && envelope.TopicName.IsEmpty())
{
envelope.TopicName = TopicRouting.DetermineTopicName(envelope);
}

if (envelope.IsScheduledForLater(DateTimeOffset.UtcNow))
{
if (IsLocal)
Expand Down

0 comments on commit 8e5078b

Please sign in to comment.