AugusteVN.Azure.ServiceBus
1.0.6
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package AugusteVN.Azure.ServiceBus --version 1.0.6
NuGet\Install-Package AugusteVN.Azure.ServiceBus -Version 1.0.6
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="AugusteVN.Azure.ServiceBus" Version="1.0.6" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AugusteVN.Azure.ServiceBus" Version="1.0.6" />
<PackageReference Include="AugusteVN.Azure.ServiceBus" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add AugusteVN.Azure.ServiceBus --version 1.0.6
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: AugusteVN.Azure.ServiceBus, 1.0.6"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package AugusteVN.Azure.ServiceBus@1.0.6
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=AugusteVN.Azure.ServiceBus&version=1.0.6
#tool nuget:?package=AugusteVN.Azure.ServiceBus&version=1.0.6
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Azure Service Bus
Publishing messages to- & receiving messages from the Azure Service Bus.
This package contains wrapper- & helper functions for the official Azure.Messaging.ServiceBus
NuGet package.
Contains:
SenderClient
to send a message to a topic.ReceiverClient
to receive messages from a topic subscription.
Configuration
appsettings.json
{
"ServiceBusConfig": {
"ConnectionString": "<to-fill>",
"QueueOrTopicNames": "<optional-fill-for-convenience>",
"SubscriptionNames": "<optional-for-convenience>"
}
}
Program.cs
builder.Services
.AddOptions<ServiceBusConfig>()
.BindConfiguration(nameof(ServiceBusConfig));
services.AddSingleton<ISenderClient, SenderClient>();
services.AddSingleton<IReceiverClient, ReceiverClient>();
// Or initialize an instance of either.
var sender = new SenderClient(
new ServiceBusConfig {
ConnectionString = "<to-fill>",
QueueOrTopicNames = null
});
var receiver = new ReceiverClient(
new ServiceBusConfig {
ConnectionString = "<to-fill>",
QueueOrTopicNames = null,
SubscriptionNames = null
});
Send Message
Program.cs
app.MapPost("/", async (ISenderClient sender) => {
var data = new { Foo = "bar" };
var customProperties = new Dictionary<string, object> {{ "foo", "bar" }};
await sender.SendAsync(
queueOrTopicName: "<to-fill>",
data,
customProperties);
// Or use the overload and construct your own 'ServiceBusMessage'.
// Set 'queueOrTopicName' if not set in appSettings.json.
await sender.SendAsync(
queueOrTopicName: "<to-fill>"
new ServiceBusMessage(body: data) {
CorrelationId = "",
ApplicationProperties = customProperties,
...
}
);
return Results.NoContent();
});
Receive Message
Program.cs
app.MapPost("/", async (IReceiverClient receiver) => {
var message = await receiver.ReceiveMessageAsync(
queueOrTopicName: "<to-fill>",
subscriptionName: null,
maxWaitTime: TimeSpan.FromMinutes(5));
if (message != null) {
await receiver.CompleteMessageAsync(
message,
queueOrTopicName: "<to-fill>",
subscriptionName: null);
}
return Results.NoContent();
});
Receive Multiple Messages
Program.cs
app.MapPost("/", async (IReceiverClient receiver) => {
var messages = await receiver.ReceiveMessagesAsync(
queueOrTopicName: "<to-fill>",
subscriptionName: null,
maxMessages: 300,
maxWaitTime: TimeSpan.FromMinutes(5));
foreach(var message in messages) {
var isWantedMessage = message.ApplicationProperties["foo"]?.ToString() == "bar";
if (!isWantedMessage) continue;
var messageBody = receiver.ParseMessageBody<object>(message);
...
var isSuccess = await DoStuff(messageBody);
if (!isSuccess) continue;
await receiver.CompleteMessageAsync(
message,
queueOrTopicName: "<to-fill>",
subscriptionName: null);
}
return Results.NoContent();
});
To see it in action, watch: Azure Service Bus Messaging in C# .NET
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 was computed. 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 was computed. 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- Azure.Messaging.ServiceBus (>= 7.17.0)
- Microsoft.Extensions.Options (>= 8.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.
Remove method overloads to pass queue, topic and/or subscription names.