-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updates to the TxEventQ Java sample (#980)
* Updates
- Loading branch information
Showing
8 changed files
with
197 additions
and
186 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Transactional Event Queues (TxEventQ) example in Java | ||
|
||
Transactional Event Queues (TxEventQ) is a messaging platform built into Oracle Database that is used for application workflows, microservices, and event-triggered actions. | ||
|
||
## Setup | ||
1. Install an Oracle Database 23ai. | ||
1. Execute the `user_perm.sql` as the `SYS` or `SYSTEM` user. | ||
|
||
## Test | ||
1. Create the TxEventQ by running the `CreateTxEventQ` class. | ||
1. Publish a message to the TxEventQ by running the `PublishTxEventQ` class. | ||
1. Consume the published message by running the `ConsumeTXEventQ` class. |
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
50 changes: 26 additions & 24 deletions
50
...n/java/com/oracle/example/ConsumeTEQ.java → ...a/com/oracle/example/ConsumeTxEventQ.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
56 changes: 0 additions & 56 deletions
56
code-teq/javaTeq/src/main/java/com/oracle/example/CreateTEQ.java
This file was deleted.
Oops, something went wrong.
65 changes: 65 additions & 0 deletions
65
code-teq/javaTeq/src/main/java/com/oracle/example/CreateTxEventQ.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// 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 is an example of how to create a TEQ using Java. | ||
// Please see the Maven POM file for dependencies. | ||
|
||
package com.oracle.example; | ||
|
||
import java.sql.SQLException; | ||
|
||
import jakarta.jms.Destination; | ||
import jakarta.jms.JMSException; | ||
import jakarta.jms.Session; | ||
import jakarta.jms.TopicConnection; | ||
import jakarta.jms.TopicConnectionFactory; | ||
|
||
import oracle.AQ.AQException; | ||
import oracle.AQ.AQQueueTableProperty; | ||
import oracle.jakarta.jms.AQjmsDestination; | ||
import oracle.jakarta.jms.AQjmsFactory; | ||
import oracle.jakarta.jms.AQjmsSession; | ||
|
||
import oracle.jdbc.pool.OracleDataSource; | ||
import java.sql.Connection; | ||
|
||
public class CreateTxEventQ { | ||
|
||
private static final String username = "testuser"; | ||
private static final String url = "jdbc:oracle:thin:@//localhost:1521/freepdb1"; | ||
private static final String password = "Welcome12345"; | ||
private static final String topicName = "my_jms_teq"; | ||
|
||
public static void main(String[] args) throws AQException, SQLException, JMSException { | ||
|
||
// Create DB connection | ||
OracleDataSource ds = new OracleDataSource(); | ||
ds.setURL(url); | ||
ds.setUser(username); | ||
ds.setPassword(password); | ||
Connection con = ds.getConnection(); | ||
if (con != null) { | ||
System.out.println("Connected!"); | ||
} | ||
|
||
// create a topic session | ||
TopicConnectionFactory tcf = AQjmsFactory.getTopicConnectionFactory(ds); | ||
TopicConnection conn = tcf.createTopicConnection(); | ||
conn.start(); | ||
AQjmsSession session = (AQjmsSession) conn.createSession(true, Session.AUTO_ACKNOWLEDGE); | ||
|
||
// create properties | ||
AQQueueTableProperty props = new AQQueueTableProperty("SYS.AQ$_JMS_TEXT_MESSAGE"); | ||
props.setMultiConsumer(true); | ||
props.setPayloadType("SYS.AQ$_JMS_TEXT_MESSAGE"); | ||
|
||
// create queue table, topic and start it | ||
Destination myTeq = session.createJMSTransactionalEventQueue(topicName, true); | ||
((AQjmsDestination) myTeq).start(session, true, true); | ||
|
||
if (con != null && !con.isClosed()) { | ||
con.close(); | ||
} | ||
} | ||
|
||
} |
63 changes: 0 additions & 63 deletions
63
code-teq/javaTeq/src/main/java/com/oracle/example/PublishTEQ.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.