private async ValueTask <Producer <T> > CreateProducer <T>(string topic, ProducerConfigurationData conf, ISchema <T> schema, ProducerInterceptors <T> interceptors) { var metadata = await GetPartitionedTopicMetadata(topic).ConfigureAwait(false); if (_actorSystem.Log.IsDebugEnabled) { _actorSystem.Log.Debug($"[{topic}] Received topic metadata. partitions: {metadata.Partitions}"); } if (metadata.Partitions > 0) { var partitionActor = _actorSystem.ActorOf(Props.Create(() => new PartitionedProducer <T>(_client, _lookup, _cnxPool, _generator, topic, conf, metadata.Partitions, schema, interceptors, _clientConfigurationData))); var co = await partitionActor.Ask <AskResponse>(Connect.Instance, _clientConfigurationData.OperationTimeout); if (co.Failed) { await partitionActor.GracefulStop(TimeSpan.FromSeconds(5)); throw co.Exception; } _client.Tell(new AddProducer(partitionActor)); return(new Producer <T>(partitionActor, schema, conf, _clientConfigurationData.OperationTimeout)); } else { var producerId = await _generator.Ask <long>(NewProducerId.Instance).ConfigureAwait(false); var producer = _actorSystem.ActorOf(Props.Create(() => new ProducerActor <T>(producerId, _client, _lookup, _cnxPool, _generator, topic, conf, -1, schema, interceptors, _clientConfigurationData))); var co = await producer.Ask <AskResponse>(Connect.Instance, _clientConfigurationData.OperationTimeout); if (co.Failed) { await producer.GracefulStop(TimeSpan.FromSeconds(5)); throw co.Exception; } _client.Tell(new AddProducer(producer)); return(new Producer <T>(producer, schema, conf, _clientConfigurationData.OperationTimeout)); } }
private async ValueTask <Producer <T> > CreateProducer <T>(ProducerConfigurationData conf, ISchema <T> schema, ProducerInterceptors <T> interceptors) { if (conf == null) { throw new PulsarClientException.InvalidConfigurationException("Producer configuration undefined"); } if (schema is AutoConsumeSchema) { throw new PulsarClientException.InvalidConfigurationException("AutoConsumeSchema is only used by consumers to detect schemas automatically"); } var state = await _client.Ask <int>(GetClientState.Instance).ConfigureAwait(false); if (state != 0) { throw new PulsarClientException.AlreadyClosedException($"Client already closed : state = {state}"); } var topic = conf.TopicName; if (!TopicName.IsValid(topic)) { throw new PulsarClientException.InvalidTopicNameException("Invalid topic name: '" + topic + "'"); } if (schema is AutoProduceBytesSchema <T> autoProduceBytesSchema) { if (autoProduceBytesSchema.SchemaInitialized()) { return(await CreateProducer(topic, conf, schema, interceptors).ConfigureAwait(false)); } else { var schem = await _lookup.Ask <AskResponse>(new GetSchema(TopicName.Get(conf.TopicName))).ConfigureAwait(false); if (schem.Failed) { throw schem.Exception; } var sc = schem.ConvertTo <GetSchemaInfoResponse>(); if (sc.SchemaInfo != null) { autoProduceBytesSchema.Schema = (ISchema <T>) ISchema <T> .GetSchema(sc.SchemaInfo); } else { autoProduceBytesSchema.Schema = (ISchema <T>)ISchema <T> .Bytes; } return(await CreateProducer(topic, conf, schema, interceptors).ConfigureAwait(false)); } } return(await CreateProducer(topic, conf, schema, interceptors).ConfigureAwait(false)); }