Skip to content

Commit 6ee90ea

Browse files
committed
Update dotnet tutorials to use 7.0.0-rc.9
This is in preparation of the next `RabbitMQ.Client` release
1 parent 7c9f60a commit 6ee90ea

26 files changed

+596
-510
lines changed

dotnet/EmitLog/EmitLog.cs

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
1-
using System.Text;
2-
using RabbitMQ.Client;
3-
4-
var factory = new ConnectionFactory { HostName = "localhost" };
5-
using var connection = factory.CreateConnection();
6-
using var channel = connection.CreateModel();
7-
8-
channel.ExchangeDeclare(exchange: "logs", type: ExchangeType.Fanout);
9-
10-
var message = GetMessage(args);
11-
var body = Encoding.UTF8.GetBytes(message);
12-
channel.BasicPublish(exchange: "logs",
13-
routingKey: string.Empty,
14-
basicProperties: null,
15-
body: body);
16-
Console.WriteLine($" [x] Sent {message}");
17-
18-
Console.WriteLine(" Press [enter] to exit.");
19-
Console.ReadLine();
20-
21-
static string GetMessage(string[] args)
22-
{
23-
return ((args.Length > 0) ? string.Join(" ", args) : "info: Hello World!");
24-
}
1+
using RabbitMQ.Client;
2+
using System.Text;
3+
4+
var factory = new ConnectionFactory { HostName = "localhost" };
5+
using var connection = await factory.CreateConnectionAsync();
6+
using var channel = await connection.CreateChannelAsync();
7+
8+
await channel.ExchangeDeclareAsync(exchange: "logs", type: ExchangeType.Fanout);
9+
10+
var message = GetMessage(args);
11+
var body = Encoding.UTF8.GetBytes(message);
12+
await channel.BasicPublishAsync(exchange: "logs", routingKey: string.Empty, body: body);
13+
Console.WriteLine($" [x] Sent {message}");
14+
15+
Console.WriteLine(" Press [enter] to exit.");
16+
Console.ReadLine();
17+
18+
static string GetMessage(string[] args)
19+
{
20+
return ((args.Length > 0) ? string.Join(" ", args) : "info: Hello World!");
21+
}

dotnet/EmitLog/EmitLog.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net7.0</TargetFramework>
4+
<TargetFramework>net8.0</TargetFramework>
55
<OutputType>Exe</OutputType>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="RabbitMQ.Client" Version="6.4.0" />
11+
<PackageReference Include="RabbitMQ.Client" Version="7.0.0-rc.9" />
1212
</ItemGroup>
1313

1414
</Project>

dotnet/EmitLogDirect/EmitLogDirect.cs

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
1-
using System.Text;
2-
using RabbitMQ.Client;
3-
4-
var factory = new ConnectionFactory { HostName = "localhost" };
5-
using var connection = factory.CreateConnection();
6-
using var channel = connection.CreateModel();
7-
8-
channel.ExchangeDeclare(exchange: "direct_logs", type: ExchangeType.Direct);
9-
10-
var severity = (args.Length > 0) ? args[0] : "info";
11-
var message = (args.Length > 1)
12-
? string.Join(" ", args.Skip(1).ToArray())
13-
: "Hello World!";
14-
var body = Encoding.UTF8.GetBytes(message);
15-
channel.BasicPublish(exchange: "direct_logs",
16-
routingKey: severity,
17-
basicProperties: null,
18-
body: body);
19-
Console.WriteLine($" [x] Sent '{severity}':'{message}'");
20-
21-
Console.WriteLine(" Press [enter] to exit.");
22-
Console.ReadLine();
1+
using RabbitMQ.Client;
2+
using System.Text;
3+
4+
var factory = new ConnectionFactory { HostName = "localhost" };
5+
using var connection = await factory.CreateConnectionAsync();
6+
using var channel = await connection.CreateChannelAsync();
7+
8+
await channel.ExchangeDeclareAsync(exchange: "direct_logs", type: ExchangeType.Direct);
9+
10+
var severity = (args.Length > 0) ? args[0] : "info";
11+
var message = (args.Length > 1) ? string.Join(" ", args.Skip(1).ToArray()) : "Hello World!";
12+
var body = Encoding.UTF8.GetBytes(message);
13+
await channel.BasicPublishAsync(exchange: "direct_logs", routingKey: severity, body: body);
14+
Console.WriteLine($" [x] Sent '{severity}':'{message}'");
15+
16+
Console.WriteLine(" Press [enter] to exit.");
17+
Console.ReadLine();
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net7.0</TargetFramework>
4+
<TargetFramework>net8.0</TargetFramework>
55
<OutputType>Exe</OutputType>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="RabbitMQ.Client" Version="6.4.0" />
11+
<PackageReference Include="RabbitMQ.Client" Version="7.0.0-rc.9" />
1212
</ItemGroup>
1313

1414
</Project>

dotnet/EmitLogTopic/EmitLogTopic.cs

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
1-
using System.Text;
2-
using RabbitMQ.Client;
3-
4-
var factory = new ConnectionFactory { HostName = "localhost" };
5-
6-
using var connection = factory.CreateConnection();
7-
using var channel = connection.CreateModel();
8-
9-
channel.ExchangeDeclare(exchange: "topic_logs", type: ExchangeType.Topic);
10-
11-
var routingKey = (args.Length > 0) ? args[0] : "anonymous.info";
12-
var message = (args.Length > 1)
13-
? string.Join(" ", args.Skip(1).ToArray())
14-
: "Hello World!";
15-
var body = Encoding.UTF8.GetBytes(message);
16-
channel.BasicPublish(exchange: "topic_logs",
17-
routingKey: routingKey,
18-
basicProperties: null,
19-
body: body);
20-
Console.WriteLine($" [x] Sent '{routingKey}':'{message}'");
1+
using RabbitMQ.Client;
2+
using System.Text;
3+
4+
var factory = new ConnectionFactory { HostName = "localhost" };
5+
using var connection = await factory.CreateConnectionAsync();
6+
using var channel = await connection.CreateChannelAsync();
7+
8+
await channel.ExchangeDeclareAsync(exchange: "topic_logs", type: ExchangeType.Topic);
9+
10+
var routingKey = (args.Length > 0) ? args[0] : "anonymous.info";
11+
var message = (args.Length > 1) ? string.Join(" ", args.Skip(1).ToArray()) : "Hello World!";
12+
var body = Encoding.UTF8.GetBytes(message);
13+
await channel.BasicPublishAsync(exchange: "topic_logs", routingKey: routingKey, body: body);
14+
Console.WriteLine($" [x] Sent '{routingKey}':'{message}'");
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net7.0</TargetFramework>
4+
<TargetFramework>net8.0</TargetFramework>
55
<OutputType>Exe</OutputType>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="RabbitMQ.Client" Version="6.4.0" />
11+
<PackageReference Include="RabbitMQ.Client" Version="7.0.0-rc.9" />
1212
</ItemGroup>
1313

1414
</Project>

dotnet/NewTask/NewTask.cs

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,26 @@
1-
using System.Text;
2-
using RabbitMQ.Client;
3-
4-
var factory = new ConnectionFactory { HostName = "localhost" };
5-
using var connection = factory.CreateConnection();
6-
using var channel = connection.CreateModel();
7-
8-
channel.QueueDeclare(queue: "task_queue",
9-
durable: true,
10-
exclusive: false,
11-
autoDelete: false,
12-
arguments: null);
13-
14-
var message = GetMessage(args);
15-
var body = Encoding.UTF8.GetBytes(message);
16-
17-
var properties = channel.CreateBasicProperties();
18-
properties.Persistent = true;
19-
20-
channel.BasicPublish(exchange: string.Empty,
21-
routingKey: "task_queue",
22-
basicProperties: properties,
23-
body: body);
24-
Console.WriteLine($" [x] Sent {message}");
25-
26-
Console.WriteLine(" Press [enter] to exit.");
27-
Console.ReadLine();
28-
29-
static string GetMessage(string[] args)
30-
{
31-
return ((args.Length > 0) ? string.Join(" ", args) : "Hello World!");
32-
}
1+
using RabbitMQ.Client;
2+
using System.Text;
3+
4+
var factory = new ConnectionFactory { HostName = "localhost" };
5+
using var connection = await factory.CreateConnectionAsync();
6+
using var channel = await connection.CreateChannelAsync();
7+
8+
await channel.QueueDeclareAsync(queue: "task_queue", durable: true, exclusive: false,
9+
autoDelete: false, arguments: null);
10+
11+
var message = GetMessage(args);
12+
var body = Encoding.UTF8.GetBytes(message);
13+
14+
var properties = new BasicProperties
15+
{
16+
Persistent = true
17+
};
18+
19+
await channel.BasicPublishAsync(exchange: string.Empty, routingKey: "task_queue", mandatory: true,
20+
basicProperties: properties, body: body);
21+
Console.WriteLine($" [x] Sent {message}");
22+
23+
static string GetMessage(string[] args)
24+
{
25+
return ((args.Length > 0) ? string.Join(" ", args) : "Hello World!");
26+
}

dotnet/NewTask/NewTask.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net7.0</TargetFramework>
4+
<TargetFramework>net8.0</TargetFramework>
55
<OutputType>Exe</OutputType>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="RabbitMQ.Client" Version="6.4.0" />
11+
<PackageReference Include="RabbitMQ.Client" Version="7.0.0-rc.9" />
1212
</ItemGroup>
1313

1414
</Project>

0 commit comments

Comments
 (0)