Skip to content

Commit 2beaca8

Browse files
Add additional message acknowledgement functionality (#77)
* Initial work on c4 component diagram * Added simplerabbit.publish project to component diagram * Added component diagram to README * Added contribution notes * Added Acknowledgement Enum * Removed duplicate documentation - examples are provided in readme * Added acknowledge switch in QueueService * added Ignore value to facilitate the asyncmessagehandler HACK * Added HandleAck() to BasicMessage; implemented the new ack functionality into ParallelMessageHandler * Made the test project compile again * Made example projects compile * Updated docs on running the local rabbit server * Updated projects to netstandard * Updated libraries * Updated example projects to net6 * Fixed BasicRabbitServiceTests.cs tests * Fixed QueuePrefetchTests.cs unit tests * Added unit tests for acknowledgement behaviour * Renamed Acknowledge.Ignore to Acknowledge.Manual * Updated library summaries * Updated README * Converted example projects to .net6 * Updated xml doc for Acknowledgement enum * Updated README * Initial work on making IMessageHandler async * Renamed ParallelMessageHandler to OrderedMessageHandler to better reflect the purpose; add async support to IMessageHandler * Code cleanup * Updated README * Updated github actions workflow scripts to use .NET6 --------- Co-authored-by: Ashik <[email protected]>
1 parent bd86a74 commit 2beaca8

30 files changed

+709
-374
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
- uses: actions/checkout@master
1616
- uses: actions/setup-dotnet@v1
1717
with:
18-
dotnet-version: '3.1.x'
18+
dotnet-version: '6.0.x'
1919

2020
- name: Run the build script
2121
run: ./build/build.sh

.github/workflows/deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
- uses: actions/checkout@master
1414
- uses: actions/setup-dotnet@v1
1515
with:
16-
dotnet-version: '3.1.x'
16+
dotnet-version: '6.0.x'
1717

1818
- name: Run the build and deploy script
1919
run: ./build/build.sh deploy

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,4 @@ FolderProfile.pubxml
3333
*.csproj.DotSettings
3434
artifacts/
3535
.vscode/
36+
.idea/

Examples/Multi-Publisher/Multi-Publisher.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
<TargetFramework>net6.0</TargetFramework>
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="microsoft.extensions.Configuration.Json" Version="3.1.7" />
10-
<PackageReference Include="microsoft.extensions.DependencyInjection" Version="3.1.7" />
9+
<PackageReference Include="microsoft.extensions.Configuration.Json" Version="6.0.0" />
10+
<PackageReference Include="microsoft.extensions.DependencyInjection" Version="6.0.1" />
1111
</ItemGroup>
1212

1313
<ItemGroup>

Examples/Multi-Subscriber.Service/Multi-Subscriber.Service.csproj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFramework>netcoreapp3.1</TargetFramework>
3+
<TargetFramework>net6.0</TargetFramework>
44
<ApplicationIcon />
55
<OutputType>Exe</OutputType>
66
<StartupObject />
77
<NoWin32Manifest>true</NoWin32Manifest>
88
</PropertyGroup>
99
<ItemGroup>
10-
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="3.1.7" />
11-
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="3.1.7" />
12-
<PackageReference Include="microsoft.extensions.configuration.Json" Version="3.1.7" />
13-
<PackageReference Include="Microsoft.Extensions.Logging.Configuration" Version="3.1.7" />
14-
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.1.7" />
10+
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="6.0.0" />
11+
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="6.0.1" />
12+
<PackageReference Include="microsoft.extensions.configuration.Json" Version="6.0.0" />
13+
<PackageReference Include="Microsoft.Extensions.Logging.Configuration" Version="6.0.0" />
14+
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="6.0.0" />
1515
</ItemGroup>
1616
<ItemGroup>
1717
<Folder Include="Properties\" />

Examples/Multi-Subscriber.Service/Service/MessageProcessor.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Threading.Tasks;
23
using SimpleRabbit.NetCore;
34

45
namespace Subscriber.Service.Service
@@ -10,12 +11,12 @@ public bool CanProcess(string tag)
1011
return true;
1112
}
1213

13-
public bool Process(BasicMessage message)
14+
public async Task<Acknowledgement> Process(BasicMessage message)
1415
{
1516
Console.WriteLine(message.Body);
1617

17-
// return true if you want to ack immediately. False if you want to handle the ack (e.g. dispatch to a thread - and ack later).
18-
return true;
18+
// See Acknowledgement enum for available options.
19+
return Acknowledgement.Ack;
1920
}
2021
}
2122
}

Examples/Publisher/Publisher.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
<TargetFramework>net6.0</TargetFramework>
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="microsoft.extensions.Configuration.Json" Version="3.1.7" />
10-
<PackageReference Include="microsoft.extensions.DependencyInjection" Version="3.1.7" />
11-
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.1.7" />
9+
<PackageReference Include="microsoft.extensions.Configuration.Json" Version="6.0.0" />
10+
<PackageReference Include="microsoft.extensions.DependencyInjection" Version="6.0.1" />
11+
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="6.0.0" />
1212
</ItemGroup>
1313

1414
<ItemGroup>

Examples/Subscriber.Service/Service/MessageProcessor.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Threading.Tasks;
23
using SimpleRabbit.NetCore;
34

45
namespace Subscriber.Service.Service
@@ -10,12 +11,12 @@ public bool CanProcess(string tag)
1011
return true;
1112
}
1213

13-
public bool Process(BasicMessage message)
14+
public async Task<Acknowledgement> Process(BasicMessage message)
1415
{
1516
Console.WriteLine(message.Body);
1617

17-
// return true if you want to ack immediately. False if you want to handle the ack (e.g. dispatch to a thread - and ack later).
18-
return true;
18+
// See Acknowledgement enum for available options.
19+
return Acknowledgement.Ack;
1920
}
2021
}
2122
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using System.Text.Json;
2+
using System.Threading.Tasks;
3+
using Microsoft.Extensions.Logging;
4+
using SimpleRabbit.NetCore;
5+
6+
namespace Subscriber.Service.Service
7+
{
8+
public record TestDeserialisedMessage(int Key, string Value);
9+
10+
public class OrderedMessageHandler : OrderedMessageHandler<int, TestDeserialisedMessage>
11+
{
12+
public OrderedMessageHandler(ILogger<OrderedMessageHandler<int, TestDeserialisedMessage>> logger) : base(logger)
13+
{
14+
}
15+
16+
public override bool CanProcess(string tag)
17+
{
18+
return true;
19+
}
20+
21+
protected override ParseResult Parse(BasicMessage message)
22+
{
23+
try
24+
{
25+
var deserialised = JsonSerializer.Deserialize<TestDeserialisedMessage>(message.Body);
26+
return ParseResult.Success(deserialised.Key, deserialised);
27+
}
28+
catch (JsonException)
29+
{
30+
// If message cannot be deserialized, you can specify the acknowledgement behaviour for more granularity.
31+
return ParseResult.Fail(Acknowledgement.Ack);
32+
}
33+
}
34+
35+
protected override async Task<Acknowledgement> ProcessAsync(TestDeserialisedMessage body)
36+
{
37+
// Process the message here.
38+
39+
// Return the acknowledgement.
40+
return Acknowledgement.Ack;
41+
}
42+
}
43+
}

Examples/Subscriber.Service/Subscriber.Service.csproj

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFramework>netcoreapp3.1</TargetFramework>
3+
<TargetFramework>net6.0</TargetFramework>
44
<ApplicationIcon />
55
<OutputType>Exe</OutputType>
66
<StartupObject />
77
<NoWin32Manifest>true</NoWin32Manifest>
8+
<LangVersion>9</LangVersion>
89
</PropertyGroup>
9-
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
10-
<LangVersion>7.1</LangVersion>
11-
</PropertyGroup>
12-
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
13-
<LangVersion>7.1</LangVersion>
14-
</PropertyGroup>
10+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'" />
11+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'" />
1512
<ItemGroup>
16-
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="3.1.7" />
17-
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="3.1.7" />
18-
<PackageReference Include="microsoft.extensions.configuration.Json" Version="3.1.7" />
19-
<PackageReference Include="Microsoft.Extensions.Logging.Configuration" Version="3.1.7" />
20-
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.1.7" />
13+
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="6.0.0" />
14+
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="6.0.1" />
15+
<PackageReference Include="microsoft.extensions.configuration.Json" Version="6.0.0" />
16+
<PackageReference Include="Microsoft.Extensions.Logging.Configuration" Version="6.0.0" />
17+
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="6.0.0" />
2118
</ItemGroup>
2219
<ItemGroup>
2320
<Folder Include="Properties\" />

0 commit comments

Comments
 (0)