30 lines
883 B
C#
30 lines
883 B
C#
using Cloud.Services.Broker.Support;
|
|
|
|
namespace Cloud.Services.Broker.Implement.Kafka
|
|
{
|
|
public class KafkaService : IBrokerService
|
|
{
|
|
private readonly KafkaProducer _producer;
|
|
private readonly KafkaConsumer _consumer;
|
|
|
|
public KafkaService(IConfiguration configuration)
|
|
{
|
|
_producer = new KafkaProducer(configuration);
|
|
_consumer = new KafkaConsumer(configuration);
|
|
}
|
|
|
|
public IEnumerable<T>? WaitMessages<T>(string topic)
|
|
where T : IBrokerResponse
|
|
=> _consumer.WaitMessages<T>(topic);
|
|
|
|
|
|
public async Task ProduceAsync(string topic, Command command)
|
|
=> await _producer.ProduceAsync("commands", command);
|
|
|
|
public void ChangeBrokerIp(string ip)
|
|
{
|
|
_consumer.ChangeBrokerIp(ip);
|
|
_producer.ChangeBrokerIp(ip);
|
|
}
|
|
}
|
|
} |