diff --git a/README.md b/README.md
index 0568394..9897831 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,7 @@
# 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,59 @@ npm i busgres
`BusgresClient` set-up & configuration:
-```
-const { BusgresClient } = require('busgres`)
-
-const sbConnectionString = process.env.CONNECTION_STRING
-
-const sbEntityName = process.env.QUEUE
-const sbEntityType = 'queue'
-
-const pgClient = {
- user: process.env.USERNAME,
- database: process.env.DATABASE,
- host: process.env.HOST,
- port: process.env.PORT
+```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']
+
+export {
+ busgresClient,
+ tableName,
+ columnNames
}
-
-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}`
- )
- })
-```
+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.
-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`:
+Starting the `BusgresClient` connection:
-```
-const tableName = 'TABLE_NAME'
-const columnNames = ['COLUMN_NAME']
+```javascript
+import {
+ busgresClient,
+ tableNames,
+ columnNames
+} from './busgres-config.js'
-bgClient.receiveMessage(tableName, columnNames)
-```
+await busgresClient.start(tableName, columnNames)
-`tableName` and `columnNames` must be defined so that they can be passed into the `receieveMessage` function.
-Disconnecting from `BusgresClient`:
+process.on('SIGINT', async () => {
+ await busgresClient.stop()
+ process.exit()
+})
```
-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,14 +75,13 @@ 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
-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
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",