Skip to content

Commit f441534

Browse files
Fix RabbitMQ sample (#156)
1 parent e3e666b commit f441534

File tree

13 files changed

+34
-88
lines changed

13 files changed

+34
-88
lines changed

.github/workflows/test-matrix.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
workflow_call:
55
inputs:
66
include_docker_info:
7-
description: 'Whether to include Docker information step'
7+
description: "Whether to include Docker information step"
88
required: false
99
type: boolean
1010
default: false
@@ -18,7 +18,7 @@ jobs:
1818
- uses: actions/checkout@v2
1919
- id: set-matrix
2020
run: |
21-
PROJECTS=$(find . -name '*.Tests.csproj' | sed 's|.*/\([^/]*\)\.csproj|\1|' | jq -R -s -c 'split("\n")[:-1]')
21+
PROJECTS=$(find . \( -name '*.Tests.csproj' -o -name '*.Sample.csproj' \) | sed 's|.*/\([^/]*\)\.csproj|\1|' | jq -R -s -c 'split("\n")[:-1]')
2222
FRAMEWORKS='["net8.0", "net9.0","net10.0"]'
2323
MATRIX=$(jq -n \
2424
--argjson projects "$PROJECTS" \
@@ -35,22 +35,22 @@ jobs:
3535
runs-on: ubuntu-latest
3636
name: ${{ matrix.test_project }} ${{ matrix.framework }}
3737
strategy:
38-
matrix:
38+
matrix:
3939
test_project: ${{fromJson(needs.prepare.outputs.matrix).test_project}}
4040
framework: ${{fromJson(needs.prepare.outputs.matrix).framework}}
4141
fail-fast: false
4242
steps:
4343
- name: Checkout code
4444
uses: actions/checkout@v2
45-
45+
4646
- name: Setup .NET
4747
uses: actions/setup-dotnet@v4
4848
with:
4949
dotnet-version: |
5050
8
5151
9
5252
10
53-
53+
5454
- name: Docker Information
5555
if: ${{ inputs.include_docker_info }}
5656
run: |

samples/AzureCloudServiceBus/AzureCloudServiceBus.csproj renamed to samples/AzureCloudServiceBus/AzureCloudServiceBus.Sample.csproj

File renamed without changes.

samples/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project>
22
<PropertyGroup>
3-
<TargetFramework>net9.0</TargetFramework>
3+
<TargetFramework>net10.0</TargetFramework>
44
<IsPackable>false</IsPackable>
55
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
66
</PropertyGroup>
File renamed without changes.
File renamed without changes.

samples/RabbitMQ/OrderBrokerTests.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,24 @@ public async Task SendEvent_Received()
3434
var broker = new OrderEventBroker(connectionFactory);
3535

3636
// Act
37-
broker.SendEvent(ev);
37+
await broker.SendEventAsync(ev);
3838

3939
OrderEvent resultEvent = null;
4040

41-
using IConnection connection = connectionFactory.CreateConnection();
42-
using IModel channel = connection.CreateModel();
43-
channel.QueueDeclare(
41+
await using IConnection connection = await connectionFactory.CreateConnectionAsync();
42+
await using IChannel channel = await connection.CreateChannelAsync();
43+
44+
await channel.QueueDeclareAsync(
4445
OrderEventBroker.QueueName,
4546
false,
4647
false,
4748
false,
4849
null);
4950

50-
BasicGetResult queueResult = channel.BasicGet(OrderEventBroker.QueueName, true);
51+
BasicGetResult queueResult = await channel.BasicGetAsync(OrderEventBroker.QueueName, true);
5152
if (queueResult != null)
5253
{
53-
var json = Encoding.UTF8.GetString(queueResult.Body);
54+
var json = Encoding.UTF8.GetString(queueResult.Body.Span);
5455
resultEvent = JsonSerializer.Deserialize<OrderEvent>(json);
5556
}
5657

samples/RabbitMQ/OrderEventBroker.cs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,24 @@ public OrderEventBroker(IConnectionFactory connectionFactory)
1919
_connectionFactory = connectionFactory;
2020
}
2121

22-
public void SendEvent(OrderEvent @event)
22+
public async Task SendEventAsync(OrderEvent @event)
2323
{
24-
using IConnection connection = _connectionFactory.CreateConnection();
25-
using IModel channel = connection.CreateModel();
26-
channel.QueueDeclare(
24+
await using IConnection connection = await _connectionFactory.CreateConnectionAsync();
25+
await using IChannel channel = await connection.CreateChannelAsync();
26+
27+
await channel.QueueDeclareAsync(
2728
QueueName,
2829
false,
2930
false,
3031
false,
3132
null);
3233

33-
channel.BasicPublish(
34-
string.Empty,
35-
QueueName,
36-
null,
37-
BuildMessage(@event));
34+
await channel.BasicPublishAsync(
35+
exchange: string.Empty,
36+
routingKey: QueueName,
37+
mandatory: false,
38+
basicProperties: new BasicProperties(),
39+
body: BuildMessage(@event));
3840
}
3941

4042
private static byte[] BuildMessage(OrderEvent @event)

0 commit comments

Comments
 (0)