2024-11-13 03:32:30 +04:00
|
|
|
using Cloud.Services.Broker.Support;
|
|
|
|
|
|
|
|
namespace Cloud.Services.Broker.Implement.Kafka
|
|
|
|
{
|
|
|
|
public class KafkaService : IBrokerService
|
|
|
|
{
|
2024-11-19 23:23:21 +04:00
|
|
|
private readonly KafkaProducer _producer;
|
|
|
|
private readonly KafkaConsumer _consumer;
|
2024-11-13 03:32:30 +04:00
|
|
|
|
2024-11-19 23:23:21 +04:00
|
|
|
public KafkaService(IConfiguration configuration)
|
2024-11-13 03:32:30 +04:00
|
|
|
{
|
2024-11-19 23:23:21 +04:00
|
|
|
_producer = new KafkaProducer(configuration);
|
|
|
|
_consumer = new KafkaConsumer(configuration);
|
2024-11-13 03:32:30 +04:00
|
|
|
}
|
2024-11-19 23:23:21 +04:00
|
|
|
|
|
|
|
public T? Consume<T>(string topic)
|
|
|
|
where T : IBrokerResponse => _consumer.WaitMessage<T>(topic);
|
|
|
|
|
|
|
|
public async Task Produce(Command command)
|
|
|
|
=> await _producer.ProduceAsync("commands", command);
|
2024-11-13 03:32:30 +04:00
|
|
|
}
|
|
|
|
}
|