public Task Invoke(IIncomingLogicalMessageContext context, Func <IIncomingLogicalMessageContext, Task> next)
    {
        var intent = GetMessageIntent(context);
        var isSubscriptionMessage = intent == MessageIntentEnum.Subscribe || intent == MessageIntentEnum.Unsubscribe;
        var isReply = intent == MessageIntentEnum.Reply;

        if (isSubscriptionMessage || isReply)
        {
            return(next(context));
        }

        // If the header is set we assume it's validity was checked by DistributeMessagesBasedOnHeader
        if (context.MessageHeaders.ContainsKey(PartitionHeaders.PartitionKey))
        {
            return(next(context));
        }

        var messagePartitionKey = mapper(context.Message.Instance);

        if (string.IsNullOrWhiteSpace(messagePartitionKey))
        {
            throw new PartitionMappingFailedException($"Could not map a partition key for message of type {context.Headers[Headers.EnclosedMessageTypes]}");
        }

        var message = $"##### Received message: {context.Headers[Headers.EnclosedMessageTypes]} with Mapped PartitionKey={messagePartitionKey} on partition {localPartitionKey}";

        if (messagePartitionKey == localPartitionKey)
        {
            return(next(context));
        }

        context.Headers[PartitionHeaders.PartitionKey] = messagePartitionKey;

        return(forwarder.Forward(context, messagePartitionKey));
    }
Esempio n. 2
0
    public Task Invoke(IIncomingPhysicalMessageContext context, Func <IIncomingPhysicalMessageContext, Task> next)
    {
        var intent = context.Message.GetMessageIntent();
        var isSubscriptionMessage = intent == MessageIntentEnum.Subscribe || intent == MessageIntentEnum.Unsubscribe;
        var isReply = intent == MessageIntentEnum.Reply;

        if (isSubscriptionMessage || isReply)
        {
            return(next(context));
        }

        var hasPartitionKeyHeader = context.MessageHeaders.TryGetValue(PartitionHeaders.PartitionKey, out var messagePartitionKey);

        // 1. The header value isn't present (logical behavior will check message contents)
        // 2. The header value matches local partition key
        if (!hasPartitionKeyHeader || messagePartitionKey == localPartitionKey)
        {
            return(next(context));
        }

        var message = $"##### Received message: {context.Message.Headers[Headers.EnclosedMessageTypes]} with Mapped PartitionKey={messagePartitionKey} on partition {localPartitionKey}";

        Logger.Log(message);

        return(forwarder.Forward(context, messagePartitionKey));
    }
Esempio n. 3
0
 public void Bar(string x)
 {
     m_barChannel.Forward(new BarArgs {
         x = x
     });
 }
Esempio n. 4
0
 public void Baz(ReadOnlyMemory <byte> x)
 {
     m_bazChannel.Forward(new BazArgs {
         x = x.ToArray()
     });
 }
Esempio n. 5
0
 public void Foo(int x, double y)
 {
     m_fooChannel.Forward(new FooArgs {
         x = x, y = y
     });
 }