public async Task <PersistenceStatus> CreateMessageAsync([FromBody] SaveSelectionRequestModel request) { DeliveryResult <Null, string> dr = null; using (IKafkaProducer <Null, string> p = this._kafkaProducerProvider.GetKafkaProducer <Null, string>("producer-1")) { try { dr = await p.ProduceAsync(new Message <Null, string> { Value = request.ToJSON() }); _logger.LogInformation($"Delivered '{dr.Value}' to '{dr.TopicPartitionOffset}'"); } catch (ProduceException <Null, string> e) { _logger.LogError($"Delivery failed: {e.Error.Reason}"); } } return(dr.Status); }
public PersistenceStatus CreateMessageSync([FromBody] SaveSelectionRequestModel request) { using (IKafkaProducer <Null, string> p = this._kafkaProducerProvider.GetKafkaProducer <Null, string>("producer-1")) { try { Action <DeliveryReport <Null, string> > handler = r => _logger.LogInformation(!r.Error.IsError ? $"Delivered message to {r.TopicPartitionOffset}" : $"Delivery Error: {r.Error.Reason}"); p.Produce(new Message <Null, string> { Value = request.ToJSON() }, handler); p.Flush(TimeSpan.FromMilliseconds(100)); } catch (ProduceException <Null, string> e) { _logger.LogError($"Delivery failed: {e.Error.Reason}"); } } return(PersistenceStatus.PossiblyPersisted); }