This repository showcases the standalone usage of Assembler + an example of integration with different Spring related technologies like Spring AI, Spring Cloud, Spring WebFlux and Spring GraphQL for real-time data composition.
- Assembler
- Spring AI
- Spring WebFlux
- Spring GraphQL
- Spring Data
- Spring Cloud
- Testcontainers
This example showcases a basic healthcare application designed to simulate monitoring patient data. Four services are implemented:
- The Patient Service retrieves patient demographics from PostgreSQL.
- The Blood Pressure Service fetches a patient's systolic and diastolic blood pressure readings from MongoDB.
- Coming soon: Support for Change Data Capture (CDC) for real-time synchronization of the Blood Pressure Service's data cache.
- The Heart Rate Streaming Service provides real-time heart rate monitoring from an ECG device via Kafka.
- The Diagnosis AI Service analyzes heart rate and blood pressure data to produce diagnostic insights.
A GraphQL Controller implemented in PatientObservationController
aggregates data from these services. A GraphQL Subscription and REST SSE (Server-Sent Events) endpoint are also implemented in VitalsMonitoringStreamController
for real-time data aggregation from a stream of heart rate records.
Check out this brief presentation for a walkthrough of the Assembler API for the real-time streaming example (please note that the newly added AI/LLM integration is not covered in this presentation):
assembler.mp4
You can also view the presentation here and go through each slide at your own speed.
The new BatchRule
API from Assembler seamlessly integrates with the Spring GraphQL @BatchMapping mechanism, as shown in the usage example found in PatientObservationController
. 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 streamTable() function.
Assembler excels in complex data aggregation within a data streaming scenario. This example, via VitalsMonitoringStreamController
, demonstrates its usage in standalone mode in conjunction with Spring WebFlux for REST Server-Sent Events, and Spring GraphQL using @SubscriptionMapping. By combining streaming and batching, Assembler enables seamless data stream augmentation for clients connected via persistent HTTP connections or WebSockets.
- Configure application.yml with your OpenAI compatible API Key (Google Gemini is used in this example):
spring: ai: openai: api-key: ${GEMINI_API_KEY} chat: base-url: https://generativelanguage.googleapis.com completions-path: /v1beta/openai/chat/completions options: model: gemini-2.0-flash
- 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:
query PatientQuery {
patients {
id
name
healthCardNumber
bloodPressures {
systolic
diastolic
time
}
heartRate {
heartRateValue
time
}
}
}
Periodically rerun the query, the number of HR
(heart rate) values for each patient should increase:
- Run the following GraphQL Query:
subscription VitalsMonitoringStream {
vitals {
patient {
id
name
healthCardNumber
}
bloodPressures {
systolic
diastolic
time
}
heartRate {
heartRateValue
time
}
diagnosis
}
}
You should see the following:
2025-04-09.16-36-14.mp4
Open a browser or a an HTTP Client (e.g. Postman) at http://localhost:8080/vitals/stream
You should see the following: