-
How can I use transaction using this library?
|
Beta Was this translation helpful? Give feedback.
Answered by
Havret
Apr 5, 2021
Replies: 1 comment 11 replies
-
@jollyamit The simplest example may look as follows: using System;
using System.Threading.Tasks;
using ActiveMQ.Artemis.Client;
using ActiveMQ.Artemis.Client.Transactions;
namespace Example
{
class Program
{
static async Task Main()
{
var endpoint = Endpoint.Create("localhost", 5672, "guest", "guest");
var connectionFactory = new ConnectionFactory();
await using var connection = await connectionFactory.CreateAsync(endpoint);
await using var producer = await connection.CreateProducerAsync("my-address");
await using var transaction = new Transaction();
var message = new Message("my-payload");
await producer.SendAsync(message, transaction);
var result = DoSthThatMayFail();
if (result)
await transaction.CommitAsync();
else
await transaction.RollbackAsync();
}
private static bool DoSthThatMayFail()
{
var random = new Random();
return random.Next() % 2 == 0;
}
}
} You can find more examples in |
Beta Was this translation helpful? Give feedback.
11 replies
Answer selected by
Havret
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@jollyamit The simplest example may look as follows: