Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions java/outbox.md
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,56 @@ You must ensure that the handler is completing the context, after executing the

[Learn more about event handlers.](./event-handlers/){.learn-more}

::: tip Customizing Outbox Entries

The outbox has no information regarding the structure and the data types that
shall be serialized and deserialized to and from the outbox.

As long as there are CDS modelled services used, no special handling is
required. Only if there are custom data types used or additional context
properties are required, special handling needs to be implemented to avoid
serialization and deserialization errors in custom outbox handlers:

::: code-group

```java [srv/src/main/java/com/myapp/CustomOutboxHandler.java]
@Component
@ServiceName(value = "*", type = OutboxService.class)
public class CustomOutboxHandler implements EventHandler {

@On
void publishedByOutbox(OutboxMessageEventContext context) {
// Restore custom values from context only
if (Boolean.FALSE.equals(context.getIsInbound())) {
return;
}

// custom deserialization logic
Long date = (Long) context.getMessage().getParams().get("orderDate");
context.getMessage().getParams().put("orderDate", Instant.ofEpochSecond(date));
}

@Before(event = "*")
void prepareOutboxMessage(OutboxMessageEventContext context) {
// prepare outbox message for storage only
if (Boolean.TRUE.equals(context.getIsInbound())) {
return;
}

// custom serialization logic
Instant date = (Instant) context.getMessage().getParams().get("orderDate");
context.getMessage().getParams().put("orderDate", new Long(date.getEpochSecond()));
}
}
```

:::

**Don't complete the context in any of those two handlers, otherwise other
handlers aren't called and functionality is broken.**

:::

## Handling Outbox Errors { #handling-outbox-errors }

The outbox by default retries publishing a message, if an error occurs during processing, until the message has reached the maximum number of attempts.
Expand Down
Loading