-
Notifications
You must be signed in to change notification settings - Fork 139
wip: Improve messaging docs #2265
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
base: main
Are you sure you want to change the base?
Conversation
|
|
||
| ## Overview | ||
|
|
||
| In SAP Cloud Application Programming Model (CAP), messaging enables decoupled communication between services using events. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| In SAP Cloud Application Programming Model (CAP), messaging enables decoupled communication between services using events. | |
| Messaging enables decoupled communication between services using events. |
| ## Overview | ||
|
|
||
| In SAP Cloud Application Programming Model (CAP), messaging enables decoupled communication between services using events. | ||
| CAP distinguishes between the logical and technical messaging layers, separating business concerns from technical infrastructure and enabling both flexibility and scalability. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| CAP distinguishes between the logical and technical messaging layers, separating business concerns from technical infrastructure and enabling both flexibility and scalability. | |
| CAP distinguishes between the logical and technical messaging layers, separating business concerns from technical infrastructure. |
Don't add AI slop ;)
|
|
||
| **Modeled Events**: Events are defined in CDS models with typed schemas, providing compile-time validation and IDE support. These events represent business occurrences like `'orderProcessed'`, or `'stockUpdated'`. | ||
|
|
||
| **Event Topics**: Topics organize events into logical channels, allowing for structured event categorization and routing. Topics can be explicitly defined or derived from service and event names. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"structured event categorization"? What is that?
|
|
||
| The **technical layer** handles the actual message transport and delivery: | ||
|
|
||
| **CAP Messaging Service**: Acts as the translation layer between logical events and technical infrastructure. It converts service-level event names to fully qualified names (e.g., `'OrderSrv.reviewed'`), manages topic resolution, message serialization, and routing logic. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems weird. Maybe "Logical events are delegated to the messaging service, the corresponding event name on the technical service is either the fully qualified event name or the value of the @topic annotation if given."
|
|
||
| **Event Topics**: Topics organize events into logical channels, allowing for structured event categorization and routing. Topics can be explicitly defined or derived from service and event names. | ||
|
|
||
| **CAP Services**: Services act as event producers and consumers, using simple APIs like `srv.emit('reviewed', data)` and `srv.on('orderProcessed', handler)`. Services communicate using friendly event names without needing to know the underlying infrastructure details. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| **CAP Services**: Services act as event producers and consumers, using simple APIs like `srv.emit('reviewed', data)` and `srv.on('orderProcessed', handler)`. Services communicate using friendly event names without needing to know the underlying infrastructure details. | |
| **CAP Services**: Services act as event producers or consumers, using simple APIs like `srv.emit('reviewed', data)` or `srv.on('orderProcessed', handler)`. Services communicate using friendly event names without needing to know the underlying infrastructure details. |
|
|
||
| The message flow follows a clear path through both layers: | ||
|
|
||
| **Outbound Flow (Publisher)**: A service calls `srv.emit('reviewed', data)` → CAP Messaging Service resolves the event name to a fully qualified topic (e.g., `OrderSrv.reviewed`) → Message is serialized and sent to the Event Broker → Broker stores and distributes the message to all subscribers. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe mention that A service is an own service (not an external one).
|
|
||
| **Outbound Flow (Publisher)**: A service calls `srv.emit('reviewed', data)` → CAP Messaging Service resolves the event name to a fully qualified topic (e.g., `OrderSrv.reviewed`) → Message is serialized and sent to the Event Broker → Broker stores and distributes the message to all subscribers. | ||
|
|
||
| **Inbound Flow (Subscriber)**: Event Broker delivers message from subscribed topic → CAP Messaging Service receives the message → Service name and event name are resolved from the topic → Message is routed to the appropriate service handler via `srv.on('reviewed', handler)`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe also mention that the existence of a srv.on event handler for moedelled event will cause the broker to listen to those (e.g. subscriptions for Event Mesh).
| // Send messages directly with full topic control | ||
| await messaging.emit('custom.topic', data); | ||
|
|
||
| // Receive messages directly from any topic |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds a bit misleading, not any topic, but a particular topic.
| When a CDS event is declared without an @topic annotation in a service (for example, an event called 'reviewed' in the OrderSrv service), the messaging behavior follows this pattern: | ||
|
|
||
| **Emitting Events:** | ||
| • Using the logical service API, you emit the event with just the event name ('reviewed') | ||
| • Using the technical messaging API, you emit using the fully qualified name ('OrderSrv.reviewed') | ||
|
|
||
| **Broker Handling:** | ||
| • The message broker receives and routes the message using the topic 'OrderSrv.reviewed' | ||
|
|
||
| **Receiving Events:** | ||
| • Using the logical service API, you listen for the event with just the event name ('reviewed') | ||
| • Using the technical messaging API, you listen using the fully qualified name ('OrderSrv.reviewed') | ||
|
|
||
| #### Scenario 2: With @topic Annotation | ||
|
|
||
| When a CDS event is declared with a custom @topic annotation (for example, an event called 'reviewed' with @topic: 'foo.bar' in the OrderSrv service), the messaging behavior follows this pattern: | ||
|
|
||
| **Emitting Events:** | ||
| • Using the logical service API, you still emit the event with the event name ('reviewed') | ||
| • Using the technical messaging API, you emit using the custom topic name ('foo.bar') | ||
|
|
||
| **Broker Handling:** | ||
| • The message broker receives and routes the message using the custom topic 'foo.bar' | ||
|
|
||
| **Receiving Events:** | ||
| • Using the logical service API, you listen for the event with the event name ('reviewed') | ||
| • Using the technical messaging API, you listen using the custom topic name ('foo.bar') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a lot of explanation for the topic mapping -> should be condensed
| await messaging.emit('cap/msg/system/my/custom/topic', | ||
| { ID, rating }) | ||
|
|
||
| // alternative if you want to send custom headers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
headers can also be the 3rd argument, i.e. messaging.emit('topic', data, headers)
No description provided.