1- /* Copyright (c) 2019, 2024 , Oracle and/or its affiliates. */
1+ /* Copyright (c) 2019, 2025 , Oracle and/or its affiliates. */
22
33/******************************************************************************
44 *
@@ -42,22 +42,26 @@ const oracledb = require('oracledb');
4242const dbConfig = require ( './dbconfig.js' ) ;
4343const aqUtil = require ( './aqutil.js' ) ;
4444
45- // This example requires node-oracledb Thick mode .
45+ // This example runs in both node-oracledb Thin and Thick modes .
4646//
47- // Thick mode requires Oracle Client or Oracle Instant Client libraries. On
48- // Windows and macOS you can specify the directory containing the
49- // libraries at runtime or before Node.js starts. On other platforms (where
50- // Oracle libraries are available) the system library search path must always
51- // include the Oracle library path before Node.js starts. If the search path
52- // is not correct, you will get a DPI-1047 error. See the node-oracledb
53- // installation documentation.
54- let clientOpts = { } ;
55- // On Windows and macOS platforms, set the environment variable
56- // NODE_ORACLEDB_CLIENT_LIB_DIR to the Oracle Client library path
57- if ( process . platform === 'win32' || process . platform === 'darwin' ) {
58- clientOpts = { libDir : process . env . NODE_ORACLEDB_CLIENT_LIB_DIR } ;
47+ // Optionally run in node-oracledb Thick mode
48+ if ( process . env . NODE_ORACLEDB_DRIVER_MODE === 'thick' ) {
49+
50+ // Thick mode requires Oracle Client or Oracle Instant Client libraries.
51+ // On Windows and macOS you can specify the directory containing the
52+ // libraries at runtime or before Node.js starts. On other platforms (where
53+ // Oracle libraries are available) the system library search path must always
54+ // include the Oracle library path before Node.js starts. If the search path
55+ // is not correct, you will get a DPI-1047 error. See the node-oracledb
56+ // installation documentation.
57+ let clientOpts = { } ;
58+ // On Windows and macOS platforms, set the environment variable
59+ // NODE_ORACLEDB_CLIENT_LIB_DIR to the Oracle Client library path
60+ if ( process . platform === 'win32' || process . platform === 'darwin' ) {
61+ clientOpts = { libDir : process . env . NODE_ORACLEDB_CLIENT_LIB_DIR } ;
62+ }
63+ oracledb . initOracleClient ( clientOpts ) ; // enable node-oracledb Thick mode
5964}
60- oracledb . initOracleClient ( clientOpts ) ; // enable node-oracledb Thick mode
6165
6266const queueName = "DEMO_RAW_QUEUE" ;
6367const RAW_TABLE = "NODB_RAW_QUEUE_TAB" ;
@@ -99,7 +103,10 @@ async function enq() {
99103 try {
100104 connection = await oracledb . getConnection ( credentials ) ;
101105 const queue = await connection . getQueue ( queueName ) ;
102- queue . enqOptions . visibility = oracledb . AQ_VISIBILITY_IMMEDIATE ; // Send a message without requiring a commit
106+
107+ /* Thin mode doesn't support visibility options */
108+ if ( ! oracledb . thin )
109+ queue . enqOptions . visibility = oracledb . AQ_VISIBILITY_IMMEDIATE ;
103110
104111 console . log ( 'Enqueuing 4 messages' ) ;
105112
@@ -113,6 +120,7 @@ async function enq() {
113120 "Message 4"
114121 ] ;
115122 await queue . enqMany ( messages ) ; // !! Review the enqMany() documentation's caveat before using it !!
123+ await connection . commit ( ) ; // Required for thin mode
116124
117125 } catch ( err ) {
118126 console . error ( err ) ;
@@ -132,7 +140,10 @@ async function deq() {
132140 try {
133141 connection = await oracledb . getConnection ( credentials ) ;
134142 const queue = await connection . getQueue ( queueName ) ;
135- queue . deqOptions . visibility = oracledb . AQ_VISIBILITY_IMMEDIATE ; // Change the visibility so no explicit commit is required
143+
144+ /* Thin mode doesn't support visibility options */
145+ if ( ! oracledb . thin )
146+ queue . enqOptions . visibility = oracledb . AQ_VISIBILITY_IMMEDIATE ;
136147
137148 console . log ( 'Dequeuing messages' ) ;
138149
@@ -142,6 +153,8 @@ async function deq() {
142153 console . log ( msg . payload . toString ( ) ) ;
143154 }
144155
156+ await connection . commit ( ) ; // Required for thin mode
157+
145158 } catch ( err ) {
146159 console . error ( err ) ;
147160 } finally {
0 commit comments