Skip to content

Commit 3450db5

Browse files
Merge pull request #2 from sadarunnisa-sf/dev
feat(connector): implement sqs and BullMQ connectors
2 parents 372b630 + 1cd23c9 commit 3450db5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+22832
-2
lines changed

.eslintignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules/
2+
dist/
3+
coverage/
4+
.eslintrc.js

.eslintrc.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module.exports = {
2+
extends: '@loopback/eslint-config',
3+
rules: {
4+
'no-extra-boolean-cast': 'off',
5+
'@typescript-eslint/interface-name-prefix': 'off',
6+
'no-prototype-builtins': 'off',
7+
'no-await-in-loop': 'error',
8+
},
9+
parserOptions: {
10+
project: './tsconfig.json',
11+
tsconfigRootDir: __dirname,
12+
},
13+
};

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
## Description
2+
3+
Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.
4+
5+
Fixes # (issue)
6+
7+
## Type of change
8+
9+
Please delete options that are not relevant.
10+
11+
- [ ] Bug fix (non-breaking change which fixes an issue)
12+
- [ ] New feature (non-breaking change which adds functionality)
13+
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
14+
- [ ] Intermediate change (work in progress)
15+
16+
## How Has This Been Tested?
17+
18+
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
19+
20+
- [ ] Test A
21+
- [ ] Test B
22+
23+
## Checklist:
24+
25+
- [ ] Performed a self-review of my own code
26+
- [ ] npm test passes on your machine
27+
- [ ] New tests added or existing tests modified to cover all changes
28+
- [ ] Code conforms with the style guide
29+
- [ ] API Documentation in code was updated
30+
- [ ] Any dependent changes have been merged and published in downstream modules

.github/workflows/build-image.yaml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# This is a basic workflow to help you get started with Actions
2+
3+
name: Build and Push Image
4+
5+
# Controls when the action will run. Triggers the workflow on push or pull request
6+
# events but only for the master branch
7+
on:
8+
push:
9+
branches: [master]
10+
11+
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
12+
jobs:
13+
# This workflow contains a single job called "build"
14+
docker_build:
15+
# The type of runner that the job will run on
16+
runs-on: ubuntu-latest
17+
env:
18+
IMAGE_REPO_NAME: ${{ secrets.DOCKERHUB_USERNAME }}
19+
NR_ENABLED: 0
20+
21+
# Steps represent a sequence of tasks that will be executed as part of the job
22+
steps:
23+
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
24+
- uses: actions/checkout@v3
25+
- uses: actions/setup-node@v3
26+
with:
27+
node-version: "18"
28+
cache: "npm"
29+
cache-dependency-path: "**/package-lock.json"
30+
31+
- name: Set up QEMU
32+
uses: docker/setup-qemu-action@v3
33+
34+
- name: Set up Docker Buildx
35+
uses: docker/setup-buildx-action@v3
36+
37+
- name: setup packages
38+
run: "npm i"
39+
40+
- name: lerna build
41+
run: "npm run build --workspaces --if-present"
42+
43+
- name: lerna test
44+
run: "npm run test --workspaces --if-present"
45+
46+
- name: lerna docker build
47+
run: "npx lerna run docker:build --stream --concurrency 2"
48+
49+
- name: Login to Docker Hub
50+
uses: docker/login-action@v2
51+
with:
52+
username: ${{ secrets.DOCKERHUB_USERNAME }}
53+
password: ${{ secrets.DOCKERHUB_TOKEN }}
54+
55+
- name: lerna docker push
56+
run: "npx lerna run docker:push"

.github/workflows/main.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
branches: [master]
6+
7+
# This workflow contains a single job called "npm_test"
8+
jobs:
9+
npm_test:
10+
# The type of runner that the job will run on
11+
runs-on: ubuntu-latest
12+
13+
# Steps represent a sequence of tasks that will be executed as part of the job
14+
steps:
15+
# Checks-out your repository under $GITHUB_WORKSPACE
16+
- uses: actions/checkout@v3
17+
- uses: actions/setup-node@v3
18+
with:
19+
node-version: '^18.x'
20+
21+
- name: Install Monorepo Deps
22+
run: npm i
23+
24+
- name: Run Test Cases
25+
run: npm run test --workspaces --if-present
26+
27+
- name: Run Lint Checks
28+
run: npm run lint --workspaces --if-present

.husky/commit-msg

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
npx --no-install commitlint --edit $1
5+
6+
# Section for git-secrets
7+
if ! command -v git-secrets &> /dev/null 2>&1
8+
then
9+
echo "git-secrets is not installed. Please run 'brew install git-secrets' or visit https://github.com/awslabs/git-secrets#installing-git-secrets"
10+
exit 1
11+
fi
12+
13+
# Initialise git-secrets configuration
14+
git-secrets --register-aws > /dev/null
15+
16+
echo "Running git-secrets..."
17+
# Scans the commit message.
18+
git-secrets --commit_msg_hook -- "$@"

.husky/pre-commit

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
# Section for git-secrets
5+
if ! command -v git-secrets &> /dev/null 2>&1
6+
then
7+
echo "git-secrets is not installed. Please run 'brew install git-secrets' or visit https://github.com/awslabs/git-secrets#installing-git-secrets"
8+
exit 1
9+
fi
10+
11+
# Initialise git-secrets configuration
12+
git-secrets --register-aws > /dev/null
13+
14+
echo "Running git-secrets..."
15+
# Scans all files that are about to be committed.
16+
git-secrets --pre_commit_hook -- "$@"
17+
18+
npm test

.husky/prepare-commit-msg

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
exec < /dev/tty && npx cz --hook || true
5+
6+
# Section for git-secrets
7+
if ! command -v git-secrets &> /dev/null 2>&1
8+
then
9+
echo "git-secrets is not installed. Please run 'brew install git-secrets' or visit https://github.com/awslabs/git-secrets#installing-git-secrets"
10+
exit 1
11+
fi
12+
13+
# Initialise git-secrets configuration
14+
git-secrets --register-aws > /dev/null
15+
16+
echo "Running git-secrets..."
17+
# Determines if merging in a commit will introduce tainted history.
18+
git-secrets --prepare_commit_msg_hook -- "$@"

README.md

Lines changed: 140 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,140 @@
1-
# loopback4-message-bus-queue-connector
2-
loopback4-message-bus-queue-connector
1+
# Message bus queue connectors
2+
This is the package for the message bus queue connectors component for LoopBack 4 applications.
3+
It provides components to work with queues such as SQS, BullMQ
4+
5+
[![LoopBack](https://github.com/loopbackio/loopback-next/raw/master/docs/site/imgs/branding/Powered-by-LoopBack-Badge-(blue)-@2x.png)](http://loopback.io/)
6+
7+
## Installation
8+
9+
Install MessageBusQueueConnectorsComponent using `npm`;
10+
11+
```sh
12+
$ [npm install | yarn add] message-bus-queue-connectors
13+
```
14+
15+
## Basic Use
16+
17+
Configure and load MessageBusQueueConnectorsComponent in the application constructor
18+
as shown below.
19+
20+
### SQS
21+
```ts
22+
import {SqsProducerProvider, SQSBindings, SQSConsumerObserver, SQSConsumerProvider} from 'message-bus-queue-connectors/sqs';
23+
24+
// ...
25+
export class MyApplication extends BootMixin(ServiceMixin(RepositoryMixin(RestApplication))) {
26+
constructor(options: ApplicationConfig = {}) {
27+
super();
28+
this.bind(SqsClientBindings.Config).to(
29+
options.sqsConfig
30+
);
31+
32+
this.bind(SQSBindings.SQSProducerProvider).toProvider(SqsProducerProvider);
33+
// ...
34+
35+
// Add lifecycle observer
36+
this.lifeCycleObserver(SQSConsumerObserver);
37+
38+
// ...
39+
}
40+
// ...
41+
}
42+
```
43+
44+
#### SQS Config
45+
```ts
46+
const config = {
47+
queueConfig: {
48+
QueueUrl: "sqs-queue-url",,
49+
MessageRetentionPeriod: 1,
50+
MaximumMessageSize: 262144 ,
51+
ReceiveMessageWaitTimeSeconds: 60,
52+
VisibilityTimeout: 300,
53+
},
54+
Credentials: {
55+
region: "aws-region",
56+
accessKeyId: "aws-access-key-id",
57+
secretAccessKey: "aws-secret-access-key",
58+
},
59+
ConsumerConfig: {
60+
MaxNumberOfMessages: 10,
61+
WaitTimeSeconds: 20,
62+
maxConsumers: 2,
63+
},
64+
}
65+
66+
```
67+
#### Consumer setup
68+
Below is consumer handler example.
69+
```ts
70+
this.bind(SQSBindings.SQSConsumerProvider).toProvider(SQSConsumerProvider);
71+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
72+
this.bind(SQSBindings.SQSConsumerHandler).to(async (message: string) => {
73+
console.log('Processing message SQS---------:', message);
74+
75+
});
76+
77+
```
78+
Please follow the [AWS SDK for JavaScript](https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/sqs-examples-send-receive-messages.html) for more information on the configuration.
79+
80+
81+
### BullMQ
82+
83+
```ts
84+
import {BullMQProducerProvider, BullMQBindings, BullMQConsumerObserver} from 'message-bus-queue-connectors/bullmq';
85+
86+
// ...
87+
export class MyApplication extends BootMixin(ServiceMixin(RepositoryMixin(RestApplication))) {
88+
constructor(options: ApplicationConfig = {}) {
89+
super();
90+
this.bind(BullMQBindings.Config).to(
91+
options.config
92+
);
93+
94+
this.bind(BullMQBindings.BullMQProducerProvider).toProvider(BullMQProducerProvider);
95+
// ...
96+
// Add lifecycle observer
97+
this.lifeCycleObserver(BullMQConsumerObserver);
98+
// ...
99+
}
100+
// ...
101+
}
102+
```
103+
104+
#### BullMQ config
105+
```ts
106+
const config = {
107+
queueConfig:{
108+
QueueName: 'BullMQ1',
109+
},
110+
QueueName: 'BullMQ1',
111+
producerConfig: {
112+
defaultJobOptions: {attempts: 3,
113+
backoff: {
114+
type: 'exponential',
115+
delay: 5000,
116+
},
117+
}
118+
},
119+
consumerConfig: {
120+
MaxConsumers: 1,
121+
MinConsumers: 1,
122+
},
123+
redisConfig: {
124+
host: process.env.REDIS_HOST ?? 'localhost',
125+
port: +(process.env.REDIS_PORT ?? 6379),
126+
}
127+
128+
}
129+
130+
```
131+
132+
#### Consumer setup
133+
Below is consumer handler example.
134+
```ts
135+
this.bind(BullMQBindings.BullMQConsumerProvider).toProvider(BullMQConsumerProvider);
136+
137+
this.bind(BullMQBindings.BullMQConsumerHandler).to(async (message: string) => {
138+
console.log('Processing message ---------:', message);
139+
});
140+
```

0 commit comments

Comments
 (0)