This repository showcases the standalone usage of Assembler + the integration of Assembler with Spring GraphQL to aggregate data from multiple sources in a single query. This combination serves as a powerful tool for implementing API composition, facilitating efficient data retrieval while reducing the complexity of client-side data aggregation.
This example demonstrates a basic healthcare application for simulating monitoring patient data. Three services are implemented: the Patient Service for retrieving patient demographics from PostgreSQL, the Body Measurement Service for retrieving patient's height and weight from MongoDB, and the SpO2 Streaming Service for real-time oxygen saturation monitoring from a pulse oximeter device via Kafka. A GraphQL Controller is implemented in PatientObservationGraphQLController
to aggregate data from these services.
This sample app was deliberately kept simple to showcase the Assembler/Spring GraphQL integration in a very accessible way. However, it does not incorporate more advanced concepts such as Change Data Capture (CDC) or complex stream processing. Additionally, it does not emphasize any distributed/scalability architecture patterns.
The new BatchRule
API from Assembler seamlessly integrates with the Spring GraphQL @BatchMapping mechanism, as shown in the usage example found in PatientObservationGraphQLController
. Additionally, this example showcases additional features of Assembler, including:
- caching of service invocations using the cached() function
- caching of real-time data streams with the autoCache() function.
Assembler excels in complex data aggregation within a data streaming scenario. This example demonstrates its usage in standalone mode in conjunction with Spring GraphQL using @SubscriptionMapping. By combining streaming and batching, Assembler enables seamless data stream augmentation for clients connected via WebSockets, offering an effective complement to GraphQL's native streaming support.
- Make sure Docker is installed
- Run the
main
method in src\test\java\io\github\pellse\example\PatientMonitoringApplicationTest.java- Or execute the bootTestRun Gradle Task
This repository takes advantage of the new Spring Boot 3.1.0 Testcontainers support for local development.
Open a browser at http://localhost:8080/graphiql?path=/graphql
- Run the following GraphQL Query:
{
patientObservations: patients {
name
health_card_number: healthCardNumber
body_measurement: bodyMeasurement {
height_cm: height
weight_kg: weight
time
}
oxygen_saturation: spO2 {
spO2Value
time
}
}
}
Periodically rerun the query, the number of SpO2
values for each patient should increase:
- Run the following GraphQL Query:
subscription {
spO2_reading: spO2Reading {
oxygen_saturation: spO2 {
id
value_in_percentage: spO2Value
time
}
patient {
id
name
health_card_number: healthCardNumber
}
body_measurement: bodyMeasurement {
height_cm: height
weight_kg: weight
}
}
}
You should see the following:
SpO2.Readings.mp4
- Assembler
- Spring GraphQL
- Spring Data
- Spring Cloud Function
- Spring Cloud Stream
- Reactive Kafka
- Spring Cloud Stream
- Testcontainers