-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #198 from cemremengu/2.0
Added starter documentation for publish and consume operations
- Loading branch information
Showing
2 changed files
with
58 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,24 @@ | ||
# Publish | ||
|
||
Bah | ||
It just isn’t feasible to have a multi-line, complex expression just to perform a simple publish (or any other operation for that matter). | ||
This is where extension methods come to the rescue. It turns out that it is dead simple to create a publish signature that very much resembles the 1.x way of doing things. | ||
|
||
First get the `Publish` operation package to enrich the BusClient with Publishing capabilities | ||
|
||
```nuget | ||
PM> Install-Package RawRabbit.Operations.Publish | ||
``` | ||
|
||
then you can | ||
|
||
```csharp | ||
|
||
var message = new BasicMessage { Prop = "Hello, world!" }; | ||
|
||
await publisher.PublishAsync(message, ctx => ctx | ||
.UsePublisherConfiguration(cfg => cfg | ||
.OnExchange("custom_exchange") | ||
.WithRoutingKey("custom_key") | ||
)); | ||
``` |
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 +1,36 @@ | ||
# Subscribe | ||
# Subscribe | ||
|
||
The extension methods again come to the rescue! Subscriptions again very much resembles the 1.x way of doing things with a cleaner separation of concerns. | ||
|
||
## BasicConsume | ||
|
||
First get the `Subscribe` operation package to enrich the BusClient with subscription/consuming capabilities | ||
|
||
```nuget | ||
PM> Install-Package RawRabbit.Operations.Subscribe | ||
``` | ||
|
||
then you can | ||
|
||
```csharp | ||
|
||
await _rabbitBus.BasicConsumeAsync(async args => | ||
{ | ||
await | ||
Task.Run(() => MyTask()); | ||
|
||
return new Ack(); | ||
|
||
}, ctx => ctx | ||
.UseConsumerConfiguration(cfg => cfg | ||
.Consume(c => c | ||
.WithRoutingKey("custom_routing_key") | ||
.OnExchange("custom_exchange") | ||
.WithPrefetchCount(100) | ||
) | ||
.FromDeclaredQueue(q => q | ||
.WithName("custom_queue_name") | ||
)) | ||
); | ||
``` |