AugusteVN.Azure.ServiceBus
1.1.0
dotnet add package AugusteVN.Azure.ServiceBus --version 1.1.0
NuGet\Install-Package AugusteVN.Azure.ServiceBus -Version 1.1.0
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.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AugusteVN.Azure.ServiceBus" Version="1.1.0" />
<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.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: AugusteVN.Azure.ServiceBus, 1.1.0"
#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.
#addin nuget:?package=AugusteVN.Azure.ServiceBus&version=1.1.0
#tool nuget:?package=AugusteVN.Azure.ServiceBus&version=1.1.0
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>"
}
}
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>"
});
var receiver = new ReceiverClient(
new ServiceBusConfig {
ConnectionString = "<to-fill>"
});
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 method overload to construct your own 'ServiceBusMessage'.
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. |
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.
Add method to parse message metadata.