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

Event hub java docs #1658

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
14 changes: 13 additions & 1 deletion guides/messaging/event-broker.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@ The following guide is based on a productive (paid) account on SAP BTP.
This guide describes the end-to-end process of developing a stand-alone (or "single tenant") CAP application that consumes messages via SAP Cloud Application Event Hub.
The guide uses SAP S/4HANA as the event emitter, but this is a stand-in for any system that is able to publish CloudEvents via SAP Cloud Application Event Hub.

<div class="impl node">

Sample app: [@capire/incidents with Customers based on S/4's Business Partners](https://github.com/cap-js/incidents-app/tree/event-broker)

</div>


### Prerequisite: Events & Messaging in CAP

Expand Down Expand Up @@ -72,10 +76,18 @@ However, please note that future [Open Resource Discovery (ORD)](https://sap.git

Configure your application to use the messaging service kind `event-broker` (derived from SAP Cloud Application Event Hub's technical name).

[Learn more about configuring SAP Cloud Application Event Hub in CAP Node.js](../../node.js/messaging#event-broker){.learn-more}
<div class="impl node">

[Learn more about configuring SAP Cloud Application Event Hub in CAP Node.js](../../node.js/messaging#event-broker){.learn-more}
[Learn more about `cds.env` profiles](../../node.js/cds-env#profiles){.learn-more}

</div>
<div class="impl java">

[Learn more about configuring SAP Cloud Application Event Hub in CAP Java](../../java/messaging#configuring-sap-event-hub-support){.learn-more}

</div>

::: tip Local Testing
Since SAP Cloud Application Event Hub sends events via HTTP, you won't be able to receive events on your local machine unless you use a tunneling service. Therefore we recommend to use a messaging service of kind [`local-messaging`](../../node.js/messaging#local-messaging) for local testing.
:::
Expand Down
72 changes: 67 additions & 5 deletions java/messaging.md
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,73 @@ Besides the built-in support for `local-messaging` and `file-based-messaging`, a
```yaml [srv/src/main/resources/application.yaml]
cds:
messaging.services:
- name: "messaging-name"
- name: "messaging-kind"
kind: "enterprise-messaging"
```
:::


#### Configuring SAP Cloud Application Event Hub Support: <Beta/> { #configuring-sap-event-hub-support}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this chapter, the page is getting pretty long. What about moving out the section "Supported Message Brokers" into a dedicated subpage?


To do asynchronous communication using [SAP Cloud Application Event Hub](https://help.sap.com/docs/event-broker), the feature dependency must be added:

```xml [srv/pom.xml]
<dependency>
<groupId>com.sap.cds</groupId>
<artifactId>cds-feature-event-hub</artifactId>
<scope>runtime</scope>
</dependency>
```

Additionally it can be configured in the `application.yaml` file:

```yaml [srv/src/main/resources/application.yaml]
cds:
messaging.services:
- name: "eventhub-messaging"
kind: "event-hub"
binding: "event-broker"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this matches the name of the service binding, right? I would avoid mixing "event-hub" and "event-broker" in the configuration. Maybe "event-hub-binding" produces less confusion

Copy link
Contributor

@StefanHenke StefanHenke Feb 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
binding: "event-broker"
binding: "<event-hub-binding>"

```

The [CloudEvents](https://cloudevents.io/) format is enforced since it's required by SAP Cloud Application Event Hub.

Authentication in the SAP Cloud Application Event Hub integration is based on the [Identity Authentication service (IAS)](https://help.sap.com/docs/cloud-identity-services/cloud-identity-services/getting-started-with-identity-service-of-sap-btp) of [SAP Cloud Identity Services](https://help.sap.com/docs/cloud-identity-services).

**Deployment:**

Your SAP Cloud Application Event Hub configuration must include your system namespace as well as the webhook URL. The binding parameters must set `"authentication-type": "X509_GENERATED"` to allow IAS-based authentication. Your IAS instance must be configured to include your SAP Cloud Application Event Hub instance under consumed-services in order for your application to accept requests from SAP Cloud Application Event Hub. Here's an example configuration

```yaml [mta.yaml]
- name: eventhub-messaging
requires:
- name: ...
type: org.cloudfoundry.managed-service
parameters:
service: event-broker
service-plan: event-connectivity
config:
# unique identifier for this event broker instance
# should start with own namespace (i.e., "foo.bar") and may not be longer than 15 characters
systemNamespace: cap.service
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn´t match the docs from EventHub I guess. Doesn´t this need to be ceSource? https://help.sap.com/docs/sap-cloud-application-event-hub/sap-cloud-application-event-hub-stakeholder-guide/create-service-instance-for-sap-cloud-applications and search for "single tenancy". The system namespace pops up here magically. We need to provide some information where to get this information.

webhookUrl: ~{srv-api/srv-cert-url}/messaging/v1.0/eb
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We cannot assume that the `srv-cert-url´ property is always available in a given customer mta. They would have to additionally bind the corresponding route in their CAP Java backend.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BraunMatthias : What do you think if we create a dedicated section how to configure the app with a .cert in a central place? We have some sort of half ready documentation already spread across SMS and IAS. But no central one which we can simple link from locations like this here.

- name: eventhub-messaging-ias
type: org.cloudfoundry.managed-service
parameters:
service: identity
service-plan: application
config:
consumed-services:
- service-instance-name: eventhub-messaging
display-name: cap.service #> any value, e.g., reuse MTA ID
home-url: ~{incidents-srv-api/url}
requires:
- name: eventhub-messaging
processed-after:
- eventhub-messaging
```

<span id="aftereventhub" />

<span id="beforeredispubsub" />

#### Configuring Redis PubSub Support <Beta />: { #configuring-redis-pubsub-support-beta}
Expand Down Expand Up @@ -680,7 +742,7 @@ private void handleError(MessagingErrorEventContext ctx) {
}
```

In a multi-tenant setup with several microservices, messages of a tenant not yet subscribed to the own microservice would be already received from the message queue. In this case, the message cannot be processed for the tenant because the tenant context is not yet available. By default, the standard error handler still 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.
In a multi-tenant setup with several microservices, messages of a tenant not yet subscribed to the own microservice would be already received from the message queue. In this case, the message cannot be processed for the tenant because the tenant context is not yet available. By default, the standard error handler still 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
Expand All @@ -692,15 +754,15 @@ private void handleError(MessagingErrorEventContext ctx) {
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();

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

ctx.setResult(true); // acknowledge
Expand Down
2 changes: 1 addition & 1 deletion node.js/messaging.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ In addition to that, slashes in the event name are replaced by dots and the `sou
Examples:

| publishPrefix | derived source |
|--------------------------|---------------------|
| ------------------------ | ------------------- |
| `my/own/namespace/ce/` | `/my/own/namespace` |
| `my/own.namespace/-/ce/` | `/my/own.namespace` |

Expand Down
Loading