Skip to content

Commit 36bc6fc

Browse files
authored
WIP: Update sample code (#440)
* update doc, etc. Signed-off-by: Mark Nelson <mark.x.nelson@oracle.com>
1 parent b73fd74 commit 36bc6fc

15 files changed

+74
-219
lines changed

code-teq/javaTeq/pom.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2+
<!-- Copyright (c) 2022, Oracle and/or its affiliates. -->
3+
<!-- Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. -->
24
<project xmlns="http://maven.apache.org/POM/4.0.0"
35
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
46
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
57
<modelVersion>4.0.0</modelVersion>
68

7-
89
<groupId>com.oracle.example</groupId>
910
<artifactId>teq</artifactId>
1011
<version>0.0.1-SNAPSHOT</version>
1112
<name>teq</name>
1213
<description>TEQ examples</description>
1314

1415
<properties>
16+
<!-- Use Java 8 or later -->
1517
<maven.compiler.target>17</maven.compiler.target>
1618
<maven.compiler.source>17</maven.compiler.source>
1719
</properties>

code-teq/javaTeq/src/main/java/com/oracle/example/ConsumeTEQ.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
// Copyright (c) 2022, Oracle and/or its affiliates.
2+
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
3+
4+
// This is an example of how to consume a message from a TEQ using Java.
5+
// Please see the Maven POM file for dependencies.
6+
17
package com.oracle.example;
28

39
import java.sql.SQLException;

code-teq/javaTeq/src/main/java/com/oracle/example/CreateTEQ.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
// Copyright (c) 2022, Oracle and/or its affiliates.
2+
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
3+
4+
// This is an example of how to create a TEQ using Java.
5+
// Please see the Maven POM file for dependencies.
6+
17
package com.oracle.example;
28

39
import java.sql.SQLException;

code-teq/javaTeq/src/main/java/com/oracle/example/PublishTEQ.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
// Copyright (c) 2022, Oracle and/or its affiliates.
2+
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
3+
4+
// This is an example of how to publish a message onto a TEQ using Java.
5+
// Please see the Maven POM file for dependencies.
6+
17
package com.oracle.example;
28

39
import java.sql.SQLException;

code-teq/nodeTeq/dequeueTEQ.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1+
// Copyright (c) 2022, Oracle and/or its affiliates.
2+
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
3+
14
//
2-
// This sample demonstrates how to enqueue a message onto a TEQ using PL/SQL
5+
// This sample demonstrates how to dequeue a message from a TEQ using JavaScript/Node
36
//
47

58
// There are various payload types supported, including user-defined object, raw, JMS and JSON.
69
// This sample uses the RAW payload type.
710

811
// Execute permission on dbms_aq is required.
12+
// The node module 'oracledb' must be installed, e.g. with npm
913

1014
const oracledb = require('oracledb');
1115

code-teq/nodeTeq/enqueueTEQ.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1+
// Copyright (c) 2022, Oracle and/or its affiliates.
2+
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
3+
14
//
2-
// This sample demonstrates how to enqueue a message onto a TEQ using PL/SQL
5+
// This sample demonstrates how to enqueue a message onto a TEQ using JavaScript/Node
36
//
47

58
// There are various payload types supported, including user-defined object, raw, JMS and JSON.
69
// This sample uses the RAW payload type.
710

811
// Execute permission on dbms_aq is required.
12+
// The node module 'oracledb' must be installed, e.g. with npm
913

1014
const oracledb = require('oracledb');
1115

code-teq/plsqlTeq/cleanupTEQ.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
-- Copyright (c) 2022, Oracle and/or its affiliates.
2+
-- Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
3+
14
--
25
-- This sample demonstrates how to remove (clean up) a TEQ using PL/SQL
36
--

code-teq/plsqlTeq/createTEQ.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
-- Copyright (c) 2022, Oracle and/or its affiliates.
2+
-- Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
3+
14
--
25
-- This sample demonstrates how to create a TEQ using PL/SQL
36
--

code-teq/plsqlTeq/dequeueTEQ.sql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
-- Copyright (c) 2022, Oracle and/or its affiliates.
2+
-- Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
13
--
2-
-- This sample demonstrates how to enqueue a message onto a TEQ using PL/SQL
4+
-- This sample demonstrates how to dequeue a message from a TEQ using PL/SQL
35
--
46

57
-- There are various payload types supported, including user-defined object, raw, JMS and JSON.

code-teq/plsqlTeq/enqueueTEQ.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
-- Copyright (c) 2022, Oracle and/or its affiliates.
2+
-- Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
3+
14
--
25
-- This sample demonstrates how to enqueue a message onto a TEQ using PL/SQL
36
--

code-teq/pythonTeq/dequeueTEQ.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,41 @@
1+
# Copyright (c) 2022, Oracle and/or its affiliates.
2+
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
3+
14
#
2-
# This sample demonstrates how to enqueue a message onto a TEQ using PL/SQL
5+
# This sample demonstrates how to enqueue a message onto a TEQ using Python
36
#
47

58
# There are various payload types supported, including user-defined object, raw, JMS and JSON.
6-
# This sample uses the JSON payload type.
9+
# This sample uses the JMS payload type.
710

811
# Execute permission on dbms_aq is required.
12+
# The python package 'oracledb' must be installed (e.g. with pip)
913

1014
import oracledb
1115
from os import environ as env
1216

1317
# initialize the oracledb library, this will put us into 'thick mode' which is reqiured to use types
1418
oracledb.init_oracle_client()
1519

16-
topicName = "my_teq"
20+
topicName = "my_jms_q"
1721
consumerName = "my_subscriber"
1822

1923
# make sure that you set the environment variable DB_PASSWORD before running this
2024
connection = oracledb.connect(dsn='localhost:1521/pdb1',user='pdbadmin',password=env.get('DB_PASSWORD'))
2125

22-
# get the JMS type
26+
# get the JMS types
2327
jmsType = connection.gettype("SYS.AQ$_JMS_TEXT_MESSAGE")
2428
headerType = connection.gettype("SYS.AQ$_JMS_HEADER")
2529
userPropType = connection.gettype("SYS.AQ$_JMS_USERPROPARRAY")
2630

27-
queue = connection.queue(topicName) #, jmsType)
31+
# get the TEQ and set up the dequeue options
32+
queue = connection.queue(topicName, jmsType)
2833
queue.deqOptions.consumername = consumerName
29-
queue.deqOptions.wait = 10
34+
queue.deqOptions.wait = 10 # wait 10 seconds before giving up if no message received
3035

36+
# perform the dequeue
3137
message = queue.deqOne()
3238
connection.commit()
33-
print("message: ", message.payload.decode(connection.encoding)) #TEXT_VC)
39+
40+
# print out the payload
41+
print("message: ", message.payload.TEXT_VC)

code-teq/pythonTeq/enqueueTEQ.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,41 @@
1+
# Copyright (c) 2022, Oracle and/or its affiliates.
2+
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
3+
14
#
2-
# This sample demonstrates how to enqueue a message onto a TEQ using PL/SQL
5+
# This sample demonstrates how to enqueue a message onto a TEQ using Python
36
#
47

58
# There are various payload types supported, including user-defined object, raw, JMS and JSON.
6-
# This sample uses the JSON payload type.
9+
# This sample uses the JMS payload type.
710

811
# Execute permission on dbms_aq is required.
12+
# The python package 'oracledb' must be installed (e.g. with pip)
913

10-
import cx_Oracle
14+
import oracledb
1115
from os import environ as env
1216

17+
# initialize the oracledb library, this will put us into 'thick mode' which is reqiured to use types
18+
oracledb.init_oracle_client()
19+
1320
# make sure that you set the environment variable DB_PASSWORD before running this
14-
connection = cx_Oracle.connect(dsn='localhost:1521/pdb1',user='pdbadmin',password=env.get('DB_PASSWORD'))
21+
connection = oracledb.connect(dsn='localhost:1521/pdb1',user='pdbadmin',password=env.get('DB_PASSWORD'))
1522

1623
# get the JMS type
1724
jmsType = connection.gettype("SYS.AQ$_JMS_TEXT_MESSAGE")
1825
headerType = connection.gettype("SYS.AQ$_JMS_HEADER")
1926
userPropType = connection.gettype("SYS.AQ$_JMS_USERPROPARRAY")
2027

21-
queue = connection.queue("my_json_teq", jmsType)
28+
# get the TEQ
29+
queue = connection.queue("my_jms_q", jmsType)
2230

31+
# prepare the message and headers
2332
text = jmsType.newobject()
2433
text.HEADER = headerType.newobject()
2534
text.TEXT_VC = "hello from python"
2635
text.TEXT_LEN = len(text.TEXT_VC)
2736
text.HEADER.TYPE = "MyHeader"
2837
text.HEADER.PROPERTIES = userPropType.newobject()
2938

30-
queue.enqOne(connection.msgproperties(payload=text))
39+
# enqueue the message
40+
queue.enqOne(connection.msgproperties(payload=text,recipients=["my_subscriber"]))
3141
connection.commit()

code-teq/pythonTeq/pythonCleanupTEQ.py

Lines changed: 0 additions & 24 deletions
This file was deleted.

code-teq/pythonTeq/pythonCreateTEQ.py

Lines changed: 0 additions & 88 deletions
This file was deleted.

0 commit comments

Comments
 (0)