If I have an existing producer, how can I make it not to create a new one but to use the existing producer?
public class FProducer<T> : ProducerBase2
{
private static readonly ObjectSerializer<T> serializer = new ObjectSerializer<T>();
public static IProducer<Null, T> producer = new ProducerBuilder<Null, T>(producerConfig).SetValueSerializer(serializer).Build();
public static async Task<DeliveryResult<Null, T>> Produce(string topic,List<T> data)
{
try
{
foreach (var item in data)
{
producer.Poll(TimeSpan.FromSeconds(5));
await producer.ProduceAsync(topic, new Message<Null, T> { Value = item });
}
}
catch (ProduceException<Null, string> ex)
{
LogManager.Logger.Fatal(ex, "Delivery failed: {reason}", ex.Error.Reason);
throw;
}
}
return null;
}
}
}
Since a new producer is created for each api request in the current structure, I cannot read the incoming messages sequentially.