public void GetRoutingKey_MultipleKeyAttributesWithSameKey_ExceptionIsThrown() { var message = new MultipleRoutingKeyAttributesMessage { Id = Guid.NewGuid(), One = "1", Two = "2", Three = "3" }; Action act = () => RoutingKeyHelper.GetRoutingKey(message); act.Should().Throw <InvalidOperationException>(); }
public void GetRoutingKey_SingleKeyMemberMessage_PropertyValueIsReturned() { var message = new RoutingKeyMessage { Id = Guid.NewGuid(), One = "1", Two = "2", Three = "3" }; var key = RoutingKeyHelper.GetRoutingKey(message); key.Should().Be("1"); }
public void GetRoutingKey_NoKeyAttribute_NullIsReturned() { var message = new NoRoutingKeyMessage { Id = Guid.NewGuid(), One = "1", Two = "2", Three = "3" }; var key = RoutingKeyHelper.GetRoutingKey(message); key.Should().BeNull(); }
/// <inheritdoc cref="IProducerBehavior.HandleAsync" /> public async Task HandleAsync(ProducerPipelineContext context, ProducerBehaviorHandler next) { Check.NotNull(context, nameof(context)); Check.NotNull(next, nameof(next)); if (context.Envelope.Message != null) { var key = RoutingKeyHelper.GetRoutingKey(context.Envelope.Message); if (key != null) { context.Envelope.Headers.AddOrReplace(RabbitMessageHeaders.RoutingKey, key); context.Envelope.AdditionalLogData["routingKey"] = key; } } await next(context).ConfigureAwait(false); }
/// <summary> /// Actual implementation of GetRoutingKey, called only when the type has not been cached yet. /// </summary> /// <param name="messageType"></param> protected virtual string BuildRoutingKey(Type messageType) { return(RoutingKeyHelper.Decorate(messageType, () => { // Split PascalCase into dot-separated parts. If the class name ends in "Message" leave that out. var words = SplitPascalCase(messageType.Name); if (words == null) { return ""; } if (words.Count > 1 && words.Last().Equals("Message", StringComparison.InvariantCultureIgnoreCase)) { words.RemoveAt(words.Count - 1); } return string.Join(".", words.Select(s => s.ToLower())); })); }
public static string GetRoutingGey(this ServerEventMessage message, string prefix) { return(RoutingKeyHelper.GetRoutingGey(prefix, message.ResourceType, message.ActionCode)); }