Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated the default behaviour of the messaging error handler #1369

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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
38 changes: 38 additions & 0 deletions java/messaging.md
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,44 @@ private void handleError(MessagingErrorEventContext ctx) {
}
```

In the multitenant application, there may be race conditions in the subscription process. In this case, the message cannot be processed for the tenant because the tenant context is not available. In this case, the standard error handler acknowledges the message to prevent it from getting stuck in the message sequence. To change this behavior, the custom error handler from the example above can be extended by checking the exception type of the unknown tenant.


```java
@On(service = "messaging")
private void handleError(MessagingErrorEventContext ctx) {

String errorCode = ctx.getException().getErrorStatus().getCodeString();
if (errorCode.equals(CdsErrorStatuses.NO_ON_HANDLER.getCodeString()) ||
errorCode.equals(CdsErrorStatuses.INVALID_DATA_FORMAT.getCodeString())) {
// error handling for infrastructure error
ctx.setResult(false); // no acknowledgement

} else if (errorCode.equals(CdsErrorStatuses.TENANT_NOT_EXISTS.getCodeString())) {
// error handling for unknown tenant context

// tenant of the received message
String tenant = ctx.getTenant();

// receieved message
Map<String, Object> headers = ctx.getMessageHeaders();
Map<String, Object> message = ctx.getMessageData();

ctx.setResult(true); // acknowledge
} else {
// error handling for application errors

// how to access the event context of the raised exception:
// ctx.getException().getEventContexts().stream().findFirst().ifPresent(e -> {
// String event = e.getEvent());
// String payload = e.get("data"));
// });

ctx.setResult(true); // acknowledge
}
}
```

::: warning _❗ Warning_
The way how unsuccessfully delivered messages are treated, fully depends on the messaging broker. Please check in section [Acknowledgement Support](#acknowledgement-support) whether the messaging broker you are using is suitable for your error handler implementation.
:::
Expand Down