The sample about kafka, which use these libraries:
-
kafka-plus to support kafkajs, combine with mq-one for nodejs. Example is at kafka-sample.
We also provide these libraries to support GO:
- segmentio/kafka-go, IBM/sarama and confluent
- kafka to wrap go-stomp
- Simplify the way to initialize the consumer, publisher by configurations
- Props: when you want to change the parameter of consumer or publisher, you can change the config file, and restart Kubernetes POD, do not need to change source code and re-compile.
- Simplify the way to initialize the consumer, publisher by configurations
- core-go/mq to implement this flow, which can be considered a low code tool for message queue consumer:
A complete TypeScript sample application demonstrating how to build an event-driven service using kafka-plus (which wraps kafkajs) and the core-ts ecosystem.
The project shows how to produce and consume Kafka messages, validate payloads, process messages with retry support, persist data into MySQL, and expose health check endpoints.
Rather than being a simple Kafka example, this project demonstrates how multiple reusable infrastructure libraries can be composed into a clean, maintainable microservice.
- Kafka producer
- Kafka consumer
- Message validation
- Automatic retry processing
- MySQL persistence
- Structured logging
- Health check endpoint
- Environment-based configuration
- Lightweight HTTP server
- Clean dependency injection using a composition root
HTTP Request
│
▼
HTTP Application
│
▼
Application Context
│
┌───────────────┼────────────────┐
│ │ │
▼ ▼ ▼
Producer Consumer Health Check
│ │
│ ▼
│ Message Processor
│ │
│ Validation
│ │
│ Retry Policy
│ │
│ Repository
│ │
└───────────► MySQL
All application components are created in a single composition root (context.ts), making dependencies explicit and easy to maintain.
- TypeScript
- Node.js
- Kafka
- MySQL
- kafka-plus
- message-processing
- logger-core
- validation-core
- mysql2-core
- config-plus
- health-service
src/
│
├── app.ts
├── context.ts
├── config.ts
├── model.ts
│
├── handler/
│ ├── validator.ts
│ ├── writer.ts
│ └── processor.ts
│
├── repository/
│ └── user-repository.ts
│
└── index.ts
HTTP Request
│
▼
Producer
│
▼
Kafka Topic
│
▼
Consumer
│
▼
Message Processor
│
▼
Validation
│
▼
Retry
│
▼
MySQL
npm installUpdate the Kafka and MySQL configuration.
Kafka
-------
Broker
Topic
Client ID
Username
Password
MySQL
-------
Host
Port
Database
Username
Passwordnpm startor
npm run devPOST /send
Example
{
"id": "u001",
"name": "John Doe",
"email": "john@example.com"
}The application publishes the message to Kafka.
GET /health
Returns the health status of:
- Kafka
- MySQL
Example
{
"status": "UP",
"checks": [
{
"name": "kafka",
"status": "UP"
},
{
"name": "mysql",
"status": "UP"
}
]
}Incoming Kafka messages pass through several stages.
Kafka Message
│
▼
Validation
│
▼
Retry
│
▼
Repository
│
▼
MySQL
This separation keeps business logic small while making infrastructure concerns reusable.
The sample uses a simple composition root instead of a dependency injection framework.
createContext()
│
├── Logger
├── Validator
├── Repository
├── Retry Policy
├── Processor
├── Producer
├── Consumer
└── Health Check
This approach keeps dependencies explicit and easy to understand.
Most Kafka examples only demonstrate how to send and receive messages.
This sample demonstrates how to build a real service by combining reusable infrastructure libraries.
It shows how to:
- publish Kafka events
- consume Kafka events
- validate messages
- implement retry processing
- persist data
- expose health checks
- organize application dependencies
- keep business logic independent from infrastructure
| Library | Purpose |
|---|---|
| kafka-plus | Kafka producer and consumer abstraction |
| message-processing | Message processing pipeline with retry support |
| logger-core | Structured logging |
| validation-core | Data validation |
| mysql2-core | MySQL data access |
| config-plus | Configuration management |
| health-service | Health check aggregation |
MIT
