Service BUS + PostGRES = Busgres
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 and pg (node-postgres) packages for Service Bus and Postgres integration.
For the best experience, use only Busgres v5.0.3 and above.
This package can be installed using NPM:
npm i busgres
BusgresClient set-up & configuration:
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
}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.
Starting the BusgresClient connection:
import {
busgresClient,
tableNames,
columnNames
} from './busgres-config.js'
await busgresClient.start(tableName, columnNames)
process.on('SIGINT', async () => {
await busgresClient.stop()
process.exit()
})With the above set-up and configuration a basic working BusgresClient connection can be established.
A simple demo Node.js application, busgres-demo, was created to test the functionality of this package during its development and to provide further example of usage.
This package is licensed under the MIT License.
Feel free to reach out if you have any suggestions for improvement or further development.
This package has a total of 2 dependencies on the following: