/// <summary> /// Initializes a new instance of the KafkaConnection class. /// </summary> /// <param name="server">The server to connect to.</param> /// <param name="port">The port to connect to.</param> /// <param name="bufferSize"></param> /// <param name="socketTimeout"></param> /// <param name="idleTimeToKeepAlive">idle time until keepalives (ms)</param> /// <param name="keepAliveInterval">interval between keepalives(ms)</param> /// <param name="socketPollingTimeout">socket polling timeout(usec)</param> /// <param name="keepAliveInterval">interval between keepalives(ms)</param> public KafkaConnection(string server, int port, int bufferSize, int socketTimeout, long idleTimeToKeepAlive, long keepAliveInterval, long socketPollingTimeout, SocketPollingLevel socketPollingLevel) { this.server = server; this.port = port; this.timeCreated = DateTime.Now; this.bufferSize = bufferSize; this.socketTimeout = socketTimeout; this.idleTimeToKeepAlive = (ulong)idleTimeToKeepAlive; this.keepAliveInterval = (ulong)keepAliveInterval; this.socketPollingTimeout = socketPollingTimeout; this.socketPollingLevel = socketPollingLevel; try { // connection opened this.client = new TcpClient(server, port) { ReceiveTimeout = socketTimeout, SendTimeout = socketTimeout, ReceiveBufferSize = bufferSize, SendBufferSize = bufferSize }; var stream = this.client.GetStream(); SetKeepAlive(); this.Reader = new KafkaBinaryReader(stream); } catch (Exception e) { Dispose(); throw new KafkaConnectionException(e); } }
public static void Init(int maxPoolSize, TimeSpan lifespan, int bufferSize, int socketTimeout, long idleTimeToKeepAlive, long keepAliveInterval, long socketPollingIntervalTimeout, SocketPollingLevel socketPollingLevel) { if (!isInitialized) { kafkaServerConnections = new ConcurrentDictionary <string, KafkaServerConnectionPool>(); _lifespan = lifespan; _maxPoolSize = maxPoolSize; _bufferSize = bufferSize; _socketTimeout = socketTimeout; _idleTimeToKeepAlive = idleTimeToKeepAlive; _keepAliveInterval = keepAliveInterval; _socketPollingIntervalTimeout = socketPollingIntervalTimeout; _socketPollingLevel = socketPollingLevel; isInitialized = true; } }
public KafkaServerConnectionPool(int maxConnections, TimeSpan connectionLifespan, string server, int port, int bufferSize, int socketTimeout, long idleTimeToKeepAlive, long keepAliveInterval, long socketPollingTimeout, SocketPollingLevel socketPollingLevel) { this.maxPoolSize = maxConnections; this.lifespan = connectionLifespan; this.host = server; this.port = port; this.bufferSize = bufferSize; this.socketTimeout = socketTimeout; this.idleTimeToKeepAlive = idleTimeToKeepAlive; this.keepAliveInterval = keepAliveInterval; this.socketPollingIntervalTimeout = socketPollingTimeout; this.socketPollingLevel = socketPollingLevel; this.availableConnections = new ConcurrentQueue <KafkaConnection>(); }