loopback4-message-bus-connector¶
Overview¶
This is a LoopBack 4 extension for adding message queue and event based communication to your LoopBack applications. It provides a unified and extensible interface for working with different queuing systems.
✅ Supported Connectors
- SQSConnector – Integrates with AWS SQS using @aws-sdk/client-sqs. Supports both message sending and consumption with polling, visibility timeout, etc.
- BullMQConnector – Integrates with BullMQ (Redis-based queue). Supports advanced job options like retries, backoff, consumer concurrency, and job polling.
- EventBridge - Allows sending events to AWS EventBridge with support for event buses and schemas. Provides the HTTPS endpoint for receiving events.
🧩 Core Features - Component Based Approach Central registry for components, enabling multi-bus usage in a single application.
- @producer() Decorator Injects a producer for sending single or multiple typed events to any configured bus.
- @consumer Decorator Registers a service class as a consumer for a specific event and queue, handling messages automatically.
- IProducer Interface Exposes send() and sendMultiple() methods to send messages to buses.
- IConsumer Interface Allows you to implement a handler for a specific event type and bus, supporting strongly typed data flow.
- Typed Event Streams Encourages defining typed contracts for all events, improving consistency and type safety between producers and consumers.
You can configure one or more of the supported queue types in your application. For each, you simply provide the required connection and queue configuration. The rest—producer/consumer setup, bindings, and event handling—is abstracted and managed by the extension.
Installation¶
Install EventStreamConnectorComponent using npm;
Flow Diagram¶
Basic Use¶
Configure and load EventStreamConnectorComponent in the application constructor as shown below.
SQS¶
To use SQS as their message queue, bind its required config and connector component in your application.
to make the application as consumer, pass 'isConsumer' flag to be true in SQS config. like
Please follow the AWS SDK for JavaScript for more information on the configuration.
BullMQ¶
To use BullMq as their message queue, bind its required config and connector component in your application.
to make the application as consumer, pass 'isConsumer' flag to be true in Bull config. like
Integration¶
loopback4-message-bus-connector provides a decorator '@producer()' that can be used to access the producer of each msg queue. It expects one arguement defining the type of queue, of which producer u want to use. like
```ts
@injectable({scope: BindingScope.TRANSIENT})
export class EventConnector implements IEventConnector
// rest of implementation
} ```
Producer provider two ways of sending events - single event at a time and multiple event at a time.
ts
export type Producer<Stream extends AnyObject = AnyObject> = {
send: <Event extends keyof Stream>(data: Stream[Event], topic?: Event) => Promise<void>;
sendMultiple: <Event extends keyof Stream>(data: Stream[Event][], topic?: Event) => Promise<void>;
};
It provides '@consumer' decorator to make a service as consumer. consumer needs to follow an interface.
and can be used as
