Пример #1
0
        public override async Task <Message> HandleMessage(Message sourceMessage)
        {
            // Validate supported language
            // For simplicity, message key corresponds to selected language
            var validationPassed = false;
            var message          = (Message <int, string>)sourceMessage;

            if (languageStore.ContainsKey(message.Key))
            {
                validationPassed = true;
            }
            else
            {
                var errorMessage = $"No language corresponds to message key '{message.Key}'";
                validationErrorProducer.ProduceEvent(
                    new Confluent.Kafka.Message <int, string>
                {
                    Key   = message.Key,
                    Value = errorMessage
                });
                logger.LogInformation($"Validation handler: {errorMessage}");
                return(null);
            }

            // Call next handler
            var sinkMessage = new Message <int, string>(message.Key, message.Value);

            if (validationPassed)
            {
                logger.LogInformation($"Validation handler: Passed { sinkMessage.Key } { sinkMessage.Value }");
            }
            return(await base.HandleMessage(sinkMessage));
        }
Пример #2
0
        public override async Task <Message> HandleMessage(Message sourceMessage)
        {
            // Transform message
            var message = ((MockMessage <string>)sourceMessage).Value.ToLower();

            // Notify subscribers
            messageHandledProducer.ProduceEvent(message);

            // Call next handler
            var sinkMessage = new MockMessage <string>(message);

            return(await base.HandleMessage(sinkMessage));
        }
        public override async Task <Message> HandleMessage(Message sourceMessage)
        {
            // Get count
            var count = ((MockMessage <string>)sourceMessage).Value.Length;

            // Notify subscribers
            messageHandledProducer.ProduceEvent(count);

            // Call next handler
            var sinkMessage = new MockMessage <int>(count);

            return(await base.HandleMessage(sinkMessage));
        }
Пример #4
0
        public override async Task <Message> HandleMessage(Message sourceMessage)
        {
            // Transform message
            var message = (Message <int, string>)sourceMessage;
            var chars   = message.Value.ToCharArray();

            Array.Reverse(chars);
            message.Value = new string(chars);

            // Notify subscribers
            messageHandledProducer.ProduceEvent(message.Value);

            // Call next handler
            var sinkMessage = new Message <int, string>(message.Key, message.Value);

            return(await base.HandleMessage(sinkMessage));
        }