A Spring Boot 3 application that serves as a gateway for Server-Sent Events (SSE) from multiple backend services. This service aggregates real-time events from various sources and provides unified endpoints for clients to consume these streams.
The SSE Gateway acts as a proxy and aggregator for multiple SSE endpoints, providing both public and secured access to real-time event streams.
- Java 21 or higher
- Node.js (for mock servers)
- Gradle (included as wrapper)
The easiest way to run the complete system is using the provided start script:
./start-all.shThis script will:
- Check and install npm dependencies for mock servers
- Start three mock SSE servers on ports 8081, 8082, 8083
- Start the SSE Gateway on port 8080
- Display all available endpoints and example usage
cd mock-sse-servers
npm install
npm run start-allThis starts:
- Account Service on port 8081
- Payment Service on port 8082
- Customer Service on port 8083
./gradlew bootRunOr with a specific profile:
./gradlew bootRun --args='--spring.profiles.active=local'./gradlew buildThe application uses Spring Boot configuration with the prefix sse-gateway. Configuration can be set in application.yaml or application-local.yaml.
sse-gateway:
debug: false # Enable debug logging
security: false # Enable/disable JWT security
endpoints: [] # List of public SSE endpoints
secured-endpoints: [] # List of secured SSE endpoints (requires JWT)Each endpoint is configured with:
name: Unique identifier for the endpointurl: Backend SSE service URLfilter-params: List of allowed query parameters
Example endpoint configuration:
sse-gateway:
endpoints:
- name: account-low-balance
url: http://localhost:8081/accounts/low-balance-alerts
filter-params:
- customerId
- currency
- name: account-transactions
url: http://localhost:8081/accounts/transaction-events
filter-params:
- customerId
- currency
- minAmount
- name: payment-transactions
url: http://localhost:8082/transactions/sse
filter-params:
- customerId
- currency
- limit
- name: high-value-transactions
url: http://localhost:8082/transactions/high-value
filter-params:
- minAmount
- currency
- name: customer-activity
url: http://localhost:8083/customers/activity
filter-params:
- customerId
- activityType
- name: security-alerts
url: http://localhost:8083/customers/security-alerts
filter-params:
- severity
- customerIdWhen sse-gateway.security: true, the secured endpoints require JWT authentication. You must also configure the JWT issuer URI:
sse-gateway:
security: true
secured-endpoints:
- name: customer-profile-events
url: http://localhost:8083/customers/profile-events
filter-params:
- profileType
- name: account-private-events
url: http://localhost:8081/accounts/private-events
filter-params:
- currency
spring:
security:
oauth2:
resourceserver:
jwt:
issuer-uri: https://your-auth-server.com # Required when security is enabledStandard Spring Boot properties are also available:
server:
port: 8080
spring:
application:
name: sse-gateway-services
management:
endpoints:
web:
exposure:
include: health,info,metricsGET /public/events- Access public SSE streams without authenticationGET /actuator/health- Health check endpointGET /actuator/info- Application informationGET /actuator/metrics- Metrics endpoint
GET /events- Access secured SSE streams with JWT authentication
sources: Comma-separated list of endpoint names to subscribe to- Additional parameters as defined in endpoint
filter-params
Public access:
curl "http://localhost:8080/public/events?sources=account-transactions,payment-transactions&customerId=cust123¤cy=USD"Secured access (when security enabled):
curl -H "Authorization: Bearer <JWT_TOKEN>" "http://localhost:8080/events?sources=customer-profile-events,account-private-events¤cy=USD"Uses configuration from application.yaml with production-ready settings.
Uses application-local.yaml with:
- Debug logging enabled
- H2 in-memory database
- OpenTelemetry disabled