Skip to content

Conversation

@vkozyura
Copy link
Contributor

No description provided.

@vkozyura vkozyura requested a review from smahati as a code owner December 10, 2025 16:01
@vkozyura vkozyura marked this pull request as draft December 10, 2025 16:01

## Overview

In SAP Cloud Application Programming Model (CAP), messaging enables decoupled communication between services using events.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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.
Copy link
Contributor

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.
Copy link
Contributor

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.
Copy link
Contributor

@David-Kunz David-Kunz Dec 11, 2025

Choose a reason for hiding this comment

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

Suggested change
**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.
Copy link
Contributor

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)`.
Copy link
Contributor

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
Copy link
Contributor

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.

Comment on lines +65 to +91
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')
Copy link
Contributor

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
Copy link
Contributor

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants