Skip to content

Commit 0f18bb7

Browse files
authored
Dotnet stream client tutorial getting started (#382)
* dotnet stream tutorial hello world --------- Signed-off-by: Gabriele Santomaggio <[email protected]>
1 parent c3170b0 commit 0f18bb7

File tree

7 files changed

+245
-0
lines changed

7 files changed

+245
-0
lines changed

dotnet-stream/.gitignore

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
## Misc files
2+
*.bak
3+
.DS_Store
4+
.idea
5+
InternalTrace*
6+
[Ll]ocal.dist
7+
[Ll]ocal.props
8+
*.lock.json
9+
nunit-agent*
10+
*.pyc
11+
*.VisualState.xml
12+
.vscode
13+
14+
## Misc directories
15+
.fake/
16+
gensrc/
17+
.ionide/
18+
NuGet/
19+
tmp/
20+
.vscode/
21+
22+
#################
23+
## Visual Studio
24+
#################
25+
26+
## Ignore Visual Studio temporary files, build results, and
27+
## files generated by popular Visual Studio add-ons.
28+
29+
# User-specific files
30+
*.suo
31+
*.user
32+
*.sln.docstates
33+
34+
# Build results
35+
[Dd]ebug/
36+
[Rr]elease/
37+
x64/
38+
build/
39+
[Bb]in/
40+
[Oo]bj/
41+
*.lock.json
42+
43+
BenchmarkDotNet.Artifacts/*
44+
45+
APIApproval.Approve.received.txt
46+
47+
# Visual Studio 2015 cache/options directory
48+
.vs/
49+
50+
# Visual Studio profiler
51+
*.psess
52+
*.vsp
53+
*.vspx
54+
55+
# ReSharper is a .NET coding add-in
56+
_ReSharper*/
57+
*.[Rr]e[Ss]harper
58+
59+
# DotCover is a Code Coverage Tool
60+
*.dotCover
61+
62+
# NCrunch
63+
*.ncrunch*
64+
.*crunch*.local.xml
65+
66+
# Installshield output folder
67+
[Ee]xpress/
68+
69+
# DocProject is a documentation generator add-in
70+
DocProject/buildhelp/
71+
DocProject/Help/*.HxT
72+
DocProject/Help/*.HxC
73+
DocProject/Help/*.hhc
74+
DocProject/Help/*.hhk
75+
DocProject/Help/*.hhp
76+
DocProject/Help/Html2
77+
DocProject/Help/html
78+
79+
# NuGet Packages Directory
80+
packages/
81+
/packages
82+
83+
# Windows Store app package directory
84+
AppPackages/
85+
86+
# Others
87+
sql/
88+
*.Cache
89+
ClientBin/
90+
[Ss]tyle[Cc]op.*
91+
~$*
92+
*~
93+
*.dbmdl
94+
*.[Pp]ublish.xml
95+
*.pfx
96+
*.publishsettings
97+
98+
# Backup & report files from converting an old project file to a newer
99+
# Visual Studio version. Backup files are not needed, because we have git ;-)
100+
_UpgradeReport_Files/
101+
Backup*/
102+
UpgradeLog*.XML
103+
UpgradeLog*.htm
104+
105+
# Unit tests
106+
projects/Unit*/TestResult.xml
107+
108+
# Development scripts
109+
*.pcap
110+
111+
# Vim
112+
.sw?
113+
.*.sw?

dotnet-stream/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Dotnet Stream C# code for RabbitMQ tutorials
2+
3+
Here you can find the C# code examples for [RabbitMQ
4+
tutorials](https://www.rabbitmq.com/getstarted.html) using .NET 8.0.
5+
6+
To successfully use the examples you will need a running RabbitMQ server with the [stream plugin enabled](https://www.rabbitmq.com/docs/stream#enabling-plugin).
7+
8+
## Requirements
9+
10+
### Requirements on Windows
11+
12+
* [dotnet core](https://www.microsoft.com/net/core)
13+
14+
We're using the command line (start->run cmd.exe) to
15+
compile and run the code.
16+
17+
### Requirements on Linux
18+
19+
* [dotnet core](https://www.microsoft.com/net/core)
20+
21+
### Code
22+
23+
Each command is best run in a separate console/terminal instance run from the root
24+
of the tutorial directory.
25+
26+
#### [Tutorial one: "Hello World!"](https://www.rabbitmq.com/tutorials/tutorial-one-dotnet-stream.html)
27+
28+
dotnet run --project Receive/Receive.csproj
29+
dotnet run --project Send/Send.csproj

dotnet-stream/Receive/Receive.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// See https://aka.ms/new-console-template for more information
2+
3+
using System.Text;
4+
using RabbitMQ.Stream.Client;
5+
using RabbitMQ.Stream.Client.Reliable;
6+
7+
var streamSystem = await StreamSystem.Create(new StreamSystemConfig());
8+
9+
await streamSystem.CreateStream(new StreamSpec("hello-stream")
10+
{
11+
MaxLengthBytes = 5_000_000_000
12+
});
13+
14+
15+
var consumer = await Consumer.Create(new ConsumerConfig(streamSystem, "hello-stream")
16+
{
17+
OffsetSpec = new OffsetTypeFirst(),
18+
MessageHandler = async (stream, _, _, message) =>
19+
{
20+
Console.WriteLine($"Stream: {stream} - " +
21+
$"Received message: {Encoding.UTF8.GetString(message.Data.Contents)}");
22+
await Task.CompletedTask;
23+
}
24+
});
25+
26+
Console.WriteLine(" [x] Press any key to exit");
27+
Console.ReadKey();
28+
29+
await consumer.Close();
30+
await streamSystem.Close();

dotnet-stream/Receive/Receive.csproj

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
<RootNamespace>ReceiveHello</RootNamespace>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="RabbitMQ.Stream.Client" Version="1.8.3" />
13+
</ItemGroup>
14+
15+
</Project>

dotnet-stream/Send/Send.csproj

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
<RootNamespace>SendHello</RootNamespace>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="RabbitMQ.Stream.Client" Version="1.8.3" />
13+
</ItemGroup>
14+
15+
</Project>

dotnet-stream/Send/Sends.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System.Text;
2+
using RabbitMQ.Stream.Client;
3+
using RabbitMQ.Stream.Client.Reliable;
4+
5+
var streamSystem = await StreamSystem.Create(new StreamSystemConfig());
6+
7+
await streamSystem.CreateStream(new StreamSpec("hello-stream")
8+
{
9+
MaxLengthBytes = 5_000_000_000
10+
});
11+
12+
var producer = await Producer.Create(new ProducerConfig(streamSystem, "hello-stream"));
13+
14+
15+
await producer.Send(new Message(Encoding.UTF8.GetBytes($"Hello, World")));
16+
Console.WriteLine(" [x] Sent 'Hello, World'");
17+
18+
Console.WriteLine(" [x] Press any key to exit");
19+
Console.ReadKey();
20+
await producer.Close();
21+
await streamSystem.Close();

dotnet-stream/dotnet-stream.sln

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Send", "Send\Send.csproj", "{C23444A1-BCB9-46A6-8D6D-7783C03E2A2E}"
4+
EndProject
5+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Receive", "Receive\Receive.csproj", "{37F1D7F4-58B1-4A1B-BE76-178A9D7A91E8}"
6+
EndProject
7+
Global
8+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
9+
Debug|Any CPU = Debug|Any CPU
10+
Release|Any CPU = Release|Any CPU
11+
EndGlobalSection
12+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
13+
{C23444A1-BCB9-46A6-8D6D-7783C03E2A2E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
14+
{C23444A1-BCB9-46A6-8D6D-7783C03E2A2E}.Debug|Any CPU.Build.0 = Debug|Any CPU
15+
{C23444A1-BCB9-46A6-8D6D-7783C03E2A2E}.Release|Any CPU.ActiveCfg = Release|Any CPU
16+
{C23444A1-BCB9-46A6-8D6D-7783C03E2A2E}.Release|Any CPU.Build.0 = Release|Any CPU
17+
{37F1D7F4-58B1-4A1B-BE76-178A9D7A91E8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
18+
{37F1D7F4-58B1-4A1B-BE76-178A9D7A91E8}.Debug|Any CPU.Build.0 = Debug|Any CPU
19+
{37F1D7F4-58B1-4A1B-BE76-178A9D7A91E8}.Release|Any CPU.ActiveCfg = Release|Any CPU
20+
{37F1D7F4-58B1-4A1B-BE76-178A9D7A91E8}.Release|Any CPU.Build.0 = Release|Any CPU
21+
EndGlobalSection
22+
EndGlobal

0 commit comments

Comments
 (0)