Dependencies
Before setting up the Email Gateway, ensure you have the following dependencies in place:- PostgreSQL database for storing email gateway data
- MongoDB connection to the app-runtime database for runtime data access
- Kafka for event-driven communication with other FlowX.AI services
- Redis for caching
- Keycloak (or compatible OAuth2 provider) for authentication and authorization
The Email Gateway does not require an ingress configuration as it operates as an internal service communicating via Kafka.
Infrastructure prerequisites
| Component | Description |
|---|---|
| PostgreSQL | Dedicated database named email_gateway |
| MongoDB | Shared connection to the app-runtime database |
| Kafka | Message broker for inter-service communication |
| Redis | Caching layer for improved performance |
| Keycloak | Identity provider for service authentication |
Configuration
Authorization configuration
Set the following environment variables to connect to your identity management platform:| Environment Variable | Description | Default Value |
|---|---|---|
SECURITY_OAUTH2_BASE_SERVER_URL | Base URL of the OAuth2/OIDC server | - |
SECURITY_OAUTH2_REALM | OAuth2 realm name | - |
SECURITY_OAUTH2_CLIENT_CLIENT_ID | OAuth2 client ID for the Email Gateway | - |
SECURITY_OAUTH2_CLIENT_CLIENT_SECRET | OAuth2 client secret | - |
SECURITY_OAUTH2_SERVICE_ACCOUNT_ADMIN_CLIENT_SECRET | Service account client secret for admin operations | - |
The Email Gateway requires a dedicated Keycloak service account. This service account will be provisioned automatically as part of the SaaS organization/auth service, which handles realm creation for services.
PostgreSQL configuration
The Email Gateway uses its own dedicated PostgreSQL database for storing email-related data.| Environment Variable | Description | Default Value |
|---|---|---|
SPRING_DATASOURCE_URL | JDBC connection URL for PostgreSQL | jdbc:postgresql://postgresql:5432/email_gateway |
SPRING_DATASOURCE_USERNAME | Database username | flowx |
SPRING_DATASOURCE_PASSWORD | Database password | - |
MongoDB configuration (app-runtime)
The Email Gateway connects to the sharedapp-runtime MongoDB database for accessing runtime data.
| Environment Variable | Description | Default Value |
|---|---|---|
SPRING_DATA_MONGODB_RUNTIME_URI | MongoDB connection URI for app-runtime | mongodb://${DB_USERNAME}:${DB_PASSWORD}@mongodb-0.mongodb-headless,mongodb-1.mongodb-headless,mongodb-arbiter-0.mongodb-arbiter-headless:27017/app-runtime?retryWrites=false |
DB_USERNAME | MongoDB username | app-runtime |
DB_PASSWORD | MongoDB password | - |
The
retryWrites=false parameter is required for compatibility with MongoDB replica set configurations that include arbiters.Redis configuration
Email Gateway uses Redis for caching. Configure Redis connection using the standard Redis environment variables. Quick reference:| Environment Variable | Description | Example Value |
|---|---|---|
SPRING_REDIS_HOST | Redis server hostname | localhost |
SPRING_REDIS_PORT | Redis server port | 6379 |
SPRING_REDIS_PASSWORD | Redis authentication password | yourpassword |
For complete Redis configuration including Sentinel mode, Cluster mode, and SSL/TLS setup, see the Redis Configuration guide.
Kafka configuration
Core Kafka settings
| Environment Variable | Description | Default Value |
|---|---|---|
SPRING_KAFKA_BOOTSTRAP_SERVERS | Address of the Kafka server(s) | localhost:9092 |
SPRING_KAFKA_SECURITY_PROTOCOL | Security protocol for Kafka connections | PLAINTEXT |
KAFKA_MESSAGE_MAX_BYTES | Maximum message size (bytes) | 52428800 (50 MB) |
KAFKA_AUTHEXCEPTIONRETRYINTERVAL | Retry interval after authorization exceptions (seconds) | 10 |
OAuth authentication (when using SASL_PLAINTEXT)
| Environment Variable | Description | Default Value |
|---|---|---|
KAFKA_OAUTH_CLIENT_ID | OAuth client ID | kafka |
KAFKA_OAUTH_CLIENT_SECRET | OAuth client secret | kafka-secret |
KAFKA_OAUTH_TOKEN_ENDPOINT_URI | OAuth token endpoint | kafka.auth.localhost |
Topic naming configuration
| Environment Variable | Description | Default Value |
|---|---|---|
KAFKA_TOPIC_NAMING_PACKAGE | Package prefix for topic names | ai.flowx. |
KAFKA_TOPIC_NAMING_ENVIRONMENT | Environment segment for topic names | |
KAFKA_TOPIC_NAMING_VERSION | Version suffix for topic names | .v1 |
KAFKA_TOPIC_NAMING_SEPARATOR | Primary separator for topic names | . |
KAFKA_TOPIC_NAMING_SEPARATOR2 | Secondary separator for topic names | - |
Logging configuration
Control logging levels for different components:| Environment Variable | Description | Default Value |
|---|---|---|
LOGGING_LEVEL_ROOT | Root logging level | INFO |
LOGGING_LEVEL_APP | Application-specific log level | DEBUG |
LOGGING_CONFIG_FILE | Path to external logging config file | - |
Secrets management
The Email Gateway requires several secrets to be configured. These should be stored securely and referenced via Kubernetes secrets or a secrets management solution.| Secret Name | Description |
|---|---|
SPRING_DATASOURCE_PASSWORD | PostgreSQL database password |
DB_PASSWORD | MongoDB password for app-runtime access |
SPRING_REDIS_PASSWORD | Redis authentication password |
SECURITY_OAUTH2_CLIENT_CLIENT_SECRET | Keycloak client secret |
SECURITY_OAUTH2_SERVICE_ACCOUNT_ADMIN_CLIENT_SECRET | Keycloak service account admin secret |
KAFKA_OAUTH_CLIENT_SECRET | Kafka OAuth client secret (if using OAuth) |
Deployment
Helm values example
Below is an example Helm values configuration for deploying the Email Gateway:Network policies
The Email Gateway requires network access to the following services:| Service | Purpose | Pod Label |
|---|---|---|
| Kafka | Message broker communication | flowx.ai/egress-s-kafka |
| PostgreSQL | Primary data storage | flowx.ai/egress-s-postgresql |
| MongoDB | App-runtime data access | flowx.ai/egress-s-mongodb |
Monitoring
The Email Gateway exposes Prometheus metrics for monitoring. Enable scraping by setting the pod label:Health endpoints
| Endpoint | Description |
|---|---|
/actuator/health | Health check endpoint |
/actuator/metrics | Prometheus metrics endpoint |
/actuator/info | Application info endpoint |
Troubleshooting
Common issues
Database connection failures
Database connection failures
Symptoms: Service fails to start with database connection errors.Solutions:
- Verify the
email_gatewaydatabase exists in PostgreSQL - Check that the database user has appropriate permissions
- Ensure network connectivity between the pod and PostgreSQL service
- Verify the JDBC URL format is correct
MongoDB connection issues
MongoDB connection issues
Symptoms: Errors accessing app-runtime data.Solutions:
- Verify MongoDB replica set is healthy
- Check that
retryWrites=falseis set in the connection URI - Ensure the MongoDB user has read access to the
app-runtimedatabase - Verify network policies allow MongoDB traffic
Kafka authentication failures
Kafka authentication failures
Symptoms: Kafka consumer/producer fails to connect.Solutions:
- Verify OAuth token endpoint is accessible
- Check Kafka OAuth client credentials
- Ensure the
kafka-authzrealm exists in Keycloak - Verify network connectivity to both Kafka and Keycloak
Service account authentication errors
Service account authentication errors
Symptoms: 401/403 errors when calling other FlowX services.Solutions:
- Verify the Keycloak service account is properly configured
- Check that client secrets match between configuration and Keycloak
- Ensure the service account has required roles assigned

