ServiceBus.AspNetCore.Rabbit
2.3.0
dotnet add package ServiceBus.AspNetCore.Rabbit --version 2.3.0
NuGet\Install-Package ServiceBus.AspNetCore.Rabbit -Version 2.3.0
<PackageReference Include="ServiceBus.AspNetCore.Rabbit" Version="2.3.0" />
<PackageVersion Include="ServiceBus.AspNetCore.Rabbit" Version="2.3.0" />
<PackageReference Include="ServiceBus.AspNetCore.Rabbit" />
paket add ServiceBus.AspNetCore.Rabbit --version 2.3.0
#r "nuget: ServiceBus.AspNetCore.Rabbit, 2.3.0"
#:package ServiceBus.AspNetCore.Rabbit@2.3.0
#addin nuget:?package=ServiceBus.AspNetCore.Rabbit&version=2.3.0
#tool nuget:?package=ServiceBus.AspNetCore.Rabbit&version=2.3.0
ServiceBus.AspNetCore.Rabbit 2.x
REST over the bus for ASP.NET Core: an application receives HTTP requests through RabbitMQ instead of through a socket. A client publishes the request on the bus, the host in your application takes it from the queue, runs it through the ASP.NET Core pipeline (your controllers, middleware and filters) and publishes the answer on the reply queue of the client.
This version works with ServiceBus.Core.Rabbit 3.x (RabbitMQ.Client 6.x) and declares it as [3.9.0, 4.0.0). With ServiceBus.Core.Rabbit 4.x use ServiceBus.AspNetCore.Rabbit 3.x.
dotnet add package ServiceBus.AspNetCore.Rabbit --version 2.*
Targets: net8.0, net9.0, net10.0. net6.0 is no longer a target: applications on it stay on the earlier releases (2.2.x).
The host
The host is a subscriber, RestHostSubscriberBound, registered as IRestHostSubscriber. UseSubscriberHost() starts it when the application has started and stops it when the application stops:
using ServiceBus.AspNetCore.Extensions;
using ServiceBus.AspNetCore.Subscribers;
// in the registration of the services: the host, as a singleton
services.AddSingleton<IRestHostSubscriber, RestHostSubscriberBound>();
var app = builder.Build();
app.UseRouting();
app.MapControllers();
app.UseSubscriberHost();
await app.RunAsync();
RestHostSubscriberBound takes a RestSubscriberBoundDescriptor (ServiceName, which names the exchange and the working queue, Durable, PrefetchCount, IncludeErrorDetails and ResponseRetryPolicy; its RetryPolicy and AutoAck are not used by the host: they are marked [Obsolete] and do not exist in 3.x, so delete them before upgrading), the channel (IModel), an IHttpRestMessageSerializer and an IMemoryStreamResolver, which you register next to it; the rest comes from ASP.NET Core. The demo ServiceBus.Ms.Demo.Net10 in the repository shows a complete setup.
If the broker is not there when the application starts, the application starts anyway and keeps answering HTTP: the host logs a critical entry (it does not consume the requests that come from the bus) and nothing else. The application has to be restarted to start consuming. A connection that is lost after a successful start is recovered by the client library.
Running requests together
The host runs one request at a time, whatever the prefetch, because the client library delivers the messages of a channel one at a time. To have them run together set both on the connection and on the descriptor:
new ConnectionFactory { /* ... */ ConsumerDispatchConcurrency = 5 }; // the library delivers up to 5 at once
new RestSubscriberBoundDescriptor { /* ... */ PrefetchCount = 5 }; // and the broker sends that many
With both, five requests of 400 ms take about 400 ms instead of two seconds. The code of your controllers then runs concurrently, as on any web server. (ServiceBus.AspNetCore.Rabbit 3.x, for RabbitMQ.Client 7, needs only the prefetch.) When the application stops, the host stops taking requests and waits (up to 30 seconds) for the ones it has already taken, so they are answered.
The clients
The clients that talk to the host are in ServiceBus.Core.Rabbit:
FullDuplexRestPublisherBoundpublishes the request and waits for the answer on a reply queue, with a timeout;StatelessRestPublisherBoundpublishes the request and returns at once, with a default response: it only says "published".
var request = new RestRequest("api/orders/42") { Method = HttpMethods.Get };
var response = await client.SendAsync<Order>(request);
What the host answers
- A request goes through the pipeline and the answer is published with the same correlation id; the message is acknowledged. An exception of the application is a
500with a genericproblem+json: the message and the stack trace stay in the log of the host, so whoever can publish on the bus does not learn how your application is made. To get them in the answer (while you develop), setIncludeErrorDetails = truein theRestSubscriberBoundDescriptor, with the condition you use for your own environments. - If the answer cannot be published the host sends it again (
ResponseRetryPolicy, three attempts by default); if it still fails the error is logged and the request is acknowledged: it is never redelivered, because it would run twice. The caller gets no answer and waits until its timeout. - A request with a verb the SDK does not know (
OPTIONS,TRACE, ...) is answered501 Not Implementedand acknowledged; the application never sees it. The SDK knowsGET,POST,PUT,DELETE,HEADandPATCH. Before this version such a request was run as aGET. - A message that the serializer cannot read is rejected without requeue and reported to
OnException, with no answer: the caller waits until its timeout.
See the documentation.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- ServiceBus.Core.Rabbit (>= 3.9.0 && < 4.0.0)
-
net8.0
- ServiceBus.Core.Rabbit (>= 3.9.0 && < 4.0.0)
-
net9.0
- ServiceBus.Core.Rabbit (>= 3.9.0 && < 4.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2.3.0 | 66 | 11/20/2026 |
| 2.2.3 | 246 | 1/22/2026 |
| 2.2.2 | 393 | 3/7/2025 |
| 2.2.1 | 328 | 3/6/2025 |
| 2.1.1 | 241 | 10/16/2024 |
| 2.1.0 | 222 | 10/2/2024 |
| 1.0.7 | 1,115 | 9/22/2021 |
| 1.0.6 | 532 | 8/25/2021 |
| 1.0.5 | 659 | 2/8/2021 |
| 1.0.4 | 556 | 2/4/2021 |
| 1.0.3 | 563 | 1/23/2021 |
| 1.0.2 | 671 | 8/20/2020 |
| 1.0.1 | 696 | 7/25/2020 |
| 1.0.1-beta | 991 | 7/22/2020 |