wolverine icon indicating copy to clipboard operation
wolverine copied to clipboard

Documentation suggests to use property, which is marked internal (Routings)

Open saithis opened this issue 10 months ago • 3 comments

On the documentation page about IMessageRoutingConvention, there is a code sample which shows how to set the routing key via convention.

Unfortunately this code sample doesn't work, because the Routings property which the sample uses is internal. This code line: var routing = exchange.Routings[routingKey];

Is there an alternative on how to set the routing key, or should the property be public?

saithis avatar Feb 21 '25 09:02 saithis

Oh and if I just set it via reflection anyway, it still doesn't work. I get this exception:

ArgumentOutOfRangeException: Endpoint rabbitmq://exchange/my-producer/routing/my-routing-key does not have an active sending agent. Message type: MyMessage (Parameter 'endpoint')
Wolverine.Runtime.Routing.MessageRoute..ctor(Type messageType, Endpoint endpoint, IReplyTracker replies) in MessageRoute.cs
Wolverine.Runtime.MessageRoutingConventions+<>c__DisplayClass0_0.<FindRoutes>b__1(Endpoint e) in WolverineRuntime.Routing.cs
System.Linq.Enumerable+IteratorSelectIterator<TSource, TResult>.MoveNext()
System.Collections.Generic.List<T>.AddRange(IEnumerable<T> collection)
Wolverine.Runtime.WolverineRuntime.findRoutes(Type messageType) in WolverineRuntime.Routing.cs
Wolverine.Runtime.WolverineRuntime.RoutingFor(Type messageType) in WolverineRuntime.Routing.cs
Wolverine.Runtime.MessageBus.PublishAsync<T>(T message, DeliveryOptions options) in MessageBus.cs
Program+<>c+<<<Main>$>b__0_2>d.MoveNext() in Program.cs
+
    await bus.PublishAsync(message);
Microsoft.AspNetCore.Http.RequestDelegateFactory.<ExecuteTaskOfT>g__ExecuteAwaited|132_0<T>(Task<T> task, HttpContext httpContext, JsonTypeInfo<T> jsonTypeInfo)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)

saithis avatar Feb 21 '25 09:02 saithis

I honestly don't have a real suggestion. What are you trying to do? The built in conventional routing for Rabbit MQ just cheats and makes the binding name the same as the exchange name.

jeremydmiller avatar Feb 28 '25 19:02 jeremydmiller

I tried to make an attribute for the message DTOs, where I can set the exchange and routing key to use. Exchange would be the same for most messages, but routing key would be different. It would probably equal the message type (Which is not equal to the .NET type, because we will communicate between at least 4 different programming languages).

saithis avatar Feb 28 '25 20:02 saithis

I've been trying to do the exact same thing; sending to a specific routing key (or topic) based on a property in the message. I am surprised this is not permitted or has even been considered in Wolverine.

My topic names are dynamic for this particular exchange and so I cannot simply create more types sub-types of the same message.

I've just hit up against this too, this documentation for IMessageRoutingConvention is both confusing and incorrect.

Robula avatar Sep 24 '25 13:09 Robula