@amqp-contract/core
v0.10.0
Published
Core utilities for AMQP setup and management in amqp-contract
Maintainers
Readme
@amqp-contract/core
Core utilities for AMQP setup and management in amqp-contract.
This package provides centralized functionality for establishing AMQP topology (exchanges, queues, and bindings) from contract definitions, and defines the Logger interface used across amqp-contract packages.
Installation
npm install @amqp-contract/core
# or
pnpm add @amqp-contract/core
# or
yarn add @amqp-contract/coreUsage
AmqpClient
The core package exports an AmqpClient class that handles the creation of all AMQP resources defined in a contract.
import { AmqpClient } from "@amqp-contract/core";
import {
defineContract,
defineExchange,
defineQueue,
defineQueueBinding,
} from "@amqp-contract/contract";
// Define resources
const ordersExchange = defineExchange("orders", "topic", { durable: true });
const orderProcessingQueue = defineQueue("order-processing", { durable: true });
// Define your contract
const contract = defineContract({
exchanges: {
orders: ordersExchange,
},
queues: {
orderProcessing: orderProcessingQueue,
},
bindings: {
orderBinding: defineQueueBinding(orderProcessingQueue, ordersExchange, {
routingKey: "order.created",
}),
},
});
// Setup AMQP resources
const amqpClient = new AmqpClient(contract, {
urls: ["amqp://localhost"],
});
// Clean up
await amqpClient.close();For advanced channel configuration options (custom setup, prefetch, publisher confirms), see the Channel Configuration Guide.
Logger Interface
The core package exports a Logger interface that can be used to implement custom logging for AMQP operations:
import type { Logger } from "@amqp-contract/core";
const logger: Logger = {
debug: (message, context) => console.debug(message, context),
info: (message, context) => console.info(message, context),
warn: (message, context) => console.warn(message, context),
error: (message, context) => console.error(message, context),
};
// Pass the logger to client or worker
import { TypedAmqpClient } from "@amqp-contract/client";
const client = await TypedAmqpClient.create({
contract,
urls: ["amqp://localhost"],
logger, // Optional: logs published messages
});API
For complete API documentation, see the @amqp-contract/core API Reference.
Documentation
📖 Read the full documentation →
License
MIT
