Skip to content

Commit

Permalink
Update example application
Browse files Browse the repository at this point in the history
  • Loading branch information
brianpursley committed Jul 1, 2024
1 parent 4e9f34f commit 607d971
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion Npgmq.Example/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,20 @@
await connection.OpenAsync();
var npgmq = new NpgmqClient(connection);

await using (var tx = connection.BeginTransaction())
await using (var tx = await connection.BeginTransactionAsync())
{
var msgId = await npgmq.SendAsync("example_queue", new MyMessageType
{
Foo = "Connection object test",
Bar = 2
});
Console.WriteLine($"Sent message with id {msgId}");
msgId = await npgmq.SendAsync("example_queue", new MyMessageType
{
Foo = "Connection object test",
Bar = 3
});
Console.WriteLine($"Sent message with id {msgId}");

await tx.CommitAsync();
}
Expand All @@ -56,6 +62,12 @@
Console.WriteLine($"Read message with id {msg.MsgId}: Foo = {msg.Message?.Foo}, Bar = {msg.Message?.Bar}");
await npgmq.ArchiveAsync("example_queue", msg.MsgId);
}
msg = await npgmq.ReadAsync<MyMessageType>("example_queue");
if (msg != null)
{
Console.WriteLine($"Read message with id {msg.MsgId}: Foo = {msg.Message?.Foo}, Bar = {msg.Message?.Bar}");
await npgmq.ArchiveAsync("example_queue", msg.MsgId);
}
}

internal class MyMessageType
Expand Down

0 comments on commit 607d971

Please sign in to comment.