Skip to content

Commit

Permalink
Round-tripping topic name on envelopes. Closes GH-709
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremydmiller committed Jan 26, 2024
1 parent 8f2b4cc commit f7a440a
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ private Envelope incoming
}
}

[Fact]
public void topic_name_is_round_tripped()
{
outgoing.TopicName = Guid.NewGuid().ToString();
incoming.TopicName.ShouldBe(outgoing.TopicName);
}

[Fact]
public void accepted_content_types_positive()
Expand Down
19 changes: 19 additions & 0 deletions src/Transports/RabbitMQ/Wolverine.RabbitMQ.Tests/send_by_topics.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using JasperFx.Core;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Shouldly;
Expand Down Expand Up @@ -140,6 +141,17 @@ public async Task send_by_explicit_topic_2()
.OrderBy(x => x)
.ShouldHaveTheSameElementsAs("Second", "Third");
}

[Fact]
public async Task send_to_topic_with_delay()
{
var session = await theSender
.TrackActivity()
.IncludeExternalTransports()
.WaitForMessageToBeReceivedAt<FirstMessage>(theSecondReceiver)
.AlsoTrack(theFirstReceiver, theSecondReceiver, theThirdReceiver)
.InvokeMessageAndWaitAsync(new TriggerTopicMessage());
}
}

[Topic("color.purple")]
Expand All @@ -165,8 +177,15 @@ public class ThirdMessage : FirstMessage
{
}

public class TriggerTopicMessage{}

public class MessagesHandler
{
public object Handle(TriggerTopicMessage message)
{
return new FirstMessage().ToTopic("color.blue", new DeliveryOptions { ScheduleDelay = 3.Seconds() });
}

public void Handle(FirstMessage message)
{
}
Expand Down
1 change: 1 addition & 0 deletions src/Wolverine/EnvelopeConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ public static class EnvelopeConstants
public const string IsResponseKey = "is-response";
public const string TenantIdKey = "tenant-id";
public const string GroupIdKey = "group-id";
public const string TopicNameKey = "topic-name";
}
5 changes: 5 additions & 0 deletions src/Wolverine/Runtime/Serialization/EnvelopeSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ public static void ReadDataElement(Envelope env, string key, string value)
case EnvelopeConstants.TenantIdKey:
env.TenantId = value;
break;

case EnvelopeConstants.TopicNameKey:
env.TopicName = value;
break;

default:
env.Headers.Add(key, value);
Expand Down Expand Up @@ -220,6 +224,7 @@ private static int writeHeaders(BinaryWriter writer, Envelope env)
writer.WriteProp(ref count, EnvelopeConstants.SagaIdKey, env.SagaId);
writer.WriteProp(ref count, EnvelopeConstants.ParentIdKey, env.ParentId);
writer.WriteProp(ref count, EnvelopeConstants.TenantIdKey, env.TenantId);
writer.WriteProp(ref count, EnvelopeConstants.TopicNameKey, env.TopicName);

if (env.AcceptedContentTypes.Any())
{
Expand Down

0 comments on commit f7a440a

Please sign in to comment.