< Summary

Class:SeungYongShim.Akka.OpenTelemetry.Kafka.KafkaProducerActor
Assembly:SeungYongShim.Akka.OpenTelemetry.Kafka
File(s):/home/runner/work/SeungYongShim.Akka/SeungYongShim.Akka/src/SeungYongShim.Akka.OpenTelemetry.Kafka/KafkaProducerActor.cs
Covered lines:24
Uncovered lines:5
Coverable lines:29
Total lines:48
Line coverage:82.7% (24 of 29)
Covered branches:0
Total branches:0
Tag:81_945672945

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)0%110100%
.ctor()0%110100%
.ctor(...)0%2100%
.ctor(...)0%110100%
>c__DisplayClass3_0/<<-ctor()0%4.774063.64%
PostStop()0%110100%
PreRestart(...)0%2100%

File(s)

/home/runner/work/SeungYongShim.Akka/SeungYongShim.Akka/src/SeungYongShim.Akka.OpenTelemetry.Kafka/KafkaProducerActor.cs

#LineLine coverage
 1using System;
 2using Akka.Actor;
 3using Google.Protobuf;
 4using SeungYongShim.Kafka;
 5
 6namespace SeungYongShim.Akka.OpenTelemetry.Kafka
 7{
 8    public class KafkaProducerActor : ReceiveActor
 9    {
 410        public record Message(IMessage Body, string Topic, string Key = "1");
 111        public record Result();
 012        public record ResultException(Exception Exception) : Result;
 13
 114        public KafkaProducerActor(KafkaProducer kafkaProducer)
 115        {
 116            KafkaProducer = kafkaProducer;
 17
 118            ReceiveAsync<Message>(async msg =>
 219            {
 220                var sender = Sender;
 121
 122                try
 223                {
 224                    await kafkaProducer.SendAsync(msg.Body, msg.Topic, msg.Key);
 225                    sender.Tell(new Result());
 226                }
 127                catch (Exception ex)
 128                {
 129                    sender.Tell(new ResultException(ex));
 130                }
 231            });
 132        }
 33
 34        protected override void PostStop()
 135        {
 136            KafkaProducer.Dispose();
 137            base.PostStop();
 138        }
 39
 40        protected override void PreRestart(Exception reason, object message)
 041        {
 042            KafkaProducer.Dispose();
 043            base.PreRestart(reason, message);
 044        }
 45
 46        public KafkaProducer KafkaProducer { get; }
 47    }
 48}