You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We see there are specific implementions required, to actually integrate remote services at runtime. We deep dive into one possible solution for that next.
886
-
887
846
888
847
889
848
@@ -938,6 +897,10 @@ The querying API is the most powerful and closest to the use cases of data-centr
938
897
939
898
### Querying Remote Data
940
899
900
+
> [!tip] CAP-level Querying -> agnostic to databases & protocols
901
+
> We work with **database-agnostic** and **protocol-agnostic** [CQL queries](../../cds/cql) both for interacting with the local database as well as for querying remote services. In effect, we got a fully generic solution for replication, i.e., it works for**_any_** remote service that supports OData, or HCQL.
902
+
903
+
941
904
### Delegating Queries
942
905
943
906
Value helps are common use cases where delegation of requests is needed, which we implemented like this in`srv/travel-service.js`for the `Customers` entity:
**Motivation** – Displaying external data in lists commonly requires fast access to that data. Relying on live calls to remote services per row is clearly not an option, as that would lead to poor performance, excessive load on server, and a nightmare regarding resilience. Instead, we somehow need to ensure that all required data is available locally, so that it can be accessed fast and reliably by UIs, using good old SQL JOINs.
994
-
995
-
#### Federated Consumption Views
996
-
997
-
The xtravels app uses a simple data replication solution that automatically replicates data for all [consumption views](#consumption-views) tagged with `@federated`:
998
-
999
-
```cds :line-numbers=4
1000
-
@federated entity Customers as projection on S4.A_BusinessPartner { ... }
1001
-
```
1002
-
1003
-
If a remote service is detected, CAP turns these entities into tables to serve as local persistence forreplicated data (line 9in the code below).
956
+
Displaying external data in lists commonly requires fast access to that data. Relying on live calls to remote services per row is clearly not an option, as that would lead to poor performance, excessive load on server, and a nightmare regarding resilience. Instead, we somehow need to ensure that all required data is available locally, so that it can be accessed fast and reliably by UIs, using good old SQL JOINs.
1004
957
1005
-
> [!tip] Stay Intentional -><i>What, not how!</i> -> Minimal Assumptions
1006
-
>
1007
-
> By tagging entities with `@federated`, you declare your intention - **_what_** you want - without assuming **_how_** to implement it. This lets CAP runtimes or your own solutions choose the best implementation for each environment, which may differ between development, testing, and production environments, allowing evolution without disruption.
1008
-
1009
-
1010
-
#### Generic Implementation
1011
-
1012
-
Here's the complete code, placed in file `srv/data-federation.js`:
958
+
In the [`@capire/xtravels`](https://github.com/capire/xtravels) app we accomplished that with a simple, yet quite effective generic data replication solution. In essence that implementation boils down to these lines of querying remote services:
Let's have a closer look at this code, which handles these main tasks:
1058
-
1059
-
1. **Prepare Persistence** – When the model is `loaded`, before deploying it to the database, we collect all `@federated` entities to be replicated, check whether their respective services are remote, and if so, turn them into tables forlocal replicas (line 11).
1060
-
1061
-
2. **Setup Replication** – Later when all services are `served`, we connect to each remote one (line 20), register a handler for replication (line 21), and schedule it to be invoked every three seconds (line 22).
1062
-
1063
-
3. **Replicate Data** – Finally, the `replicate` handler implements a simple polling-based data federation strategy, based on `modifiedAt` timestamps (lines 28-32), with the actual call to remote happening on line 29.
1064
-
1065
-
> [!tip] CAP-level Querying -> agnostic to databases & protocols
1066
-
> We work with **database-agnostic** and **protocol-agnostic** [CQL queries](../../cds/cql) both for interacting with the local database as well as for querying remote services. In effect, we got a fully generic solution for replication, i.e., it works for**_any_** remote service that supports OData, or HCQL.
1067
-
1068
-
1069
-
#### Test Drive
1070
-
1071
-
Let's see the outcome in action: to activate the above data federation code, edit `srv/server.js` file and uncomment the single line of code in there like this:
Finally, open the Fiori UI in the browser again, and see that customer data from S/4 as well as flight data from xflights is now displayed properly, thanks to the data federation implemented above.
1124
-
1125
-

1126
-
1127
-

1128
973
974
+
[Learn more about CAP-level Data Federation in the dedicated guide.](data-federation){.learn-more}
0 commit comments