Пример #1
0
        public void Process(ConsumeResult <byte[], byte[]> record)
        {
            bool throwException      = false;
            ObjectDeserialized key   = null;
            ObjectDeserialized value = null;

            if (KeySerDes != null)
            {
                key = DeserializeKey(record);
                if (key.MustBeSkipped)
                {
                    log.LogDebug(
                        "{LogPrefix} Message with record metadata [topic:{Topic}|partition:{Partition}|offset:{Offset}] was skipped !",
                        logPrefix, Context.RecordContext.Topic, Context.RecordContext.Partition,
                        Context.RecordContext.Offset);
                    droppedRecordsSensor.Record();
                    return;
                }
            }
            else
            {
                throwException = true;
            }

            if (ValueSerDes != null)
            {
                value = DeserializeValue(record);
                if (value.MustBeSkipped)
                {
                    log.LogDebug(
                        "{LogPrefix} Message with record metadata [topic:{Topic}|partition:{Partition}|offset:{Offset}] was skipped !",
                        logPrefix, Context.RecordContext.Topic, Context.RecordContext.Partition,
                        Context.RecordContext.Offset);
                    droppedRecordsSensor.Record();
                    return;
                }
            }
            else
            {
                throwException = true;
            }

            if (throwException)
            {
                var s = KeySerDes == null ? "key" : "value";
                log.LogError(
                    "{LogPrefix}Impossible to receive source data because keySerdes and/or valueSerdes is not setted ! KeySerdes : {KeySerdes} | ValueSerdes : {ValueSerdes}",
                    logPrefix, KeySerDes != null ? KeySerDes.GetType().Name : "NULL",
                    ValueSerDes != null ? ValueSerDes.GetType().Name : "NULL");
                throw new StreamsException($"{logPrefix}The {s} serdes is not compatible to the actual {s} for this processor. Change the default {s} serdes in StreamConfig or provide correct Serdes via method parameters(using the DSL)");
            }
            else
            {
                Process(key.Bean, value.Bean);
            }
        }
Пример #2
0
        private object DeserializeKey(object key)
        {
            if (key is byte[] keyBytes)
            {
                if (KeySerDes != null)
                {
                    key = Key.DeserializeObject(keyBytes, GetSerializationContext(true));
                }
                else
                {
                    log.Error($"{logPrefix}Impossible to receive source data because keySerdes and/or valueSerdes is not set ! KeySerdes : {(KeySerDes != null ? KeySerDes.GetType().Name : "NULL")} | ValueSerdes : {(ValueSerDes != null ? ValueSerDes.GetType().Name : "NULL")}.");
                    throw new StreamsException($"{logPrefix}The key serdes is not compatible to the actual key for this processor. Change the default key serdes in StreamConfig or provide correct Serdes via method parameters(using the DSL)");
                }
            }

            return(key);
        }
        public override void Process(K key, V value)
        {
            LogProcessingKeyValue(key, value);

            long timestamp = Context.Timestamp;

            if (timestamp < 0)
            {
                throw new StreamsException($"Invalid (negative) timestamp of {timestamp } for output record <{key}:{value}>.");
            }

            if (KeySerDes == null || ValueSerDes == null)
            {
                log.Error($"{logPrefix}Impossible to send sink data because keySerdes and/or valueSerdes is not setted ! KeySerdes : {(KeySerDes != null ? KeySerDes.GetType().Name : "NULL")} | ValueSerdes : {(ValueSerDes != null ? ValueSerDes.GetType().Name : "NULL")}.");
                var s = KeySerDes == null ? "key" : "value";
                throw new StreamsException($"{logPrefix}The {s} serdes is not compatible to the actual {s} for this processor. Change the default {s} serdes in StreamConfig or provide correct Serdes via method parameters(using the DSL)");
            }

            var topicName = topicNameExtractor.Extract(key, value, Context.RecordContext);

            Context.RecordCollector.Send(topicName, key, value, null, timestamp, KeySerDes, ValueSerDes);
        }
Пример #4
0
        public void Process(object key, object value)
        {
            bool throwException = false;

            if (key != null && key is byte[])
            {
                if (KeySerDes != null)
                {
                    key = Key.DeserializeObject(key as byte[]);
                }
                else
                {
                    throwException = true;
                }
            }

            if (value != null && value is byte[])
            {
                if (ValueSerDes != null)
                {
                    value = Value.DeserializeObject(value as byte[]);
                }
                else
                {
                    throwException = true;
                }
            }

            if (throwException)
            {
                var s = KeySerDes == null ? "key" : "value";
                log.Error($"{logPrefix}Impossible to receive source data because keySerdes and/or valueSerdes is not setted ! KeySerdes : {(KeySerDes != null ? KeySerDes.GetType().Name : "NULL")} | ValueSerdes : {(ValueSerDes != null ? ValueSerDes.GetType().Name : "NULL")}.");
                throw new StreamsException($"{logPrefix}The {s} serdes is not compatible to the actual {s} for this processor. Change the default {s} serdes in StreamConfig or provide correct Serdes via method parameters(using the DSL)");
            }
            else if ((key == null || key is K) && (value == null || value is V))
            {
                Process((K)key, (V)value);
            }
        }
        public override void Process(K key, V value)
        {
            LogProcessingKeyValue(key, value);

            long timestamp = Context.Timestamp;

            if (timestamp < 0)
            {
                throw new StreamsException($"Invalid (negative) timestamp of {timestamp } for output record <{key}:{value}>.");
            }

            if (KeySerDes == null || ValueSerDes == null)
            {
                log.Error($"{logPrefix}Impossible to send sink data because keySerdes and/or valueSerdes is not setted ! KeySerdes : {(KeySerDes != null ? KeySerDes.GetType().Name : "NULL")} | ValueSerdes : {(ValueSerDes != null ? ValueSerDes.GetType().Name : "NULL")}.");
                var s = KeySerDes == null ? "key" : "value";
                throw new StreamsException($"{logPrefix}Invalid {s} serdes for this processor. Default {s} serdes is not the same type. Please set a explicit {s} serdes.");
            }

            var topicName = this.topicNameExtractor.Extract(key, value, this.Context.RecordContext);

            this.Context.RecordCollector.Send(topicName, key, value, null, timestamp, KeySerDes, ValueSerDes);
        }