-
-
Save marcioduarte89/e058a3fb7ae0814fd49a3e280f1cdeec to your computer and use it in GitHub Desktop.
Transaction Service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TransactionService : ITransactionService | |
{ | |
private readonly IProducer<int, string> _producer; | |
private readonly IConfiguration _configuration; | |
public TransactionService(IProducer<int, string> producer, IConfiguration configuration) | |
{ | |
_producer = producer; | |
_configuration = configuration; | |
} | |
public async Task CreateTransaction(Transaction transaction, CancellationToken cancellationToken) | |
{ | |
var topicName = _configuration.GetValue<string>("TopicName"); | |
var message = new Message<int, string> | |
{ | |
Key = transaction.UserId, | |
Value = JsonSerializer.Serialize(transaction) | |
}; | |
var deliveryResult = await _producer.ProduceAsync(topicName, message, cancellationToken); | |
Console.WriteLine($"Message written to partition { deliveryResult.Partition.Value } with current offset {deliveryResult.Offset.Value}"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment