forked from oracle/microservices-datadriven
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: Update sample code (oracle#440)
* update doc, etc. Signed-off-by: Mark Nelson <[email protected]>
- Loading branch information
1 parent
b73fd74
commit 36bc6fc
Showing
15 changed files
with
74 additions
and
219 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
code-teq/javaTeq/src/main/java/com/oracle/example/ConsumeTEQ.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
code-teq/javaTeq/src/main/java/com/oracle/example/CreateTEQ.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
code-teq/javaTeq/src/main/java/com/oracle/example/PublishTEQ.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,41 @@ | ||
# Copyright (c) 2022, Oracle and/or its affiliates. | ||
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. | ||
|
||
# | ||
# This sample demonstrates how to enqueue a message onto a TEQ using PL/SQL | ||
# This sample demonstrates how to enqueue a message onto a TEQ using Python | ||
# | ||
|
||
# There are various payload types supported, including user-defined object, raw, JMS and JSON. | ||
# This sample uses the JSON payload type. | ||
# This sample uses the JMS payload type. | ||
|
||
# Execute permission on dbms_aq is required. | ||
# The python package 'oracledb' must be installed (e.g. with pip) | ||
|
||
import oracledb | ||
from os import environ as env | ||
|
||
# initialize the oracledb library, this will put us into 'thick mode' which is reqiured to use types | ||
oracledb.init_oracle_client() | ||
|
||
topicName = "my_teq" | ||
topicName = "my_jms_q" | ||
consumerName = "my_subscriber" | ||
|
||
# make sure that you set the environment variable DB_PASSWORD before running this | ||
connection = oracledb.connect(dsn='localhost:1521/pdb1',user='pdbadmin',password=env.get('DB_PASSWORD')) | ||
|
||
# get the JMS type | ||
# get the JMS types | ||
jmsType = connection.gettype("SYS.AQ$_JMS_TEXT_MESSAGE") | ||
headerType = connection.gettype("SYS.AQ$_JMS_HEADER") | ||
userPropType = connection.gettype("SYS.AQ$_JMS_USERPROPARRAY") | ||
|
||
queue = connection.queue(topicName) #, jmsType) | ||
# get the TEQ and set up the dequeue options | ||
queue = connection.queue(topicName, jmsType) | ||
queue.deqOptions.consumername = consumerName | ||
queue.deqOptions.wait = 10 | ||
queue.deqOptions.wait = 10 # wait 10 seconds before giving up if no message received | ||
|
||
# perform the dequeue | ||
message = queue.deqOne() | ||
connection.commit() | ||
print("message: ", message.payload.decode(connection.encoding)) #TEXT_VC) | ||
|
||
# print out the payload | ||
print("message: ", message.payload.TEXT_VC) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,41 @@ | ||
# Copyright (c) 2022, Oracle and/or its affiliates. | ||
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. | ||
|
||
# | ||
# This sample demonstrates how to enqueue a message onto a TEQ using PL/SQL | ||
# This sample demonstrates how to enqueue a message onto a TEQ using Python | ||
# | ||
|
||
# There are various payload types supported, including user-defined object, raw, JMS and JSON. | ||
# This sample uses the JSON payload type. | ||
# This sample uses the JMS payload type. | ||
|
||
# Execute permission on dbms_aq is required. | ||
# The python package 'oracledb' must be installed (e.g. with pip) | ||
|
||
import cx_Oracle | ||
import oracledb | ||
from os import environ as env | ||
|
||
# initialize the oracledb library, this will put us into 'thick mode' which is reqiured to use types | ||
oracledb.init_oracle_client() | ||
|
||
# make sure that you set the environment variable DB_PASSWORD before running this | ||
connection = cx_Oracle.connect(dsn='localhost:1521/pdb1',user='pdbadmin',password=env.get('DB_PASSWORD')) | ||
connection = oracledb.connect(dsn='localhost:1521/pdb1',user='pdbadmin',password=env.get('DB_PASSWORD')) | ||
|
||
# get the JMS type | ||
jmsType = connection.gettype("SYS.AQ$_JMS_TEXT_MESSAGE") | ||
headerType = connection.gettype("SYS.AQ$_JMS_HEADER") | ||
userPropType = connection.gettype("SYS.AQ$_JMS_USERPROPARRAY") | ||
|
||
queue = connection.queue("my_json_teq", jmsType) | ||
# get the TEQ | ||
queue = connection.queue("my_jms_q", jmsType) | ||
|
||
# prepare the message and headers | ||
text = jmsType.newobject() | ||
text.HEADER = headerType.newobject() | ||
text.TEXT_VC = "hello from python" | ||
text.TEXT_LEN = len(text.TEXT_VC) | ||
text.HEADER.TYPE = "MyHeader" | ||
text.HEADER.PROPERTIES = userPropType.newobject() | ||
|
||
queue.enqOne(connection.msgproperties(payload=text)) | ||
# enqueue the message | ||
queue.enqOne(connection.msgproperties(payload=text,recipients=["my_subscriber"])) | ||
connection.commit() |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.