Stream

The Devprime platform simplifies seamless integration with leading streaming services such as Kafka, RabbitMQ, Google GCP, AWS SQS, and Azure Service Bus, allowing changes without the need to modify a single line of code. In addition, it supports distributed systems strategies such as retry, circuit break, and resiliency.

The Stream Adapter organizes the emission and receipt of events on the Devprime platform following a standard Devprime protocol and also enables the receipt of generic events sent by other applications.

Sending RabbitMQ/Kafka and other platforms events
“The Devprime platform provides a standardized approach to emitting events using the Stream Adapter and the Dp.Stream.Send(destination, eventName, eventData) method. This method is independent of the technology used, even allowing switching between streaming services, such as RabbitMQ, Kafka, and other platforms.

In the example below, a DTO OrderCreatedEventDTO is populated with the payload to be passed in the event, and then the Dp.Stream.Send(destination, eventName, eventData) method is executed.

The ‘destination’ parameter represents the queue, topic, or exchange; ‘eventName’ is the name of the event; and ‘eventData’ represents the content to be streamed.”

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
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;
    }
}

Event Hub in Stream Adapter for Queues/Topics

Receiving events through queues or topics is a simple and transparent process through the Stream adapter. This process works regardless of the Stream technology adopted, be it RabbitMQ, Kafka, or any other service. After receiving the event, Stream directs it to Application Services, which in turn forwards it to Domain. The latter is solely responsible for processing the business rule.

In this way, the Devprime platform ensures that the flow of events is conducted efficiently and coherently, ensuring the integrity of operations and maintaining clarity in the execution of business rules.

In the example below, the Payment microservice is receiving the “OrderCreated” event and then passing the processing to the “Application Service” paymentService.

Standard events between applications based on the Devprime platform are handled in a standardized way, as shown in the example below ‘OrderCreated’.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
public class EventStream : EventStreamBase, IEventStream
{
    public override void StreamEvents()
    {
        Subscribe<IPaymentService,
         OrderCreatedEventDTO>("Stream1", "OrderCreated",
         (dto, paymentService, Dp) =>

        {
            var command = new Payment()
            {
                CustomerName = dto.CustomerName,
                OrderID = dto.OrderID,
                Value = dto.Value
            };
            paymentService.Add(command);
        });
    }
}

Automatic Protocol on Event Events
The Stream Adapter uses a standard protocol for sending events, which manages information such as version, traceability, identification parameters, creation date, and payload. This information is visible in the queues or threads of the streaming tools and transparent to developers. Internally, they receive standardized, typed events in the Devprime platform.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
{"Headers":{"trace-id":"6a61dd3e4296ba544e9eb7f1dec3ebab:ef6501c0445a44e5"},
"Id":"e3d69575-aaac-4f20-92b9-b8e413ba5b38",
"CorrelationId":"99f3b318-c8f5-4dc7-85a3-297146855015",
"TraceId":"99f3b318-c8f5-4dc7-85a3-297146855015",
"AppId":"8be817a8-0dfc-41be-b9aa-607311ffe9fb",
"AppName":"ms-order", "TenantID":"","TenantUserID":"",
"Version":1,"Name":"OrderCreated",
"CreationDate":"2023-09-01T12:40:24.2028489-03:00",
"Payload":{"ID":"62d3e0a6-7bdf-4b40-ab13-fce02f90f392",
"CustomerName":"Ramon","CustomerTaxID":"string","Total":0}}

Subscribing to an event

The Devprime platform offers a CLI that boosts software developer productivity at every stage and provides the “dp add subscribe” command, which streamlines the implementation of a new Subscribe in the Stream Event Hub.

Last modified October 17, 2023 (e38ae05b)