Exemple #1
0
        /// <summary>
        ///     Ctor
        /// </summary>
        /// <param name="layout">LAyout to create parameters from</param>
        internal KafkaLayoutParameters(KafkaLogstashLayout layout)
        {
            Application       = EnvironmentResolver.Resolve(layout.Application);
            CustomTags        = EnvironmentResolver.Resolve(layout.CustomTags);
            IncludeProperties = layout.IncludeProperties;
            MessageType       = Type.GetType(EnvironmentResolver.Resolve(layout.MessageType));
            SendNullValues    = layout.SendNullValues;

            if (MessageType == null)
            {
                throw new ArgumentException($"Cannot create any type from {layout.MessageType}");
            }
            if (!typeof(IKafkaMessage).IsAssignableFrom(MessageType))
            {
                throw new ArgumentException(
                          $"Type [{MessageType.FullName}] does not inherit from [{typeof(IKafkaMessage).FullName}]");
            }
        }
Exemple #2
0
        /// <summary>
        ///     Validates the input, resolves all string inputs through the <see cref="EnvironmentResolver" /> and fills the
        ///     <see cref="Params" /> and <see cref="ParsedBootStrapServers" /> collections.
        /// </summary>
        public void Validate()
        {
            if (BootstrapServers == null || !BootstrapServers.Any())
            {
                throw new LogException($"No {nameof(BootstrapServers)} configured");
            }

            foreach (string bootstrapServer in BootstrapServers.Select(EnvironmentResolver.Resolve))
            {
                if (string.IsNullOrEmpty(bootstrapServer) ||
                    !Uri.TryCreate(bootstrapServer, UriKind.Absolute, out Uri serverUri))
                {
                    throw new LogException($"Invalid {nameof(BootstrapServers)} element: \"{bootstrapServer}\"");
                }
                ParsedBootStrapServers.Add(serverUri);
            }

            if (string.IsNullOrEmpty(Topic))
            {
                Console.WriteLine(
                    $"[{nameof(KafkaAppenderSettings)}] Invalid topic [{Topic}] resetting to default topic [logstash]");
                Topic = "logstash";
            }

            Topic    = EnvironmentResolver.Resolve(Topic);
            ClientId = EnvironmentResolver.Resolve(ClientId);

            Params["bootstrap.servers"]      = string.Join(",", ParsedBootStrapServers.Select(x => x.ToString()));
            Params["retries"]                = Retries;
            Params["client.id"]              = string.Join(",", ParsedBootStrapServers.Select(x => x.ToString()));
            Params["socket.blocking.max.ms"] = MaxBlockingMs;
            Params["queue.buffering.max.ms"] = BufferingMaxMs;

            string preStartMsg =
                $"Starting {GetType().FullName} using config: {JsonConvert.SerializeObject(this)}";

            Console.WriteLine(preStartMsg);
            Trace.TraceInformation(preStartMsg);
        }