Overview
The GreeterService provides a greeting functionality that calls an external API via the CallerService and stores greeting records in a PostgreSQL database. This service demonstrates synchronous database writes and inter-service communication patterns. Base Path:/greeter.v1.GreeterService
Authentication: Required - Bearer token via Authorization header
Middleware: CORS, rate limiting, retry logic
RPCs
Greet
Generates a personalized greeting message and records it in the database. This RPC synchronously calls the CallerService to fetch external API data before responding. Endpoint:POST /greeter.v1.GreeterService/Greet
Signature:
Request
The name to greet. If empty, defaults to “World”.
Response
The greeting message in the format: “Hello from greeter-service!”
HTTP status code returned from the external API call via CallerService
Length of the response body from the external API call (in bytes)
Connect-Query Example
cURL Example (h2c)
Example Response
Implementation Details
Database Integration
The Greet RPC performs a synchronous database write to thegreetings table before returning the response:
Service Dependencies
- CallerService: Called to fetch external API data (configured via
EXTERNAL_API_URLenvironment variable, defaults tohttps://httpbin.org/get) - PostgreSQL: Stores greeting records in the
greeter_db.greetingstable
Error Handling
The service returns Connect RPC error codes:CodeInvalidArgument: Invalid request parametersCodeDeadlineExceeded: Timeout calling CallerService (2 second timeout)CodeUnavailable: CallerService is unavailableCodeInternal: Database or internal errors
Timeouts
- CallerService RPC timeout: 2 seconds
- HTTP client timeout: 3 seconds
Authentication
All requests to the GreeterService must include a valid JWT token in theAuthorization header:
401 Unauthorized response.
Rate Limiting
The GreeterService is protected by rate limiting middleware configured in Traefik. Excessive requests may receive a429 Too Many Requests response.
Service Configuration
| Environment Variable | Default | Description |
|---|---|---|
PORT | 8080 | Service port |
CALLER_BASE_URL | http://caller-service.microservices:8081 | CallerService endpoint |
EXTERNAL_API_URL | https://httpbin.org/get | External API to call |
DATABASE_URL | - | PostgreSQL connection string (optional) |
OTEL_EXPORTER_OTLP_ENDPOINT | - | OpenTelemetry collector endpoint |