public void ReadStream(Stream stream, CancellationToken token)
 {
     while (!token.IsCancellationRequested)
     {
         var obj = Serializer.DeserializeWithLengthPrefix <BaseDto>(stream, PrefixStyle.Base128, fieldNumber: 1);
         ObjectDeserialized?.Invoke(obj);
     }
 }
Exemplo n.º 2
0
 public void ReadFromStream(Stream stream, CancellationToken token)
 {
     RuntimeTypeModel.Default.MetadataTimeoutMilliseconds = 300000;
     while (!token.IsCancellationRequested)
     {
         var obj = Serializer.DeserializeWithLengthPrefix <BaseDto>(stream, PrefixStyle.Base128, fieldNumber: 1);
         ObjectDeserialized?.Invoke(obj);
     }
 }
Exemplo n.º 3
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);
            }
        }