Skip to content

Commit 8ca1e32

Browse files
committed
Update dotnet docs for upcoming 7.0.0 release
* Start by updating the client lib guide * Start migrating tutorial code to version 7 of `RabbitMQ.Client` * Add docusaurus-theme-github-codeblock plugin * Use plugin for .NET tutorials * Fix dotnet tutorial one references * Update dotnet tutorial two to use GitHub references * Update dotnet tutorial three to use GitHub references * Update dotnet tutorial four to use GitHub references * Update dotnet tutorial five and six to use GitHub directly. * Update dotnet tutorial seven to use GitHub references
1 parent 99abdee commit 8ca1e32

File tree

13 files changed

+419
-1078
lines changed

13 files changed

+419
-1078
lines changed

client-libraries/dotnet-api-guide.md

Lines changed: 202 additions & 249 deletions
Large diffs are not rendered by default.

docs/ssl/index.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,24 +1106,28 @@ using System.IO;
11061106
using System.Text;
11071107

11081108
using RabbitMQ.client;
1109-
using RabbitMQ.Util;
11101109

1111-
namespace RabbitMQ.client.Examples {
1112-
public class TestSSL {
1113-
public static int Main(string[] args) {
1110+
namespace RabbitMQ.client.Examples
1111+
{
1112+
public class TestSSL
1113+
{
1114+
public static async Task<int> Main(string[] args)
1115+
{
11141116
ConnectionFactory cf = new ConnectionFactory();
11151117

11161118
cf.Ssl.Enabled = true;
11171119
cf.Ssl.ServerName = System.Net.Dns.GetHostName();
11181120
cf.Ssl.CertPath = "/path/to/client_key.p12";
11191121
cf.Ssl.CertPassphrase = "MySecretPassword";
11201122

1121-
using (IConnection conn = cf.CreateConnection()) {
1122-
using (IModel ch = conn.CreateModel()) {
1123+
using (IConnection conn = await cf.CreateConnectionAsync())
1124+
{
1125+
using (IChannel ch = await conn.CreateChannelAsync())
1126+
{
11231127
Console.WriteLine("Successfully connected and opened a channel");
1124-
ch.QueueDeclare("rabbitmq-dotnet-test", false, false, false, null);
1128+
await ch.QueueDeclareAsync("rabbitmq-dotnet-test", false, false, false, null);
11251129
Console.WriteLine("Successfully declared a queue");
1126-
ch.QueueDelete("rabbitmq-dotnet-test");
1130+
await ch.QueueDeleteAsync("rabbitmq-dotnet-test");
11271131
Console.WriteLine("Successfully deleted the queue");
11281132
}
11291133
}

docusaurus.config.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,10 @@ const config = {
235235
themeConfig:
236236
/** @type {import('@docusaurus/preset-classic').ThemeConfig} */
237237
({
238+
codeblock: {
239+
showGithubLink: true,
240+
githubLinkLabel: 'View on GitHub'
241+
},
238242
colorMode: {
239243
respectPrefersColorScheme: true
240244
},
@@ -435,7 +439,10 @@ const config = {
435439
markdown: {
436440
mermaid: true,
437441
},
438-
themes: ['@docusaurus/theme-mermaid'],
442+
themes: [
443+
'@docusaurus/theme-mermaid',
444+
'docusaurus-theme-github-codeblock'
445+
],
439446
};
440447

441448
export default config;

package-lock.json

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"@docusaurus/theme-mermaid": "^3.5.2",
2020
"@mdx-js/react": "^3.0.0",
2121
"clsx": "^1.2.1",
22+
"docusaurus-theme-github-codeblock": "^2.0.2",
2223
"prism-react-renderer": "^2.1.0",
2324
"react": "^18.0.0",
2425
"react-dom": "^18.0.0",

tutorials/tutorial-five-dotnet.md

Lines changed: 4 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -127,78 +127,14 @@ The code is almost the same as in the
127127

128128
The code for `EmitLogTopic.cs`:
129129

130-
```csharp
131-
using System.Text;
132-
using RabbitMQ.Client;
133-
134-
var factory = new ConnectionFactory { HostName = "localhost" };
135-
136-
using var connection = factory.CreateConnection();
137-
using var channel = connection.CreateModel();
138-
139-
channel.ExchangeDeclare(exchange: "topic_logs", type: ExchangeType.Topic);
140-
141-
var routingKey = (args.Length > 0) ? args[0] : "anonymous.info";
142-
var message = (args.Length > 1)
143-
? string.Join(" ", args.Skip(1).ToArray())
144-
: "Hello World!";
145-
var body = Encoding.UTF8.GetBytes(message);
146-
channel.BasicPublish(exchange: "topic_logs",
147-
routingKey: routingKey,
148-
basicProperties: null,
149-
body: body);
150-
Console.WriteLine($" [x] Sent '{routingKey}':'{message}'");
130+
```csharp reference
131+
https://github.com/rabbitmq/rabbitmq-tutorials/blob/rabbitmq-dotnet-client-7.0.0/dotnet/EmitLogTopic/EmitLogTopic.cs
151132
```
152133

153134
The code for `ReceiveLogsTopic.cs`:
154135

155-
```csharp
156-
using System.Text;
157-
using RabbitMQ.Client;
158-
using RabbitMQ.Client.Events;
159-
160-
var factory = new ConnectionFactory { HostName = "localhost" };
161-
162-
using var connection = factory.CreateConnection();
163-
using var channel = connection.CreateModel();
164-
165-
channel.ExchangeDeclare(exchange: "topic_logs", type: ExchangeType.Topic);
166-
// declare a server-named queue
167-
var queueName = channel.QueueDeclare().QueueName;
168-
169-
if (args.Length < 1)
170-
{
171-
Console.Error.WriteLine("Usage: {0} [binding_key...]",
172-
Environment.GetCommandLineArgs()[0]);
173-
Console.WriteLine(" Press [enter] to exit.");
174-
Console.ReadLine();
175-
Environment.ExitCode = 1;
176-
return;
177-
}
178-
179-
foreach (var bindingKey in args)
180-
{
181-
channel.QueueBind(queue: queueName,
182-
exchange: "topic_logs",
183-
routingKey: bindingKey);
184-
}
185-
186-
Console.WriteLine(" [*] Waiting for messages. To exit press CTRL+C");
187-
188-
var consumer = new EventingBasicConsumer(channel);
189-
consumer.Received += (model, ea) =>
190-
{
191-
var body = ea.Body.ToArray();
192-
var message = Encoding.UTF8.GetString(body);
193-
var routingKey = ea.RoutingKey;
194-
Console.WriteLine($" [x] Received '{routingKey}':'{message}'");
195-
};
196-
channel.BasicConsume(queue: queueName,
197-
autoAck: true,
198-
consumer: consumer);
199-
200-
Console.WriteLine(" Press [enter] to exit.");
201-
Console.ReadLine();
136+
```csharp reference
137+
https://github.com/rabbitmq/rabbitmq-tutorials/blob/rabbitmq-dotnet-client-7.0.0/dotnet/ReceiveLogsTopic/ReceiveLogsTopic.cs
202138
```
203139

204140
Run the following examples:
@@ -242,7 +178,4 @@ Have fun playing with these programs. Note that the code doesn't make
242178
any assumption about the routing or binding keys, you may want to play
243179
with more than two routing key parameters.
244180

245-
(Full source code for [EmitLogTopic.cs](https://github.com/rabbitmq/rabbitmq-tutorials/blob/main/dotnet/EmitLogTopic/EmitLogTopic.cs)
246-
and [ReceiveLogsTopic.cs](https://github.com/rabbitmq/rabbitmq-tutorials/blob/main/dotnet/ReceiveLogsTopic/ReceiveLogsTopic.cs))
247-
248181
Next, find out how to do a round trip message as a remote procedure call in [tutorial 6](./tutorial-six-dotnet).

tutorials/tutorial-four-dotnet.md

Lines changed: 14 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -47,24 +47,20 @@ Bindings
4747
In previous examples we were already creating bindings. You may recall
4848
code like:
4949

50-
```csharp
51-
channel.QueueBind(queue: queueName,
52-
exchange: "logs",
53-
routingKey: string.Empty);
50+
```csharp reference
51+
https://github.com/rabbitmq/rabbitmq-tutorials/blob/rabbitmq-dotnet-client-7.0.0/dotnet/ReceiveLogs/ReceiveLogs.cs#L15
5452
```
5553

5654
A binding is a relationship between an exchange and a queue. This can
5755
be simply read as: the queue is interested in messages from this
5856
exchange.
5957

6058
Bindings can take an extra `routingKey` parameter. To avoid the
61-
confusion with a `BasicPublish` parameter we're going to call it a
59+
confusion with a `BasicPublishAsync` parameter we're going to call it a
6260
`binding key`. This is how we could create a binding with a key:
6361

6462
```csharp
65-
channel.QueueBind(queue: queueName,
66-
exchange: "direct_logs",
67-
routingKey: "black");
63+
await channel.QueueBindAsync(queue: queueName, exchange: "direct_logs", routingKey: "black");
6864
```
6965

7066
The meaning of a binding key depends on the exchange type. The
@@ -124,18 +120,14 @@ first.
124120

125121
As always, we need to create an exchange first:
126122

127-
```csharp
128-
channel.ExchangeDeclare(exchange: "direct_logs", type: ExchangeType.Direct);
123+
```csharp reference
124+
https://github.com/rabbitmq/rabbitmq-tutorials/blob/rabbitmq-dotnet-client-7.0.0/dotnet/EmitLogDirect/EmitLogDirect.cs#L8
129125
```
130126

131127
And we're ready to send a message:
132128

133-
```csharp
134-
var body = Encoding.UTF8.GetBytes(message);
135-
channel.BasicPublish(exchange: "direct_logs",
136-
routingKey: severity,
137-
basicProperties: null,
138-
body: body);
129+
```csharp reference
130+
https://github.com/rabbitmq/rabbitmq-tutorials/blob/rabbitmq-dotnet-client-7.0.0/dotnet/EmitLogDirect/EmitLogDirect.cs#L12-L13
139131
```
140132

141133
To simplify things we will assume that 'severity' can be one of
@@ -150,15 +142,8 @@ one exception - we're going to create a new binding for each severity
150142
we're interested in.
151143

152144

153-
```csharp
154-
var queueName = channel.QueueDeclare().QueueName;
155-
156-
foreach(var severity in args)
157-
{
158-
channel.QueueBind(queue: queueName,
159-
exchange: "direct_logs",
160-
routingKey: severity);
161-
}
145+
```csharp reference
146+
https://github.com/rabbitmq/rabbitmq-tutorials/blob/rabbitmq-dotnet-client-7.0.0/dotnet/ReceiveLogsDirect/ReceiveLogsDirect.cs#L23-L29
162147
```
163148

164149
Putting it all together
@@ -171,80 +156,14 @@ Putting it all together
171156

172157
The code for `EmitLogDirect.cs` class:
173158

174-
```csharp
175-
using System.Text;
176-
using RabbitMQ.Client;
177-
178-
var factory = new ConnectionFactory { HostName = "localhost" };
179-
using var connection = factory.CreateConnection();
180-
using var channel = connection.CreateModel();
181-
182-
channel.ExchangeDeclare(exchange: "direct_logs", type: ExchangeType.Direct);
183-
184-
var severity = (args.Length > 0) ? args[0] : "info";
185-
var message = (args.Length > 1)
186-
? string.Join(" ", args.Skip(1).ToArray())
187-
: "Hello World!";
188-
var body = Encoding.UTF8.GetBytes(message);
189-
channel.BasicPublish(exchange: "direct_logs",
190-
routingKey: severity,
191-
basicProperties: null,
192-
body: body);
193-
Console.WriteLine($" [x] Sent '{severity}':'{message}'");
194-
195-
Console.WriteLine(" Press [enter] to exit.");
196-
Console.ReadLine();
159+
```csharp reference
160+
https://github.com/rabbitmq/rabbitmq-tutorials/blob/rabbitmq-dotnet-client-7.0.0/dotnet/EmitLogDirect/EmitLogDirect.cs
197161
```
198162

199163
The code for `ReceiveLogsDirect.cs`:
200164

201-
```csharp
202-
using System.Text;
203-
using RabbitMQ.Client;
204-
using RabbitMQ.Client.Events;
205-
206-
var factory = new ConnectionFactory { HostName = "localhost" };
207-
208-
using var connection = factory.CreateConnection();
209-
using var channel = connection.CreateModel();
210-
211-
channel.ExchangeDeclare(exchange: "direct_logs", type: ExchangeType.Direct);
212-
// declare a server-named queue
213-
var queueName = channel.QueueDeclare().QueueName;
214-
215-
if (args.Length < 1)
216-
{
217-
Console.Error.WriteLine("Usage: {0} [info] [warning] [error]",
218-
Environment.GetCommandLineArgs()[0]);
219-
Console.WriteLine(" Press [enter] to exit.");
220-
Console.ReadLine();
221-
Environment.ExitCode = 1;
222-
return;
223-
}
224-
225-
foreach (var severity in args)
226-
{
227-
channel.QueueBind(queue: queueName,
228-
exchange: "direct_logs",
229-
routingKey: severity);
230-
}
231-
232-
Console.WriteLine(" [*] Waiting for messages.");
233-
234-
var consumer = new EventingBasicConsumer(channel);
235-
consumer.Received += (model, ea) =>
236-
{
237-
var body = ea.Body.ToArray();
238-
var message = Encoding.UTF8.GetString(body);
239-
var routingKey = ea.RoutingKey;
240-
Console.WriteLine($" [x] Received '{routingKey}':'{message}'");
241-
};
242-
channel.BasicConsume(queue: queueName,
243-
autoAck: true,
244-
consumer: consumer);
245-
246-
Console.WriteLine(" Press [enter] to exit.");
247-
Console.ReadLine();
165+
```csharp reference
166+
https://github.com/rabbitmq/rabbitmq-tutorials/blob/rabbitmq-dotnet-client-7.0.0/dotnet/ReceiveLogsDirect/ReceiveLogsDirect.cs
248167
```
249168

250169
Create projects as usual (see [tutorial one](./tutorial-one-dotnet) for
@@ -275,8 +194,5 @@ dotnet run error "Run. Run. Or it will explode."
275194
# => [x] Sent 'error':'Run. Run. Or it will explode.'
276195
```
277196

278-
(Full source code for [(EmitLogDirect.cs source)](https://github.com/rabbitmq/rabbitmq-tutorials/blob/main/dotnet/EmitLogDirect/EmitLogDirect.cs)
279-
and [(ReceiveLogsDirect.cs source)](https://github.com/rabbitmq/rabbitmq-tutorials/blob/main/dotnet/ReceiveLogsDirect/ReceiveLogsDirect.cs))
280-
281197
Move on to [tutorial 5](./tutorial-five-dotnet) to find out how to listen
282198
for messages based on a pattern.

0 commit comments

Comments
 (0)