@onlineapps/agent-registry-client
v1.0.28
Published
Agent-registry-client provides the core communication mechanism for microservices in this environment. It enables them to interact with a services_registry to receive and fulfill tasks by submitting heartbeats or their API descriptions.
Downloads
6
Maintainers
Readme
@onlineapps/agent-registry-client
A lightweight client for microservice registration, heartbeat, and API description exchange via RabbitMQ.
🚀 Features
- Automatic queue management (
workflow,<serviceName>.registry,api_services_queue,registry_office) - Periodic heartbeat messages with metadata
- API description request/response flow
- Event-driven API using
EventEmitter - Fully configurable via environment variables or constructor options
📦 Installation
npm install @onlineapps/agent-registry-client
# or
yarn add @onlineapps/agent-registry-client🔧 Quick Start
// Load environment, if using .env
require('dotenv').config();
const { ServiceRegistryClient, EVENTS } = require('@onlineapps/agent-registry-client');
const client = new ServiceRegistryClient({
amqpUrl: process.env.AMQP_URL,
serviceName: 'invoicing',
version: '1.0.0'
});
// Listen for API description requests
client.on(EVENTS.API_DESCRIPTION_REQUEST, async () => {
const apiSpec = await loadOpenApiSpec();
await client.sendApiDescription(apiSpec);
});
// Initialize and start heartbeats
await client.init();
client.startHeartbeat();
// Graceful shutdown
process.on('SIGINT', async () => {
await client.close();
process.exit(0);
});📄 Configuration
Configuration can be provided via environment variables or constructor options:
| Variable | Description | Default |
| -------------------- | --------------------------------------------- | -------------------- |
| AMQP_URL | RabbitMQ connection string (required) | — |
| SERVICE_NAME | Logical name of your service (required) | — |
| SERVICE_VERSION | Service version in SemVer format (required) | — |
| HEARTBEAT_INTERVAL | Interval in ms between heartbeats | 10000 |
| API_QUEUE | Queue name for heartbeat/API messages | api_services_queue |
| REGISTRY_QUEUE | Queue name for registry requests/descriptions | registry_office |
🛠️ API Reference
See docs/api.md for full details on classes, methods, and events.
📖 Documentation
- Architecture overview: docs/architecture.md
- API reference: docs/api.md
- Examples: examples/basicUsage.js
✅ Testing
# Run unit and integration tests
yarn test
# or
npm test🎨 Coding Standards
- Linting: ESLint (Airbnb style)
- Formatting: Prettier
- Testing: Jest
🤝 Contributing
Please read CONTRIBUTING.md for details on submitting issues and pull requests.
📜 License
This project is licensed under the MIT License. See LICENSE for details.
xxxxx
