Publishing events to queues and exchanges

The Devprime platform natively supports RabbitMQ, an open-source messaging software that operates on the basis of Advanced Message Queuing Protocol (AMQP). You can use automatic integration to send events on the RabbitMQ exchange and queues.

Using the Send/Publish Command on the Stream Adapter

The Devprime platform, through the Stream adapter, offers a common approach using the Publish/Send commands, as demonstrated below. This approach provides a consistent event publishing experience across all messaging and event platforms supported by DevPrime. This allows the implementation of an event-driven architecture from start to finish, using cloud native strategies, so that the exchange of streams can be done simply by changing the settings.

In the example below, implemented in the Application layer and within the EventHandler OrderCreatedEventHandler, it is possible to observe the use of the Send / Publish command with the following parameters:

Parameter Description
Destination Queue Name/Topic/Exchange
Event Name of the event issued by the DevPrime platform
Date Event Content
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
namespace Application.EventHandlers.Order;
public class OrderCreatedEventHandler : EventHandler<OrderCreated, IOrderState>
{
    public OrderCreatedEventHandler(IOrderState state, IDp dp) : base(state, dp)
    {
    }
    public override dynamic Handle(OrderCreated orderCreated)
    {
        var success = false;
        var order = orderCreated.Get<Domain.Aggregates.Order.Order>();
        var destination = Dp.Settings.Default("stream.orderevents");
        var eventName = "OrderCreated";
        var eventData = new OrderCreatedEventDTO()
        {
            ID = order.ID,
            CustomerName = order.CustomerName,
            CustomerTaxID = order.CustomerTaxID,
            Total = order.Total
        };
        Dp.Stream.Send(destination, eventName, eventData);
        success = true;
        return success;
    }
}

This method offers multiple overloads, allowing for a wide range of customizations. It also supports passing a different Stream “Alias”, useful in scenarios where you have more than one Stream platform linked to the same microservice.

Example:

1
Dp.Stream.Send("Stream2", destination, eventName, eventData);
Last modified September 10, 2024 (6166aa4f)