From 25bd64aef589018c4aa1e9c349caba0f47dbd07c Mon Sep 17 00:00:00 2001 From: Brian Pursley Date: Tue, 21 May 2024 19:16:24 -0400 Subject: [PATCH 1/6] Upgrade Npgsql dependency to 7.0.7 --- Npgmq/Npgmq.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Npgmq/Npgmq.csproj b/Npgmq/Npgmq.csproj index ad5b4ff..32af162 100644 --- a/Npgmq/Npgmq.csproj +++ b/Npgmq/Npgmq.csproj @@ -18,7 +18,7 @@ - + From 38153640f0257548d2111a619765c4dd0c6d9d02 Mon Sep 17 00:00:00 2001 From: Brian Pursley Date: Wed, 22 May 2024 09:41:05 -0400 Subject: [PATCH 2/6] Add sleep to start-db.sh, to avoid occasional flake due to docker startup time. --- Npgmq.Test/scripts/start-db.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/Npgmq.Test/scripts/start-db.sh b/Npgmq.Test/scripts/start-db.sh index 7e80215..508f356 100755 --- a/Npgmq.Test/scripts/start-db.sh +++ b/Npgmq.Test/scripts/start-db.sh @@ -4,6 +4,7 @@ set -e PGMQ_VERSION=$1 docker run -d --name npgmq_test_db -p 5432:5432 --rm quay.io/tembo/tembo-local +sleep 4 docker exec npgmq_test_db /bin/sh -c "psql -c \"CREATE DATABASE npgmq_test;\"" From 8c6102603458f18dd3e24aa09715eff0289a3f17 Mon Sep 17 00:00:00 2001 From: Brian Pursley Date: Wed, 22 May 2024 09:41:18 -0400 Subject: [PATCH 3/6] Add readme comment --- Npgmq.Test/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Npgmq.Test/README.md b/Npgmq.Test/README.md index a360a56..e069af4 100644 --- a/Npgmq.Test/README.md +++ b/Npgmq.Test/README.md @@ -21,6 +21,7 @@ scripts/run-tests.sh 1.1.1 ``` ### Start Database Only +This can be helpful if you want to manually run tests, without having to start the database each time. ```bash scripts/start-db.sh From b275d6bc68af8b68d01e36924378f30fdb75894e Mon Sep 17 00:00:00 2001 From: Brian Pursley Date: Wed, 22 May 2024 09:41:44 -0400 Subject: [PATCH 4/6] Update build.yml to test pgmq 1.1.1. --- .github/workflows/build.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index bd171e7..648880b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -42,9 +42,12 @@ jobs: - name: Build run: dotnet build --no-restore --configuration Release /p:Version=${{ env.VERSION }} /p:CopyrightYear=$(date +%Y) - - name: Test + - name: Test (latest pgmq version) run: Npgmq.Test/scripts/run-tests.sh + - name: Test (pgmq 1.1.1) + run: Npgmq.Test/scripts/run-tests.sh 1.1.1 + - name: Test (pgmq 1.0.0) run: Npgmq.Test/scripts/run-tests.sh 1.0.0 From 0a3ab2b9d6d454435bcfb79cc233d288e9a3325b Mon Sep 17 00:00:00 2001 From: Brian Pursley Date: Wed, 22 May 2024 09:48:42 -0400 Subject: [PATCH 5/6] Update Npgsql dependency to 8.0.3 --- Npgmq/Npgmq.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Npgmq/Npgmq.csproj b/Npgmq/Npgmq.csproj index 32af162..08ec567 100644 --- a/Npgmq/Npgmq.csproj +++ b/Npgmq/Npgmq.csproj @@ -18,7 +18,7 @@ - + From 5aeabe9637236e9b10e4433acf62a0f5c225e15e Mon Sep 17 00:00:00 2001 From: Brian Pursley Date: Wed, 22 May 2024 10:32:04 -0400 Subject: [PATCH 6/6] Add Npgmq.Example project. --- Npgmq.Example/Npgmq.Example.csproj | 20 ++++++++++++++++++ Npgmq.Example/Program.cs | 33 ++++++++++++++++++++++++++++++ Npgmq.Example/README.md | 3 +++ Npgmq.sln | 6 ++++++ README.md | 6 ++++-- 5 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 Npgmq.Example/Npgmq.Example.csproj create mode 100644 Npgmq.Example/Program.cs create mode 100644 Npgmq.Example/README.md diff --git a/Npgmq.Example/Npgmq.Example.csproj b/Npgmq.Example/Npgmq.Example.csproj new file mode 100644 index 0000000..e9e7233 --- /dev/null +++ b/Npgmq.Example/Npgmq.Example.csproj @@ -0,0 +1,20 @@ + + + + Exe + net8.0 + enable + enable + ffbcfb1f-57f6-4fca-96ae-4a0e2b43c970 + + + + + + + + + + + + diff --git a/Npgmq.Example/Program.cs b/Npgmq.Example/Program.cs new file mode 100644 index 0000000..72ce1dc --- /dev/null +++ b/Npgmq.Example/Program.cs @@ -0,0 +1,33 @@ +using System.Reflection; +using Microsoft.Extensions.Configuration; +using Npgmq; + +var configuration = new ConfigurationBuilder() + .AddEnvironmentVariables() + .AddUserSecrets(Assembly.GetExecutingAssembly()) + .Build(); + +var npgmq = new NpgmqClient(configuration.GetConnectionString("ExampleDB")!); + +await npgmq.InitAsync(); +await npgmq.CreateQueueAsync("example_queue"); + +var msgId = await npgmq.SendAsync("example_queue", new MyMessageType +{ + Foo = "Test", + Bar = 123 +}); +Console.WriteLine($"Sent message with id {msgId}"); + +var msg = await npgmq.ReadAsync("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 +{ + public string Foo { get; set; } = null!; + public int Bar { get; set; } +} \ No newline at end of file diff --git a/Npgmq.Example/README.md b/Npgmq.Example/README.md new file mode 100644 index 0000000..faade7a --- /dev/null +++ b/Npgmq.Example/README.md @@ -0,0 +1,3 @@ +# Npgmq.Example + +Example project for Npgmq. diff --git a/Npgmq.sln b/Npgmq.sln index e1461d6..21e8272 100644 --- a/Npgmq.sln +++ b/Npgmq.sln @@ -15,6 +15,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{ .github\workflows\build.yml = .github\workflows\build.yml EndProjectSection EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Npgmq.Example", "Npgmq.Example\Npgmq.Example.csproj", "{60A266EF-6EFA-42B0-B592-C0C50BC32C7C}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -29,6 +31,10 @@ Global {27C187EE-9298-452F-9FA7-6DF8FC381095}.Debug|Any CPU.Build.0 = Debug|Any CPU {27C187EE-9298-452F-9FA7-6DF8FC381095}.Release|Any CPU.ActiveCfg = Release|Any CPU {27C187EE-9298-452F-9FA7-6DF8FC381095}.Release|Any CPU.Build.0 = Release|Any CPU + {60A266EF-6EFA-42B0-B592-C0C50BC32C7C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {60A266EF-6EFA-42B0-B592-C0C50BC32C7C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {60A266EF-6EFA-42B0-B592-C0C50BC32C7C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {60A266EF-6EFA-42B0-B592-C0C50BC32C7C}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(NestedProjects) = preSolution {8C37002D-05C6-4B1F-B4FC-C2F45C5E5328} = {023319FF-914F-42F7-AE34-3BA9CF91DAEE} diff --git a/README.md b/README.md index 8724b99..8dd95d2 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,8 @@ using Npgmq; var npgmq = new NpgmqClient(""); +await npgmq.InitAsync(); + await npgmq.CreateQueueAsync("my_queue"); var msgId = await npgmq.SendAsync("my_queue", new MyMessageType @@ -35,7 +37,7 @@ var msg = await npgmq.ReadAsync("my_queue"); if (msg != null) { Console.WriteLine($"Read message with id {msg.MsgId}: Foo = {msg.Message?.Foo}, Bar = {msg.Message?.Bar}"); - await npgmq.ArchiveAsync("my_queue", msg!.MsgId); + await npgmq.ArchiveAsync("my_queue", msg.MsgId); } ``` @@ -59,7 +61,7 @@ var msg = await npgmq.ReadAsync("my_queue"); if (msg != null) { Console.WriteLine($"Read message with id {msg.MsgId}: {msg.Message}"); - await npgmq.ArchiveAsync("my_queue", msg!.MsgId); + await npgmq.ArchiveAsync("my_queue", msg.MsgId); } ```