Exemplo n.º 1
0
        /// <summary>
        /// Selects either a synchronous or an asynchronous producer, for
        /// the specified broker id and calls the send API on the selected
        /// producer to publish the data to the specified broker partition.
        /// </summary>
        /// <param name="poolData">The producer pool request object.</param>
        /// <remarks>
        /// Used for single-topic request
        /// </remarks>
        public void Send(ProducerPoolData <TData> poolData)
        {
            this.EnsuresNotDisposed();
            Guard.NotNull(poolData, "poolData");

            this.Send(new[] { poolData });
        }
Exemplo n.º 2
0
        /// <summary>
        /// Sends the data to a multiple topics, partitioned by key, using either the
        /// synchronous or the asynchronous producer.
        /// </summary>
        /// <param name="data">The producer data objects that encapsulate the topic, key and message data.</param>
        public void Send(IEnumerable <ProducerData <TKey, TData> > data)
        {
            Guard.NotNull(data, "data");
            Guard.Greater(data.Count(), 0, "data");

            this.EnsuresNotDisposed();
            var poolRequests = new List <ProducerPoolData <TData> >();

            foreach (var dataItem in data)
            {
                Partition partition   = this.GetPartition(dataItem);
                var       poolRequest = new ProducerPoolData <TData>(dataItem.Topic, partition, dataItem.Data);
                poolRequests.Add(poolRequest);
            }

            try
            {
                producerPool.Send(poolRequests);
            }
            catch (IllegalStateException e)
            {
                var exceptionData = e.Data;
                var brokerId      = 0;
                if (exceptionData.Contains("brokerId") &&
                    int.TryParse(exceptionData["brokerId"].ToString(), out brokerId))
                {
                    var broker = brokerPartitionInfo.GetBrokerInfo(brokerId);
                    if (null != broker)
                    {
                        producerPool.AddProducer(broker);
                        producerPool.Send(poolRequests);
                    }
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Sends the data to a multiple topics, partitioned by key, using either the
        /// synchronous or the asynchronous producer.
        /// </summary>
        /// <param name="data">The producer data objects that encapsulate the topic, key and message data.</param>
        public void Send(IEnumerable <ProducerData <TKey, TData> > data)
        {
            Guard.NotNull(data, "data");
            Guard.Greater(data.Count(), 0, "data");

            this.EnsuresNotDisposed();
            var poolRequests = new List <ProducerPoolData <TData> >();

            foreach (var dataItem in data)
            {
                Partition partition   = this.GetPartition(dataItem);
                var       poolRequest = new ProducerPoolData <TData>(dataItem.Topic, partition, dataItem.Data);
                poolRequests.Add(poolRequest);
            }

            this.producerPool.Send(poolRequests);
        }