From 48dbf1ec8c21726d0a26d2bbe0dd242ffbaa570f Mon Sep 17 00:00:00 2001 From: Rana Salem Date: Thu, 10 Jul 2025 16:03:27 +0100 Subject: [PATCH 1/5] update readme --- README.md | 105 ++++++++++++++++++++---------------------------------- 1 file changed, 39 insertions(+), 66 deletions(-) diff --git a/README.md b/README.md index 0568394..3b323a0 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Busgres -Service BUS + PostGRES = Busgres +Service BUS + PostGRES = Busgres -[Busgres](https://www.npmjs.com/package/busgres) is a Node.js package that will receieve a message from an Azure Service Bus queue or topic and save it into a PostgreSQL database. It abstracts the [`@azure/service-bus`](https://www.npmjs.com/package/@azure/service-bus) the [`pg` (node-postgres)](https://www.npmjs.com/package/pg) package for Service Bus and Postgres integration. +[Busgres](https://www.npmjs.com/package/busgres) is a Node.js package that will receive a message from an Azure Service Bus queue or topic and save it into a PostgreSQL database. It abstracts the [`@azure/service-bus`](https://www.npmjs.com/package/@azure/service-bus) and [`pg` (node-postgres)](https://www.npmjs.com/package/pg) packages for Service Bus and Postgres integration. ## Installation @@ -15,80 +15,53 @@ npm i busgres `BusgresClient` set-up & configuration: +```javascript +import { BusgresClient } from 'busgres' +import 'dotenv/config' + +const busgresClient = new BusgresClient({ + serviceBus: { + connectionString: process.env.SB_CONNECTION_STRING, + entity: process.env.SB_ENTITY, + entityType: 'queue' + }, + postgres: { + username: process.env.PG_USERNAME, + password: process.env.PG_PASSWORD, + database: process.env.PG_DATABASE, + host: process.env.PG_HOST, + port: process.env.PG_PORT + } +}) + +const tableName = 'busgres' +const columnNames = ['message'] ``` -const { BusgresClient } = require('busgres`) -const sbConnectionString = process.env.CONNECTION_STRING +NOTE: If using topics, provide the topic name for `sbEntityName` in place of a queue name. Additionally, ensure `sbEntityType` is set to `'topic'` and that a value for `sbEntitySubscription` is also provided. -const sbEntityName = process.env.QUEUE -const sbEntityType = 'queue' +Starting the `BusgresClient` connection: -const pgClient = { - user: process.env.USERNAME, - database: process.env.DATABASE, - host: process.env.HOST, - port: process.env.PORT -} +```javascript +import { + busgresClient, + tableNames, + columnNames +} from './busgres-config.js' -const bgClient = new BusgresClient(sbConnectionString, sbEntityName, sbEntityType, pgClient) -``` - -NOTE: If using topics, provide the topic name for `sbEntityName` in place of a queue name. Additionally, ensure `sbEntityType` is set to `'topic'` and that a value for `sbEntitySubscription` is also provided. - -Connecting to `BusgresClient`: - -``` -bgClient - .connect() - .then(async () => { - console.log( - `You are now connected to the ${process.env.DATABASE} database in PostgreSQL.` - ) - - const query = 'SELECT * FROM TABLE_NAME' - const result = await bgClient.pgClient.query(query) - console.log('All messages in the database:') - - result.rows.forEach((row, index) => { - console.log(`Row ${index + 1}:`, row) - }) - }) - .catch((error) => { - console.error( - `There has been an error connecting to your PostgreSQL database: ${error}` - ) - }) -``` +await busgresClient.start(tableName, columnNames) -The above example will confirm a connection has been established via the `BusgresClient` and will select all content from any table in the PostgreSQL database to then log it into the console (not necessary, just further confirms the PostgreSQL connection is active).

-Receiving and saving messages via `receiveMessage`: - -``` -const tableName = 'TABLE_NAME' -const columnNames = ['COLUMN_NAME'] +process.on('SIGINT', async () => { + await busgresClient.stop() + process.exit() +}) -bgClient.receiveMessage(tableName, columnNames) ``` - -`tableName` and `columnNames` must be defined so that they can be passed into the `receieveMessage` function.

-Disconnecting from `BusgresClient`: - -``` -bgClient.disconnect() -``` - -When called the connection to PostgreSQL will be terminated and will also close the Service Bus client & receiver. Messages can no longer be received from Service Bus nor saved to the PostgreSQL database. - -## Configuration - -`BusgresClient` - Client that contains the configuration for both Azure Service Bus & PostgreSQL. Arguments passed into the constructor of the `BusgresClient` include the Service Bus connection string (`sbConnectionString`), Service Bus entity (`sbEntityName`) i.e. name of the queue or topic, Service Bus entity type (either `'queue'` or `'topic'`), Service Bus entity subscription (name of the subscription if using topic), and the PostgreSQL client configuration (`pgClient`).

-`connect` - When called will establish connection to the PostgreSQL database.

-`saveMessage` & `receiveMessage` - Logic for inserting messages received from a Service Bus entity into a table within a PostgreSQL database.

-`disconnect` - When called will terminate the connection to PostgreSQL and close the Service Bus client and entity. +With the above set-up and configuration a basic working `BusgresClient` connection can be established. ## Demo -A simple demo Node.js application called [busgres-demo](https://github.com/rtasalem/busgres-demo) was created to test the functionality of this package during its development and to provide further example of usage. +A simple demo Node.js application, [busgres-demo](https://github.com/rtasalem/busgres-demo) was created to test the functionality of this package during its development and to provide further example of usage. ## License @@ -96,7 +69,7 @@ This package is licensed under the MIT License. Refer to the [LICENSE](https://g ## Feedback -Feel free to reach out if you have any suggestions for improvement. A [contributor's guide](https://github.com/rtasalem/busgres/blob/main/CONTRIBUTORS-GUIDE.md) is also available. +Feel free to reach out if you have any suggestions for improvement or further development. ## Dependencies From 48042a3b64314cf86f12dd1b96114acc962154aa Mon Sep 17 00:00:00 2001 From: Rana Salem Date: Thu, 10 Jul 2025 16:03:41 +0100 Subject: [PATCH 2/5] bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3b44b2f..bf56792 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "busgres", - "version": "5.0.0", + "version": "5.0.2", "description": "Busgres is an NPM package for receiving messages from Service Bus and saving them into a PostgreSQL database.", "main": "index.js", "type": "module", From a22cfcdcd943a4dc3f4f8fb218d4d586217cb478 Mon Sep 17 00:00:00 2001 From: Rana Salem Date: Thu, 10 Jul 2025 16:06:53 +0100 Subject: [PATCH 3/5] remove underlines from readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3b323a0..b17e770 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # Busgres -Service BUS + PostGRES = Busgres +Service BUS + PostGRES = Busgres [Busgres](https://www.npmjs.com/package/busgres) is a Node.js package that will receive a message from an Azure Service Bus queue or topic and save it into a PostgreSQL database. It abstracts the [`@azure/service-bus`](https://www.npmjs.com/package/@azure/service-bus) and [`pg` (node-postgres)](https://www.npmjs.com/package/pg) packages for Service Bus and Postgres integration. From 9071aa75da2a7d5934170553d620418732145cf2 Mon Sep 17 00:00:00 2001 From: Rana Salem Date: Thu, 10 Jul 2025 16:07:57 +0100 Subject: [PATCH 4/5] update readme --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index b17e770..430797a 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,12 @@ const busgresClient = new BusgresClient({ const tableName = 'busgres' const columnNames = ['message'] + +export { + busgresClient, + tableName, + columnNames +} ``` NOTE: If using topics, provide the topic name for `sbEntityName` in place of a queue name. Additionally, ensure `sbEntityType` is set to `'topic'` and that a value for `sbEntitySubscription` is also provided. From 6a229395d0c1144661398281bcaedc343751367c Mon Sep 17 00:00:00 2001 From: Rana Salem Date: Thu, 10 Jul 2025 16:09:57 +0100 Subject: [PATCH 5/5] update readme --- README.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 430797a..9897831 100644 --- a/README.md +++ b/README.md @@ -79,10 +79,9 @@ Feel free to reach out if you have any suggestions for improvement or further de ## Dependencies -This package has a total of 2 dependencies on the following: - -- [`@azure/service-bus`](https://www.npmjs.com/package/@azure/service-bus) -- [`pg`](https://www.npmjs.com/package/pg) +This package has a total of 2 dependencies on the following: +[@azure/service-bus](https://www.npmjs.com/package/@azure/service-bus) +[pg](https://www.npmjs.com/package/pg) ## Author