|
| 1 | +<!-- |
| 2 | +Copyright (c) 2021 Oracle and/or its affiliates. |
| 3 | +
|
| 4 | +The Universal Permissive License (UPL), Version 1.0 |
| 5 | +
|
| 6 | +Subject to the condition set forth below, permission is hereby granted to any |
| 7 | +person obtaining a copy of this software, associated documentation and/or data |
| 8 | +(collectively the "Software"), free of charge and under any and all copyright |
| 9 | +rights in the Software, and any and all patent rights owned or freely |
| 10 | +licensable by each licensor hereunder covering either (i) the unmodified |
| 11 | +Software as contributed to or provided by such licensor, or (ii) the Larger |
| 12 | +Works (as defined below), to deal in both |
| 13 | +
|
| 14 | +(a) the Software, and |
| 15 | +(b) any piece of software and/or hardware listed in the lrgrwrks.txt file if |
| 16 | +one is included with the Software (each a "Larger Work" to which the Software |
| 17 | +is contributed by such licensors), |
| 18 | +
|
| 19 | +without restriction, including without limitation the rights to copy, create |
| 20 | +derivative works of, display, perform, and distribute the Software and make, |
| 21 | +use, sell, offer for sale, import, export, have made, and have sold the |
| 22 | +Software and the Larger Work(s), and to sublicense the foregoing rights on |
| 23 | +either these or other terms. |
| 24 | +
|
| 25 | +This license is subject to the following condition: |
| 26 | +The above copyright notice and either this complete permission notice or at |
| 27 | +a minimum a reference to the UPL must be included in all copies or |
| 28 | +substantial portions of the Software. |
| 29 | +
|
| 30 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 31 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 32 | +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 33 | +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 34 | +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 35 | +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 36 | +SOFTWARE. |
| 37 | +--> |
| 38 | + |
| 39 | +## OCI Queue example in NodeJS with GitHub Actions |
| 40 | + |
| 41 | +### OCI Queue |
| 42 | + |
| 43 | +Create Queue and copy the Queue OCID and Enpoint: |
| 44 | + |
| 45 | +<p> |
| 46 | +<img src="endpoint.png" width="800" /> |
| 47 | + |
| 48 | +<p> |
| 49 | +When using another <code>region</code> than <code>EU_FRANKFURT_1</code> please modify the |
| 50 | +<a href="https://github.com/mikarinneoracle/oci-queue-node/blob/main/index.js#L10"> |
| 51 | +<code>index.js</code></a> Line #10 accordingly: |
| 52 | + |
| 53 | +<pre> |
| 54 | +const region = common.Region.EU_FRANKFURT_1; |
| 55 | +</pre> |
| 56 | + |
| 57 | +### Policies |
| 58 | + |
| 59 | +Setup policies for your user in the tenancy |
| 60 | + |
| 61 | +e.g. <code>Allow <USER_GROUP> to manage queues in compartment <COMPARTMENT></code> |
| 62 | + |
| 63 | +More on OCI Queue IAM policies: https://docs.oracle.com/en-us/iaas/Content/queue/policy-reference.htm |
| 64 | + |
| 65 | +### Secrets |
| 66 | + |
| 67 | +Setup secrets to run this example with GitHub Actions: |
| 68 | + |
| 69 | +<ul> |
| 70 | + <li><b>OCI_TENANCY</b>: OCI Tenancy OCID</li> |
| 71 | + <li><b>OCI_USER</b>: OCI User OCID</li> |
| 72 | + <li><b>OCI_FINGERPRINT</b>: OCI User Fingerprint</li> |
| 73 | + <li><b>OCI_KEY</b>: OCI User Private Key</li> |
| 74 | + <li><b>OCI_PASSPHRASE</b>: OCI User Private Key passphrase (optional)</li> |
| 75 | + <li><b>Q_ID</b>: OCI Queue OCID</li> |
| 76 | + <li><b>Q_ENDPOINT</b>OCI Queue Endpoint</li> |
| 77 | +</ul> |
| 78 | + |
| 79 | +### Run Action |
| 80 | + |
| 81 | +Monitor the GitHub action to run: |
| 82 | + |
| 83 | +<p> |
| 84 | +<img src="action.png" width="800" /> |
| 85 | + |
| 86 | +<p> |
| 87 | +This example will poll for messages in the queue and finally writes a new message to it. |
| 88 | + |
| 89 | +### View messages in the Queue |
| 90 | + |
| 91 | +<img src="messages.png" width="800" /> |
| 92 | + |
| 93 | +### Running locally |
| 94 | + |
| 95 | +Clone this repo, setup npm and <code>oci cli</code> and modify <a href="https://github.com/mikarinneoracle/oci-queue-node/blob/main/index.js#L8">index.js</a> line 8 by uncommenting it and removing/commenting lines 10-18 and replace lines 21-22 |
| 96 | +with Queue details : |
| 97 | + |
| 98 | +<pre> |
| 99 | +// Use this locally instead of env vars and region: |
| 100 | +const provider = new common.ConfigFileAuthenticationDetailsProvider(); |
| 101 | + |
| 102 | +// Q settings |
| 103 | +const queueId = 'ocid1.queue.oc1.eu-frankfurt-1.ama....a5z4ic2tslq'; |
| 104 | +const endpoint = 'https://cell-1.queue......oci.oraclecloud.com'; |
| 105 | +</pre> |
| 106 | + |
| 107 | +Then run: |
| 108 | + |
| 109 | +<pre> |
| 110 | +npm install |
| 111 | +node index.js |
| 112 | +</pre> |
| 113 | + |
| 114 | +### Sending messages to Queue |
| 115 | + |
| 116 | +You can manually send messages to the queue using the OCI Queue Console |
| 117 | +<code>Actions/Send Message</code> and then see them being received by re-running the build. |
| 118 | + |
| 119 | +<p> |
| 120 | +You can also play with the queue's <code>Dead Letter Queue</code> settings to see how many |
| 121 | +times the same message is being received (default is 5). To do this comment the |
| 122 | +<a href="index.js#L61">line 61 of the index.js</a> and re-run the build using commit. |
0 commit comments