Skip to content

Commit

Permalink
Making it more robust to "thaw" out topic routed messages from Outbox
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremydmiller committed Nov 7, 2024
1 parent 0e2613b commit 6023948
Showing 1 changed file with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using JasperFx.Core;
using Microsoft.Extensions.Logging;
using RabbitMQ.Client;
using Wolverine.Configuration;
Expand Down Expand Up @@ -27,7 +28,22 @@ public RabbitMqSender(RabbitMqEndpoint endpoint, RabbitMqTransport transport,
_exchangeName = new CachedString(endpoint.ExchangeName);
_key = endpoint.RoutingKey();

_toRoutingKey = routingType == RoutingMode.Static ? _ => new CachedString(_key) : x => new CachedString(TopicRouting.DetermineTopicName(x));
_toRoutingKey = routingType == RoutingMode.Static ? _ => new CachedString(_key) : x =>
{
if (x.TopicName.IsEmpty() && x.Message == null)
{
try
{
runtime.Pipeline.TryDeserializeEnvelope(x, out var _);
}
catch (Exception e)
{
Logger.LogError(e, "Error trying to deserialize an envelope in order to determine the topic name");
}
}

return new CachedString(TopicRouting.DetermineTopicName(x));
};

_mapper = endpoint.BuildMapper(runtime);
_endpoint = endpoint;
Expand Down

0 comments on commit 6023948

Please sign in to comment.