@edd-kernel/provider-rabbitmq
v0.2.0-alpha.1
Published
RabbitMQ EDD Kernel provider.
Maintainers
Readme
@edd-kernel/provider-rabbitmq
RabbitMQ provider for EDD Kernel.
This package belongs to the EDD Kernel provider layer. It owns only the RabbitMQ
transport mapping for the shared @edd-kernel/contracts client contract.
Repository: brunnofoggia/edd-kernel-js
Install
npm install @edd-kernel/contracts @edd-kernel/provider-rabbitmqFor provider-name based client creation, install @edd-kernel/factory in place of the
contract. It brings the contract and re-exports it:
npm install @edd-kernel/factory @edd-kernel/provider-rabbitmqUsage
import { createRabbitMqClient } from '@edd-kernel/provider-rabbitmq';
const client = createRabbitMqClient(
{ createIfNotExists: true },
{
host: 'localhost',
port: 5672,
username: 'guest',
password: 'guest',
},
);
await client.send({ queueName: 'jobs' }, { type: 'UserCreated', payload: { id: '1' } });
await client.consume({ queueName: 'jobs' }, async (event, context) => {
console.log(event);
await context.ack();
});Each part goes to amqplib as a field of its own, so a password or a virtual host
carrying @, / or : is written as it is — no URL is assembled, and nothing needs to
be percent-encoded. A URL is accepted too, and wins over the parts when both are given:
const client = createRabbitMqClient(
{ createIfNotExists: true },
{ url: 'amqp://guest:guest@localhost:5672' },
);You can also create this provider through @edd-kernel/factory:
import { EddProviderName, createEddClient } from '@edd-kernel/factory';
const client = await createEddClient({
providerName: EddProviderName.RabbitMq,
createIfNotExists: true,
options: {
host: 'localhost',
port: 5672,
username: 'guest',
password: 'guest',
},
});The package also exports RabbitMqEddClient for direct construction and
inheritance. Its static provider identity is rabbitmq.
Addressing
| Type | Address | Meaning |
| --------------------- | ---------------- | ---------------------------------------------------------- |
| RabbitMqEventTarget | { queueName } | A logical name, joined with env, project and prefix. |
| RabbitMqEventTarget | { routingKey } | A routing key written in full, used as it is. |
| RabbitMqEventQueue | { queueName } | The queue to consume, scoped the same way. |
Any other address is refused by the compiler, and at runtime with
EddKernelConfigurationError.
Messages go through the default exchange. A queueName is published with the routing key
routingKeyByName gives for it, or with the name itself. durable and queueArguments
apply to every queue the provider creates; createQueue overrides them field by field.
Provider Options
connection: custom RabbitMQ connection-like object for tests or adapters.channel: custom RabbitMQ channel-like object for tests or adapters.url: AMQP URL oramqplibconnection options. When provided, it takes priority over every part below, which are then neither read nor checked. An empty or blank string counts as not provided.host: RabbitMQ host used whenurlis not provided. Defaults tolocalhost.port: RabbitMQ port used whenurlis not provided. Defaults to5672, or5671whenschemeisamqps.username: RabbitMQ username used whenurlis not provided. Defaults toguest.password: RabbitMQ password used whenurlis not provided. Defaults toguest.virtualHost: AMQP virtual host used whenurlis not provided. Defaults to/.scheme:amqp, oramqpsfor AMQP over TLS, used whenurlis not provided. Defaults toamqp; any other value throwsEddKernelConfigurationError.clientOptions: socket options passed toamqplibwhen the provider connects, whether from the parts or fromurl—clientPropertiesincluded.publishOptions: options passed tosendToQueue.durable: default queue durability whencreateIfNotExistsasserts a queue. Defaults totrue.queueArguments: default queue arguments, likewise. Queue metadata overrides both per queue.routingKeyByName: physical routing keys keyed by logical target name.pollIntervalMs: delay between empty polling cycles.nackRequeue: whethernack()requeues messages.
Acknowledgement
This provider uses manual acknowledgements only. autoAck: true means the
provider calls the manual ack operation when a message is received; it does
not enable RabbitMQ native no-ack delivery.
The provider uses finite channel.get polling for the base consume behavior
so multi-queue consumers can rotate between queues without leaving all broker
consumers active forever.
Runtime polling failures are logged and retried after pollIntervalMs. Stopping
a consumer waits for active handlers, and closing the client stops and drains
all consumers before releasing transport resources. Only connections and
channels created internally by the kernel are closed; injected resources remain
application-owned. Both operations are idempotent.
