DeftFlux.Azure.ServiceBus.Manager
1.0.0.15
dotnet add package DeftFlux.Azure.ServiceBus.Manager --version 1.0.0.15
NuGet\Install-Package DeftFlux.Azure.ServiceBus.Manager -Version 1.0.0.15
<PackageReference Include="DeftFlux.Azure.ServiceBus.Manager" Version="1.0.0.15" />
<PackageVersion Include="DeftFlux.Azure.ServiceBus.Manager" Version="1.0.0.15" />
<PackageReference Include="DeftFlux.Azure.ServiceBus.Manager" />
paket add DeftFlux.Azure.ServiceBus.Manager --version 1.0.0.15
#r "nuget: DeftFlux.Azure.ServiceBus.Manager, 1.0.0.15"
#:package DeftFlux.Azure.ServiceBus.Manager@1.0.0.15
#addin nuget:?package=DeftFlux.Azure.ServiceBus.Manager&version=1.0.0.15
#tool nuget:?package=DeftFlux.Azure.ServiceBus.Manager&version=1.0.0.15
DeftFlux Azure Service Bus Manager
Project Description
DeftFlux Azure Service Bus Manager is a .NET library that simplifies working with Azure Service Bus topics and messages. It provides a structured approach to creating, managing, and processing Service Bus messages with built-in serialization, validation, and type safety features.
The library offers:
- Type-safe message handling through generic base classes
- Built-in JSON serialization/deserialization for Service Bus messages
- Validation support using data annotations
- Easy dependency injection setup for .NET applications
- Extensible architecture for custom topic implementations
Features
- 🚀 Simple Setup: Easy integration with .NET dependency injection
- 🔒 Type Safety: Generic constraints ensure compile-time type safety
- 📝 Validation: Built-in support for data annotation validation
- 🔄 Serialization: Automatic JSON serialization/deserialization
- 🎯 Extensible: Easy to extend with custom topic classes
- 📦 Lightweight: Minimal dependencies and overhead
Installation
Add the package reference to your project:
<PackageReference Include="DeftFlux.Azure.ServiceBus.Manager" Version="1.0.0" />
Setup in Program.cs
To set up the Service Bus Manager as a service in your application, add the following configuration to your Program.cs:
using DeftFlux.Azure.ServiceBus.Manager.Services;
using DeftFlux.Azure.ServiceBus.Manager.Services.Interfaces;
var builder = WebApplication.CreateBuilder(args);
// pull settings for section "ServiceBusSettings" from configuration and set to ServiceBusSettings object variable
var settings = builder.Configuration.GetSection("ServiceBusSettings").Get<ServiceBusSettings>();
builder.Services.AddSingleton<IConfiguration>(builder.Configuration);
// Add Azure Service Bus Manager
builder.Services.AddServiceBusServiceScoped<ExampleTopicObject>(settings);
var app = builder.Build();
app.Run();
You'll also need to add your Azure Service Bus connection string to your appsettings.json:
{
"ServiceBusSettings": {
"ServiceBusConnectionString": "Endpoint=sb://blablabla;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=SAS_KEY_VALUE;",
"SubscriptionName": "SubscriptionName",
"AutoComplete": true,
"StartOnRegister": true,
"MaxConcurrentCalls": 1
}
}
Creating Custom Topic Classes
To define your own custom topic classes, inherit from the TopicBase<T> abstract class. This base class provides JSON serialization/deserialization functionality through the ITopic<T> interface.
Example Custom Topic
Here's how to create a custom topic class:
using System.ComponentModel.DataAnnotations;
using System.Text.Json.Serialization;
using DeftFlux.Azure.ServiceBus.Manager.Topics;
public class OrderTopic : TopicBase<OrderTopic>
{
[Required]
public int OrderId { get; set; }
[Required]
[StringLength(100, MinimumLength = 1)]
public string CustomerName { get; set; } = string.Empty;
[Required]
[Range(0.01, double.MaxValue)]
public decimal TotalAmount { get; set; }
[JsonIgnore]
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
public bool IsValid()
{
var context = new ValidationContext(this);
return Validator.TryValidateObject(this, context, null, true);
}
}
Key Features of TopicBase<T>
The TopicBase<T> class provides:
- JSON Serialization:
ToJson()method to convert your topic to JSON string - JSON Deserialization:
FromJson(string json)method to create topic instances from JSON - Type Safety: Generic constraint ensures type safety during serialization/deserialization
Usage Example
// Create a new topic instance
var orderTopic = new OrderTopic
{
OrderId = 123,
CustomerName = "John Doe",
TotalAmount = 99.99m
};
// Serialize to JSON
string json = orderTopic.ToJson();
// Deserialize from JSON
var deserializedOrder = new OrderTopic().FromJson(json);
Best Practices
- Validation: Implement validation using data annotations and the
IsValid()method - Required Fields: Use
[Required]attribute for mandatory properties - JSON Ignore: Use
[JsonIgnore]for properties that shouldn't be serialized - Naming: Use descriptive names that reflect the message content
- Versioning: Consider versioning strategies for topic evolution
Requirements
- .NET 6.0 or higher
- Azure Service Bus namespace
- Valid Azure Service Bus connection string
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
For questions and support, please open an issue in the GitHub repository.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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 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. |
-
net9.0
- Azure.Messaging.ServiceBus (>= 7.19.0)
- Microsoft.Extensions.Configuration.Abstractions (>= 9.0.5)
- Microsoft.Extensions.Logging (>= 9.0.5)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.