mikarinneoracle / oci-queue-node

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

OCI Queue example in NodeJS with GitHub Actions

OCI Queue

Create Queue and copy the Queue OCID and Enpoint:

When using another region than EU_FRANKFURT_1 please modify the index.js Line #10 accordingly:

const region = common.Region.EU_FRANKFURT_1;

Policies

Setup policies for your user in the tenancy

e.g. Allow <USER_GROUP> to manage queues in compartment <COMPARTMENT>

More on OCI Queue IAM policies: https://docs.oracle.com/en-us/iaas/Content/queue/policy-reference.htm

Secrets

Setup secrets to run this example with GitHub Actions:

  • OCI_TENANCY: OCI Tenancy OCID
  • OCI_USER: OCI User OCID
  • OCI_FINGERPRINT: OCI User Fingerprint
  • OCI_KEY: OCI User Private Key
  • OCI_PASSPHRASE: OCI User Private Key passphrase (optional)
  • Q_ID: OCI Queue OCID
  • Q_ENDPOINTOCI Queue Endpoint

Run Action

Monitor the GitHub action to run:

This example will poll for messages in the queue and finally writes a new message to it.

View messages in the Queue

Running locally

Clone this repo, setup npm and oci cli and modify index.js line 8 by uncommenting it and removing/commenting lines 10-18 and replace lines 21-22 with Queue details :

// Use this locally instead of env vars and region:
const provider = new common.ConfigFileAuthenticationDetailsProvider();

// Q settings
const queueId = 'ocid1.queue.oc1.eu-frankfurt-1.ama....a5z4ic2tslq';
const endpoint = 'https://cell-1.queue.messaging.eu-frankfurt-1.oci.oraclecloud.com';

Then run:

npm install
node index.js

Sending messages to Queue

You can manually send messages to the queue using the OCI Queue Console
Actions/Send Message and then see them being received by re-running the build.

You can also play with the queue's Dead Letter Queue settings to see how many times the same message is being received (default is 5). To do this comment the line 61 of the index.js and re-run the build using commit.

About


Languages

Language:JavaScript 100.0%