HMIS.Base.MessageQueueMassTransit 1.0.2

HMIS.Base.MessageQueueMassTransit

A Package for Message Queue for the HMIS solution that will be used across all modules.
This package is built on MassTransit and RabbitMQ, providing a consistent way to publish and consume messages in your APIs and class libraries.


Installation

Add Internal NuGet Package Source with the next steps:

  • Open Visual Studio.
  • Go to Tools > Options.
  • Select NuGet Package Manager > Package Sources.
  • Click the + button to add a new package source.
  • Set the Name to e.g. HMIS and the Source to https://baget.ahbsdev.com/v3/index.json.
  • After that, click OK to save the changes.
  • Then, you can install the package via the .NET CLI:
dotnet add package HMIS.Base.MessageQueueMassTransit --source https://baget.ahbsdev.com/v3/index.json

Or via the NuGet Package Manager:

  • Open the NuGet Package Manager in Visual Studio.
  • Package Manager Console:
    Install-Package HMIS.Base.MessageQueueMassTransit -Source https://baget.ahbsdev.com/v3/index.json
    

Or via the NuGet Package Manager UI:

  • Open the NuGet Package Manager in Visual Studio.
  • Select the HMIS package source from the dropdown.
  • Search for HMIS.Base.MessageQueueMassTransit.
  • Click Install to add the package to your project.

Configuration in API Projects

This package is designed for ASP.NET Core Web APIs or class libraries.

You only need to register the package once in your Program.cs. Do not call AddMassTransit() manually � the package handles all configuration internally, including:

- RabbitMQ host setup
- Consumers registration
- Retry policy
- Delayed redelivery
- Circuit breaker
- - DI-aware in-memory outbox

Publisher API Setup

In your Program.cs:

builder.Services.AddMessageBroker(new MessageBrokerOptions
{
    RabbitMQUrl = "localhost",
    RabbitMQUser = "guest",
    RabbitMQPassword = "guest",
    RabbitMQVirtualHost = "/"
});

Using the publisher in a service:

public class MessagePublisherService
{
    private readonly IPublishEndpoint _publishEndpoint;

    public MessagePublisherService(IPublishEndpoint publishEndpoint)
    {
        _publishEndpoint = publishEndpoint;
    }

    public async Task PublishTestMessage()
    {
        await _publishEndpoint.Publish(new TestMessage
        {
            Text = "Hello from API",
            SentAt = DateTime.UtcNow
        });
    }
}
  • Inject MessagePublisherService into your controllers or background services.
  • Call PublishTestMessage() whenever you want to send a message.

Subscriber API Setup

In your Program.cs:

builder.Services.AddMessageBroker(new MessageBrokerOptions
{
    RabbitMQUrl = "localhost",
    RabbitMQUser = "guest",
    RabbitMQPassword = "guest",
    RabbitMQVirtualHost = "/"
});

Creating a consumer:

using MassTransit;
using MessageQueueDemo.Shared.Models;

public class TestMessageConsumer : IConsumer<TestMessage>
{
    public async Task Consume(ConsumeContext<TestMessage> context)
    {
        var message = context.Message;
        Console.WriteLine($"Received message: {message.Text} at {message.SentAt}");
        await Task.CompletedTask;
    }
}
  • MassTransit automatically registers all consumers via AddConsumers() in the package.
  • When a message is published, it will automatically be delivered to the correct consumer.

No packages depend on HMIS.Base.MessageQueueMassTransit.

Version Downloads Last updated
1.0.2 23 11/13/2025
1.0.1 17 11/10/2025