KafkaNet.Producer.Producer C# (CSharp) Méthode

Producer() public méthode

Construct a Producer class.
The maximumAsyncRequests parameter provides a mechanism for minimizing the amount of async requests in flight at any one time by blocking the caller requesting the async call. This affectively puts an upper limit on the amount of times a caller can call SendMessageAsync before the caller is blocked. The MaximumMessageBuffer parameter provides a way to limit the max amount of memory the driver uses should the send pipeline get overwhelmed and the buffer starts to fill up. This is an inaccurate limiting memory use as the amount of memory actually used is dependant on the general message size being buffered. A message will start its timeout countdown as soon as it is added to the producer async queue. If there are a large number of messages sitting in the async queue then a message may spend its entire timeout cycle waiting in this queue and never getting attempted to send to Kafka before a timeout exception is thrown.
public Producer ( IBrokerRouter brokerRouter, int maximumAsyncRequests = MaximumAsyncRequests, int maximumMessageBuffer = MaximumMessageBuffer ) : KafkaNet.Common
brokerRouter IBrokerRouter The router used to direct produced messages to the correct partition.
maximumAsyncRequests int The maximum async calls allowed before blocking new requests. -1 indicates unlimited.
maximumMessageBuffer int The maximum amount of messages to buffer if the async calls are blocking from sending.
Résultat KafkaNet.Common
        public Producer(IBrokerRouter brokerRouter, int maximumAsyncRequests = MaximumAsyncRequests, int maximumMessageBuffer = MaximumMessageBuffer)
        {
            BrokerRouter = brokerRouter;
            _protocolGateway = new ProtocolGateway(BrokerRouter);
            _maximumAsyncRequests = maximumAsyncRequests;
            _metadataQueries = new MetadataQueries(BrokerRouter);
            _asyncCollection = new AsyncCollection<TopicMessage>();
            _semaphoreMaximumAsync = new SemaphoreSlim(maximumAsyncRequests, maximumAsyncRequests);

            BatchSize = DefaultBatchSize;
            BatchDelayTime = TimeSpan.FromMilliseconds(DefaultBatchDelayMS);

            _postTask = Task.Run(() =>
            {
                BatchSendAsync();
                BrokerRouter.Log.InfoFormat("ending the sending thread");
            });
        }