private static void PrintMessageValue <TValue>(int key, TValue val)
            where TValue : class, IMessage <TValue>, new()
        {
            var             msg = string.Empty;
            var             tmp = string.Empty;
            GoogleTimestamp ts  = null;

            if (val is Protos.v1.HelloReply val1)
            {
                msg = val1.Message;
            }
            if (val is Protos.v2.HelloReply val2)
            {
                msg = val2.Message;
                tmp = val2.TemperatureF != null ? $"at {val2.TemperatureF} degrees" : string.Empty;
            }
            if (val is Protos.v3.HelloReply val3)
            {
                msg = val3.Message;
                tmp = val3.TemperatureF != null ? $"at {val3.TemperatureF} degrees" : string.Empty;
                ts  = val3.DateTimeStamp;
            }
            if (val is Protos.v4.HelloReply val4)
            {
                msg = val4.Message;
                ts  = val4.DateTimeStamp;
            }
            if (val is Protos.v5.HelloReply val5)
            {
                msg = val5.Message;
                var dt = DateTime.SpecifyKind(DateTime.Parse(val5.DateTimeStamp), DateTimeKind.Utc);
                ts = GoogleTimestamp.FromDateTime(dt);
            }
            Console.WriteLine($"\nMessage value: {key} (key) {msg} {tmp} {ts}");
        }
Esempio n. 2
0
        private static TValue CreateMessageValue <TValue>(string msg)
            where TValue : class, IMessage <TValue>, new()
        {
            int?tmp = new Random().Next(-32, 100);
            var ts  = GoogleTimestamp.FromDateTime(DateTime.UtcNow);
            var val = new TValue();

            //if (val is IHelloReply val1)
            //{
            //    val1.Message = msg;
            //};
            //if (val is IHelloReply_2 val2)
            //{
            //    val2.TemperatureF = tmp;
            //};
            //if (val is IHelloReply_3 val3)
            //{
            //    val3.TemperatureF = tmp;
            //    val3.DateTimeStamp = ts;
            //};
            //if (val is IHelloReply_4 val4)
            //{
            //    val4.DateTimeStamp = ts;
            //};
            //if (val is IHelloReply_5 val5)
            //{
            //    val5.DateTimeStamp = DateTime.UtcNow.ToLongTimeString();
            //};
            return(val);
        }
        private static void PrintConsumeResult <TValue>(ConsumeResult <int, TValue> consumeResult)
            where TValue : class, IMessage <TValue>, new()
        {
            var             key = consumeResult.Message.Key;
            var             msg = string.Empty;
            var             tmp = string.Empty;
            GoogleTimestamp ts  = null;

            if (consumeResult.Message.Value is Protos.v1.HelloReply val1)
            {
                msg = val1.Message;
            }
            if (consumeResult.Message.Value is Protos.v2.HelloReply val2)
            {
                msg = val2.Message;
                tmp = val2.TemperatureF != null ? $"at {val2.TemperatureF} degrees" : string.Empty;
            }
            if (consumeResult.Message.Value is Protos.v3.HelloReply val3)
            {
                msg = val3.Message;
                tmp = val3.TemperatureF != null ? $"at {val3.TemperatureF} degrees" : string.Empty;
                ts  = val3.DateTimeStamp;
            }
            if (consumeResult.Message.Value is Protos.v4.HelloReply val4)
            {
                msg = val4.Message;
                ts  = val4.DateTimeStamp;
            }
            if (consumeResult.Message.Value is Protos.v5.HelloReply val5)
            {
                msg = val5.Message;
                var dt = DateTime.SpecifyKind(DateTime.Parse(val5.DateTimeStamp), DateTimeKind.Utc);
                ts = GoogleTimestamp.FromDateTime(dt);
            }
            Console.WriteLine($"Received message at {consumeResult.TopicPartitionOffset}: {key} (key) {msg} {tmp} {ts}");
        }