/// <summary> /// Create a producer. /// </summary> public IProducer CreateProducer(ProducerOptions options) { ThrowIfDisposed(); ICompressorFactory?compressorFactory = null; if (options.CompressionType != CompressionType.None) { var compressionType = (Internal.PulsarApi.CompressionType)options.CompressionType; compressorFactory = CompressionFactories.CompressorFactories().SingleOrDefault(f => f.CompressionType == compressionType); if (compressorFactory is null) { throw new CompressionException($"Support for {compressionType} compression was not found"); } } var correlationId = Guid.NewGuid(); var executor = new Executor(correlationId, _processManager, _exceptionHandler); var factory = new ProducerChannelFactory(correlationId, _processManager, _connectionPool, executor, options, compressorFactory); var stateManager = new StateManager <ProducerState>(ProducerState.Disconnected, ProducerState.Closed, ProducerState.Faulted); var producer = new Producer(correlationId, ServiceUrl, options.Topic, options.InitialSequenceId, _processManager, new NotReadyChannel(), executor, stateManager); if (options.StateChangedHandler is not null) { _ = StateMonitor.MonitorProducer(producer, options.StateChangedHandler); } var process = new ProducerProcess(correlationId, stateManager, factory, producer); _processManager.Add(process); process.Start(); return(producer); }
/// <summary> /// Create a producer. /// </summary> public IProducer CreateProducer(ProducerOptions options) { ThrowIfDisposed(); var correlationId = Guid.NewGuid(); var executor = new Executor(correlationId, _processManager, _exceptionHandler); var factory = new ProducerChannelFactory(correlationId, _processManager, _connectionPool, executor, options); var stateManager = new StateManager <ProducerState>(ProducerState.Disconnected, ProducerState.Closed, ProducerState.Faulted); var producer = new Producer(correlationId, options.Topic, options.InitialSequenceId, _processManager, new NotReadyChannel(), executor, stateManager); var process = new ProducerProcess(correlationId, stateManager, factory, producer); _processManager.Add(process); process.Start(); return(producer); }