Inheritance: ConfigurationSection
        public static ProducerConfigurationSection FromXml(XElement xml)
        {
            var config = new ProducerConfigurationSection();

            config.DeserializeSection(xml.CreateReader());
            return(config);
        }
 public ProducerConfiguration(ProducerConfigurationSection config)
 {
     Guard.NotNull(config, "config");
     this.ProducerType          = config.ProducerType;
     this.BufferSize            = config.BufferSize;
     this.ConnectTimeout        = config.ConnectionTimeout;
     this.SocketTimeout         = config.SocketTimeout;
     this.MaxMessageSize        = config.MaxMessageSize;
     this.SerializerClass       = config.Serializer;
     this.ReconnectInterval     = config.ReconnectInterval;
     this.ReconnectTimeInterval = config.ReconnectTimeInterval;
     this.IdleTimeToKeepAlive   = config.IdleTimeToKeepAlive;
     this.KeepAliveInterval     = config.KeepAliveInterval;
     this.SocketPollingTimeout  = config.SocketPollingTimeout;
     this.SocketPollingLevel    = config.SocketPollingLevel;
     Validate(config);
     if (config.ZooKeeperServers.ElementInformation.IsPresent)
     {
         this.SetZooKeeperServers(config.ZooKeeperServers);
         this.PartitionerClass = config.Partitioner;
     }
     else
     {
         this.SetKafkaBrokers(config.Brokers);
     }
 }
Example #3
0
        private static void Validate(ProducerConfigurationSection config)
        {
            if (config.ZooKeeperServers.ElementInformation.IsPresent &&
                config.Brokers.ElementInformation.IsPresent)
            {
                throw new ConfigurationErrorsException("ZooKeeper configuration cannot be set when brokers configuration is used");
            }

            if (!config.ZooKeeperServers.ElementInformation.IsPresent &&
                !config.Brokers.ElementInformation.IsPresent)
            {
                throw new ConfigurationErrorsException("ZooKeeper server or Kafka broker configuration must be set");
            }

            if (config.ZooKeeperServers.ElementInformation.IsPresent &&
                config.ZooKeeperServers.Servers.Count == 0)
            {
                throw new ConfigurationErrorsException("At least one ZooKeeper server address is required");
            }

            if (config.Brokers.ElementInformation.IsPresent &&
                config.Brokers.Count == 0)
            {
                throw new ConfigurationErrorsException("Brokers list is empty");
            }

            if (config.Brokers.ElementInformation.IsPresent &&
                config.Partitioner != DefaultPartitioner)
            {
                throw new ConfigurationErrorsException("Partitioner cannot be used when broker list is set");
            }
        }
Example #4
0
 public ProducerConfiguration(XElement xml) : this(ProducerConfigurationSection.FromXml(xml))
 {
 }
 public static ProducerConfigurationSection FromXml(XElement xml)
 {
     var config = new ProducerConfigurationSection();
     config.DeserializeSection(xml.CreateReader());
     return config;
 }