@onlineapps/mq-client-core
v1.0.80
Published
Core MQ client library for RabbitMQ - shared by infrastructure services and connectors
Maintainers
Readme
@onlineapps/mq-client-core
Core MQ client library for RabbitMQ - shared by infrastructure services and connectors.
Overview
This is the core library extracted from @onlineapps/conn-infra-mq to provide basic MQ functionality for infrastructure services (gateway, registry, validator) without business-specific features.
Architecture Principle: Connectors are exclusively for business services. If a connector contains functionality that should also serve infrastructure services, it must be extracted into a shared library.
Installation
npm install @onlineapps/mq-client-coreUsage
For Infrastructure Services
const BaseClient = require('@onlineapps/mq-client-core');
const mqClient = new BaseClient({
type: 'rabbitmq',
host: 'amqp://localhost:5672',
queue: 'workflow.init' // Optional default queue
});
await mqClient.connect();
await mqClient.publish('workflow.init', { workflowId: '123', data: '...' });
await mqClient.publish('workflow.control', { workflowId: '123', data: '...' });Configuration
Flexible Schema - Only type and host are required:
{
type: 'rabbitmq', // Required
host: 'amqp://...', // Required
queue: 'optional', // Optional default queue
exchange: '', // Optional exchange
durable: true, // Optional (default: true)
prefetch: 1, // Optional (default: 1)
noAck: false, // Optional (default: false)
logger: null // Optional custom logger
}API
BaseClient
connect(options?)- Connect to RabbitMQdisconnect()- Disconnect from RabbitMQpublish(queue, message, options?)- Publish message to queueconsume(queue, handler, options?)- Consume messages from queueack(msg)- Acknowledge messagenack(msg, options?)- Negative acknowledge messageisConnected()- Check connection statusonError(callback)- Register error handler
Architecture
mq-client-core (this library)
├── BaseClient - Core AMQP operations
├── RabbitMQClient - Transport implementation
└── Basic publish/consume functionality
conn-infra-mq (connector for business services)
├── Uses mq-client-core internally
├── ConnectorMQClient - Orchestrator with layers
├── WorkflowRouter - Business workflow routing
└── Additional business-specific features
Infrastructure services (gateway, registry, validator)
└── Use mq-client-core directly (not the connector)Related Packages
@onlineapps/conn-infra-mq- Full connector with business-specific features (uses this library internally)
License
MIT
