-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
37f9e95
commit 2882bc7
Showing
7 changed files
with
156 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 11 additions & 18 deletions
29
docs/examples/RabbitMQ.Next.Examples.DemoSaslAuthMechanism/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,17 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using RabbitMQ.Next; | ||
using RabbitMQ.Next.Examples.DemoSaslAuthMechanism; | ||
|
||
namespace RabbitMQ.Next.Examples.DemoSaslAuthMechanism; | ||
Console.WriteLine("Hello World! Will try to connect RabbitMQ server with RABBIT-CR-DEMO auth mechanism."); | ||
|
||
internal static class Program | ||
{ | ||
private static async Task Main() | ||
{ | ||
Console.WriteLine("Hello World! Will try to connect RabbitMQ server with RABBIT-CR-DEMO auth mechanism."); | ||
await using var connection = ConnectionBuilder.Default | ||
.Endpoint("amqp://localhost:5672/") | ||
.WithRabbitCrDemoAuth("guest", "guest") | ||
.Build(); | ||
|
||
await using var connection = ConnectionBuilder.Default | ||
.Endpoint("amqp://localhost:5672/") | ||
.WithRabbitCrDemoAuth("guest", "guest") | ||
.Build(); | ||
await connection.OpenAsync().ConfigureAwait(false); | ||
|
||
await connection.OpenAsync().ConfigureAwait(false); | ||
Console.WriteLine("Connection opened"); | ||
Console.WriteLine("Press any key to close the connection"); | ||
|
||
Console.WriteLine("Connection opened"); | ||
Console.WriteLine("Press any key to close the connection"); | ||
|
||
Console.ReadKey(); | ||
} | ||
} | ||
Console.ReadKey(); |
37 changes: 37 additions & 0 deletions
37
docs/examples/RabbitMQ.Next.Examples.PublisherMiddleware/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using RabbitMQ.Next; | ||
using RabbitMQ.Next.Publisher; | ||
using RabbitMQ.Next.Serialization.PlainText; | ||
|
||
Console.WriteLine("Hello World! This is publisher based on RabbitMQ.Next library."); | ||
|
||
var connection = ConnectionBuilder.Default | ||
.Endpoint("amqp://guest:guest@localhost:5672/") | ||
.UsePlainTextSerializer() | ||
.Build(); | ||
|
||
await using var publisher = connection.Publisher("amq.fanout", | ||
builder => builder.UsePublishMiddleware((message, content) => | ||
{ | ||
message.SetType(message.ClrType.Name); | ||
})); | ||
|
||
Console.WriteLine("Publisher created. Type any text to send it to the 'amq.fanout' exchange. Enter empty string to exit"); | ||
|
||
while(true) | ||
{ | ||
var input = Console.ReadLine(); | ||
if (string.IsNullOrEmpty(input)) | ||
{ | ||
break; | ||
} | ||
|
||
try | ||
{ | ||
await publisher.PublishAsync(input).ConfigureAwait(false); | ||
} | ||
catch (Exception e) | ||
{ | ||
Console.WriteLine(e); | ||
throw; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...bitMQ.Next.Examples.PublisherMiddleware/RabbitMQ.Next.Examples.PublisherMiddleware.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\..\src\RabbitMQ.Next.Publisher\RabbitMQ.Next.Publisher.csproj" /> | ||
<ProjectReference Include="..\..\..\src\RabbitMQ.Next.Serialization.PlainText\RabbitMQ.Next.Serialization.PlainText.csproj" /> | ||
<ProjectReference Include="..\..\..\src\RabbitMQ.Next\RabbitMQ.Next.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
67 changes: 30 additions & 37 deletions
67
docs/examples/RabbitMQ.Next.Examples.SimpleConsumer/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,51 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using RabbitMQ.Next; | ||
using RabbitMQ.Next.Consumer; | ||
using RabbitMQ.Next.Serialization.PlainText; | ||
|
||
namespace RabbitMQ.Next.Examples.SimpleConsumer; | ||
|
||
internal static class Program | ||
{ | ||
private static async Task Main() | ||
{ | ||
Console.WriteLine("Hello World! This is consumer based on RabbitMQ.Next library."); | ||
Console.WriteLine("Hello World! This is consumer based on RabbitMQ.Next library."); | ||
|
||
var connection = ConnectionBuilder.Default | ||
.Endpoint("amqp://guest:guest@localhost:5672/") | ||
.UsePlainTextSerializer() | ||
.Build(); | ||
var connection = ConnectionBuilder.Default | ||
.Endpoint("amqp://guest:guest@localhost:5672/") | ||
.UsePlainTextSerializer() | ||
.Build(); | ||
|
||
Console.WriteLine("Connection opened"); | ||
await using var consumer = connection.Consumer( | ||
builder => builder | ||
.BindToQueue("my-queue") | ||
.PrefetchCount(10)); | ||
|
||
await using var consumer = connection.Consumer( | ||
builder => builder | ||
.BindToQueue("my-queue") | ||
.PrefetchCount(10)); | ||
Console.WriteLine("Consumer created. Press Ctrl+C to exit."); | ||
|
||
Console.WriteLine("Consumer created. Press Ctrl+C to exit."); | ||
using var cancellation = new CancellationTokenSource(); | ||
|
||
using var cancellation = new CancellationTokenSource(); | ||
MonitorKeypressAsync(cancellation); | ||
Check warning on line 25 in docs/examples/RabbitMQ.Next.Examples.SimpleConsumer/Program.cs GitHub Actions / build
Check warning on line 25 in docs/examples/RabbitMQ.Next.Examples.SimpleConsumer/Program.cs GitHub Actions / build
|
||
|
||
MonitorKeypressAsync(cancellation); | ||
await consumer.ConsumeAsync((message, content) => | ||
{ | ||
Console.WriteLine($"[{DateTimeOffset.Now.TimeOfDay}] Message received via '{message.Exchange}' exchange: {content.Get<string>()}"); | ||
} ,cancellation.Token); | ||
|
||
await consumer.ConsumeAsync((message, content) => | ||
{ | ||
Console.WriteLine($"[{DateTimeOffset.Now.TimeOfDay}] Message received via '{message.Exchange}' exchange: {content.Get<string>()}"); | ||
} ,cancellation.Token); | ||
} | ||
|
||
private static Task MonitorKeypressAsync(CancellationTokenSource cancellation) | ||
|
||
static Task MonitorKeypressAsync(CancellationTokenSource cancellation) | ||
{ | ||
void WaitForInput() | ||
{ | ||
void WaitForInput() | ||
ConsoleKeyInfo key; | ||
do | ||
{ | ||
ConsoleKeyInfo key; | ||
do | ||
{ | ||
key = Console.ReadKey(true); | ||
key = Console.ReadKey(true); | ||
|
||
} while (key.Key != ConsoleKey.C && key.Modifiers != ConsoleModifiers.Control); | ||
} while (key.Key != ConsoleKey.C && key.Modifiers != ConsoleModifiers.Control); | ||
|
||
if (!cancellation.IsCancellationRequested) | ||
{ | ||
cancellation.Cancel(); | ||
} | ||
if (!cancellation.IsCancellationRequested) | ||
{ | ||
cancellation.Cancel(); | ||
} | ||
|
||
return Task.Run(WaitForInput); | ||
} | ||
|
||
return Task.Run(WaitForInput); | ||
} |
67 changes: 23 additions & 44 deletions
67
docs/examples/RabbitMQ.Next.Examples.SimplePublisher/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,34 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using System.Threading.Tasks; | ||
|
||
using RabbitMQ.Next; | ||
using RabbitMQ.Next.Publisher; | ||
using RabbitMQ.Next.Serialization.PlainText; | ||
|
||
namespace RabbitMQ.Next.Examples.SimplePublisher; | ||
|
||
internal static class Program | ||
{ | ||
private static async Task Main() | ||
{ | ||
Console.WriteLine("Hello World! This is publisher based on RabbitMQ.Next library."); | ||
|
||
var connection = ConnectionBuilder.Default | ||
.Endpoint("amqp://guest:guest@localhost:5672/") | ||
.UsePlainTextSerializer() | ||
.Build(); | ||
Console.WriteLine("Hello World! This is publisher based on RabbitMQ.Next library."); | ||
|
||
Console.WriteLine("Connection opened"); | ||
var connection = ConnectionBuilder.Default | ||
.Endpoint("amqp://guest:guest@localhost:5672/") | ||
.UsePlainTextSerializer() | ||
.Build(); | ||
|
||
await using var publisher = connection.Publisher("amq.fanout", | ||
builder => builder.UsePublishMiddleware(async (message, content, next) => | ||
{ | ||
var ts = Stopwatch.GetTimestamp(); | ||
await next(message, content); | ||
Console.WriteLine(Stopwatch.GetTimestamp() - ts); | ||
}).UsePublishMiddleware((message, content) => | ||
{ | ||
message.SetType(message.ClrType.Name); | ||
})); | ||
await using var publisher = connection.Publisher("amq.fanout"); | ||
|
||
Console.WriteLine("Publisher created. Type any text to send it to the 'amq.fanout' exchange. Enter empty string to exit"); | ||
Console.WriteLine("Publisher created. Type any text to send it to the 'amq.fanout' exchange. Enter empty string to exit"); | ||
|
||
while(true) | ||
{ | ||
var input = Console.ReadLine(); | ||
if (string.IsNullOrEmpty(input)) | ||
{ | ||
break; | ||
} | ||
while(true) | ||
{ | ||
var input = Console.ReadLine(); | ||
if (string.IsNullOrEmpty(input)) | ||
{ | ||
break; | ||
} | ||
|
||
try | ||
{ | ||
await publisher.PublishAsync(input).ConfigureAwait(false); | ||
} | ||
catch (Exception e) | ||
{ | ||
Console.WriteLine(e); | ||
throw; | ||
} | ||
} | ||
try | ||
{ | ||
await publisher.PublishAsync(input).ConfigureAwait(false); | ||
} | ||
catch (Exception e) | ||
{ | ||
Console.WriteLine(e); | ||
throw; | ||
} | ||
} |
85 changes: 32 additions & 53 deletions
85
docs/examples/RabbitMQ.Next.Examples.TopologyBuilder/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,38 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using RabbitMQ.Next; | ||
using RabbitMQ.Next.TopologyBuilder; | ||
|
||
Console.WriteLine("Hello World! This is topology builder based on RabbitMQ.Next library."); | ||
|
||
namespace RabbitMQ.Next.Examples.TopologyBuilder; | ||
var connection = ConnectionBuilder.Default | ||
.Endpoint("amqp://guest:guest@localhost:5672/") | ||
.Build(); | ||
|
||
internal static class Program | ||
await connection.ConfigureAsync(async topology => | ||
{ | ||
private static async Task Main() | ||
{ | ||
try | ||
{ | ||
Console.WriteLine("Hello World! This is topology builder based on RabbitMQ.Next library."); | ||
|
||
var connection = ConnectionBuilder.Default | ||
.Endpoint("amqp://guest:guest@localhost:5672/") | ||
.Build(); | ||
|
||
Console.WriteLine("Connection opened"); | ||
|
||
await connection.ConfigureAsync(async topology => | ||
{ | ||
await topology.Exchange.DeclareAsync("my-exchange", ExchangeType.Topic); | ||
Console.WriteLine("'my-exchange' was created with using library defaults (durable by default)"); | ||
|
||
await topology.Exchange.DeclareAsync("my-advanced-exchange", ExchangeType.Topic, | ||
builder => builder | ||
.AutoDelete()); | ||
Console.WriteLine("'my-advanced-exchange' was created by explicitly configuring to be auto-delete"); | ||
|
||
Console.WriteLine("--------------------------------------------------------------"); | ||
|
||
await topology.Queue.DeclareQuorumAsync("my-queue"); | ||
Console.WriteLine("Declare quorum queue named 'my-queue'"); | ||
|
||
await topology.Queue.DeclareClassicAsync("my-advanced-queue", | ||
builder => builder | ||
.AutoDelete() | ||
.MaxLength(1000)); | ||
Console.WriteLine("'my-advanced-queue' was created by explicitly configuring to be auto-delete and max-length 1000"); | ||
|
||
Console.WriteLine("--------------------------------------------------------------"); | ||
|
||
await topology.Queue.BindAsync("my-queue", "amq.fanout"); | ||
await topology.Queue.BindAsync("my-queue", "my-exchange", "cat"); | ||
await topology.Queue.BindAsync("my-queue", "my-exchange", "dog"); | ||
Console.WriteLine("my-queue was bound to my-exchange by 2 bindings."); | ||
}); | ||
|
||
await connection.DisposeAsync(); | ||
} | ||
catch (Exception e) | ||
{ | ||
Console.WriteLine(e); | ||
throw; | ||
} | ||
} | ||
} | ||
await topology.Exchange.DeclareAsync("my-exchange", ExchangeType.Topic); | ||
Console.WriteLine("'my-exchange' was created with using library defaults (durable by default)"); | ||
|
||
await topology.Exchange.DeclareAsync("my-advanced-exchange", ExchangeType.Topic, | ||
builder => builder | ||
.AutoDelete()); | ||
Console.WriteLine("'my-advanced-exchange' was created by explicitly configuring to be auto-delete"); | ||
|
||
Console.WriteLine("--------------------------------------------------------------"); | ||
|
||
await topology.Queue.DeclareQuorumAsync("my-queue"); | ||
Console.WriteLine("Declare quorum queue named 'my-queue'"); | ||
|
||
await topology.Queue.DeclareClassicAsync("my-advanced-queue", | ||
builder => builder | ||
.AutoDelete() | ||
.MaxLength(1000)); | ||
Console.WriteLine("'my-advanced-queue' was created by explicitly configuring to be auto-delete and max-length 1000"); | ||
|
||
Console.WriteLine("--------------------------------------------------------------"); | ||
|
||
await topology.Queue.BindAsync("my-queue", "amq.fanout"); | ||
await topology.Queue.BindAsync("my-queue", "my-exchange", "cat"); | ||
await topology.Queue.BindAsync("my-queue", "my-exchange", "dog"); | ||
Console.WriteLine("my-queue was bound to my-exchange by 2 bindings."); | ||
}); |