Outbox Quarkus Extension
Overview
This extension is inspired by the Outbox Event Router single message transformation (SMT). As discussed in the blog post Reliable Microservices Data Exchange with the Outbox Pattern, microservices often need to exchange information with one another and an excellent way to deal with that is using the Outbox pattern combined with Debezium’s Outbox Event Router SMT.
The following image shows the overall architecture of this pattern:
The Outbox extension’s goal is to provide a Quarkus application with a reusable, highly configurable component that facilitates the use of the Outbox pattern paired with Debezium’s CDC connector pipeline to reliably and asynchronously share data with any consumer of said data.
Getting Started
In order to start using the Debezium Outbox Quarkus extension, the extension needs to be added as a part of the Quarkus application as follows:
<dependency>
<groupId>io.debezium</groupId>
<artfiactId>debezium-quarkus-outbox</artfiactId>
<version>1.3.1.Final</version>
</dependency>
The extension provides the application with the io.debezium.outbox.quarkus.ExportedEvent
interface. It’s expected that an application class will implement this interface and that the event will be emitted using the javax.enterprise.event.Event
class.
The |
Example
The following illustrates an implementation of the ExportedEvent
interface representing an order that has been created:
OrderCreatedEvent.java
public class OrderCreatedEvent implements ExportedEvent<String, JsonNode> {
private static final String TYPE = "Order";
private static final String EVENT_TYPE = "OrderCreated";
private final long orderId;
private final JsonNode jsonNode;
private final Instant timestamp;
public OrderCreatedEvent(Instant createdAt, Order order) {
this.orderId = order.getId();
this.timestamp = createdAt;
this.jsonNode = convertToJson(order);
}
@Override
public String getAggregateId() {
return String.valeuOf(orderId);
}
@Override
public String getAggregateType() {
return TYPE;
}
@Override
public JsonNode getPayload() {
return jsonNode;
}
@Override
public String getType() {
return EVENT_TYPE;
}
@Override
public Instant getTimestamp() {
return timestamp;
}
}
The following example illustrates an OrderService
that emits the OrderCreatedEvent
:
OrderService.java
@ApplicationScoped
public class OrderService {
@Inject
Event<ExportedEvent<?, ?>> event;
@Transactional
public Order addOrder(Order order) {
order = orderRepository.save(order);
event.fire(new OrderCreatedEvent(Instant.now(), order));
return order;
}
}
When the application code fires the event by calling Event#fire()
, the Outbox extension will be notified that the event occurred and persists the contents of the event into an outbox event table within the scope of the current transaction. The Debezium CDC connector in conjunction with the Outbox Event Router will be monitoring this table and will be responsible for relaying that data using CDC events.
To see a full end-to-end demo, the Outbox example illustrates two Quarkus microservice applications using the outbox pattern to share data between them when orders are placed or cancelled.
Configuration
The Outbox extension can be configured by setting options in the Quarkus application.properties
file. The extension works out-of-the-box with a default configuration, but this configuration may not be ideal for every situation.
Build time configuration options
Configuration property | Type | Default |
| string | OutboxEvent |
| string |
|
| string |
|
| string |
|
| string |
|
| string | |
| string |
|
| string |
|
| string | |
| string |
|
| string |
|
| string | |
| string |
|
| string |
|
| string | |
| string |
|
| string |
|
| string |
The build time configuration defaults will work with the Outbox Event Router SMT out of the box. When not using the default values, be sure that the SMT configuration matches. |
Runtime configuration options
Configuration property | Type | Default |
| boolean | true |