Skip to content

Commit 604b7d7

Browse files
committed
TxEventQ JMS Sample
1 parent 0c6ea40 commit 604b7d7

File tree

14 files changed

+390
-5
lines changed

14 files changed

+390
-5
lines changed

database/starters/oracle-spring-boot-starter-samples/README.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,24 @@
22

33
The Oracle Database Spring Boot Samples module provides a suite of comprehensive Spring Boot sample applications designed to enable developers with example code for application development.
44

5-
### [Oracle UCP with JPA Sample](./oracle-spring-boot-sample-ucp-jpa/README.md)
5+
## [Oracle UCP with JPA Sample](./oracle-spring-boot-sample-ucp-jpa/README.md)
66

77
The Oracle UCP with JPA sample application demonstrates how to use the Oracle Spring Boot Starter UCP with Spring Data JPA, connecting your Oracle Database with powerful ORM abstractions that facilitate rapid development, all while using the best connection pooling library for Oracle Database with Spring Boot.
88

9-
### [JSON Relational Duality Views Sample](./oracle-spring-boot-sample-json-duality/README.md)
9+
## [JSON Relational Duality Views Sample](./oracle-spring-boot-sample-json-duality/README.md)
1010

1111
The JSON Relational Duality Views sample application demonstrates how to use the Oracle Spring Boot Starter JSON Collections with [JSON Relational Duality Views](https://docs.oracle.com/en/database/oracle/oracle-database/23/jsnvu/overview-json-relational-duality-views.html). JSON Relational Duality Views layer the advantages of JSON document-style database over existing relational data structures — Powerful JSON views with full CRUD capabilities can be created on relational database schemas, nesting related data into a single document with unified access.
1212

13-
### [Kafka Java Client for Oracle Database Transactional Event Queues Sample](./oracle-spring-boot-starter-okafka/README.md)
13+
## [Kafka Java Client for Oracle Database Transactional Event Queues Sample](./oracle-spring-boot-starter-okafka/README.md)
1414

1515
This sample application demonstrates how to use the Oracle Spring Boot Starter for the [Kafka Java Client for Oracle Database Transactional Event Queues](https://github.com/oracle/okafka)
1616

1717
Using an in-database message broker like Oracle Database Transactional Event Queues eliminates the need for external message brokers, reduces overall network traffic, simplifying your overall application architecture — and the Kafka Java Client for Oracle Database Transactional Event Queues library enables developers to create applications for Oracle Database Transactional Event Queues using familiar Kafka APIs for messaging.
1818

19-
### [Oracle UCP using Wallet](./oracle-spring-boot-sample-wallet)
19+
## [Oracle UCP using Wallet](./oracle-spring-boot-sample-wallet)
2020

21-
This sample application demonstrates how to connect to an Autonomous database using the Oracle Spring Boot Starter UCP and Oracle Spring Boot Starter Wallet all while using the best connection pooling library for Oracle Database with Spring Boot.
21+
This sample application demonstrates how to connect to an Autonomous database using the Oracle Spring Boot Starter UCP and Oracle Spring Boot Starter Wallet all while using the best connection pooling library for Oracle Database with Spring Boot.
22+
23+
## [Oracle Transactional Event Queues Producer and Consumer Example](./oracle-spring-boot-starter-sample-txeventqjms/)
24+
25+
This sample demonstrates how to use [Transactional Event Queues (TxEventQ)](https://docs.oracle.com/en/database/oracle/oracle-database/23/adque/aq-introduction.html) and JMS using the Oracle Spring Boot Starter AQJMS. The sample has a Consumer and a Producer application. The Producer application puts messages on a TxEventQ and the Consumer application listens on the TxEventQ using a JMSListener.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Oracle Transactional Event Queues (TxEventQ) Producer and Consumer Example
2+
3+
[Transactional Event Queues (TxEventQ)](https://docs.oracle.com/en/database/oracle/oracle-database/23/adque/aq-introduction.html) is a messaging platform built into Oracle Database that is used for application workflows, microservices, and event-triggered actions.
4+
5+
This sample demonstrates how to use [Transactional Event Queues (TxEventQ)](https://docs.oracle.com/en/database/oracle/oracle-database/23/adque/aq-introduction.html) and JMS using the Oracle Spring Boot Starter AQJMS. The sample has a Consumer and a Producer application. The Producer application puts messages on a TxEventQ and the Consumer application listens on the TxEventQ using a JMSListener.
6+
7+
## Install an Oracle Database 23ai
8+
9+
Install an Oracle Database 23ai. This sample is using a Docker Container but any Oracle Database 23ai will work. Install and start the database using the following command:
10+
11+
```shell
12+
docker run --name free23ai -d -p 1521:1521 -e ORACLE_PWD=Welcome12345 \
13+
container-registry.oracle.com/database/free:latest-lite
14+
```
15+
16+
## Create user and the Transactional Event Queue (TxEventQ)
17+
18+
Log into the database as the `SYS` user and run the SQL script `setup.sql` located in the `sql` directory. The script creates a user called `TESTUSER` and a TxEventQ called `my-txeventq`.
19+
20+
## Start the Consumer application
21+
22+
Open a terminal window and go to the `consumer` directory and run `mvn spring-boot:run`. This will start the Consumer application that will listen to the TxEventQ `my_txeventq`.
23+
24+
## Start the Producer application
25+
26+
Open a terminal window and go to the `producer` directory and run `mvn spring-boot:run`. This will start the Producer application which will send messaged to the TxEventQ `my_txeventq`.
27+
28+
## Send a message
29+
30+
Open a terminal window and execute the following command to send a message via the Producer `/api/v1/message` endpoint:
31+
32+
```shell
33+
curl -X POST http://localhost:8080/api/v1/message?message=MyMessage
34+
```
35+
36+
The command returns the message `Message was sent successfully`.
37+
38+
In the Producer terminal window you will get a notification that looks like this:
39+
40+
```log
41+
2024-11-01T14:07:40.549-05:00 INFO 94573 --- [producer] [nio-8080-exec-2] c.o.d.s.t.producer.service.Producer : Sending message: MyMessage to topic my_txeventq
42+
```
43+
44+
In the Consumer terminal window you will get a notification that looks like this:
45+
46+
```log
47+
2024-11-01T14:07:40.548-05:00 INFO 94524 --- [consumer] [ntContainer#0-1] c.o.d.s.t.consumer.service.Consumer : Received message: MyMessage
48+
```
49+
50+
## Configure your project to use Oracle Spring Boot Starter for TxEventQ and JMS
51+
52+
To use Oracle Spring Boot Starter for TxEventQ and JMS for your Spring Boot application, add the following Maven dependency to your project:
53+
54+
```xml
55+
<dependency>
56+
<groupId>com.oracle.database.spring</groupId>
57+
<artifactId>oracle-spring-boot-starter-aqjms</artifactId>
58+
</dependency>
59+
```
60+
61+
or if you are using Gradle:
62+
63+
```text
64+
implementation 'com.oracle.database.spring:oracle-spring-boot-starter-aqjms:24.3.0'
65+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!-- Copyright (c) 2024, Oracle and/or its affiliates. -->
3+
<!-- Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. -->
4+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
6+
<modelVersion>4.0.0</modelVersion>
7+
<parent>
8+
<artifactId>oracle-spring-boot-starter-samples</artifactId>
9+
<groupId>com.oracle.database.spring</groupId>
10+
<version>24.3.0</version>
11+
<relativePath>../../pom.xml</relativePath>
12+
</parent>
13+
14+
<artifactId>oracle-spring-boot-sample-txeventqjms-consumer</artifactId>
15+
<version>24.3.0</version>
16+
17+
<name>Oracle Spring Boot Starter - Transactional Event Queue JMS Sample</name>
18+
<description>Oracle Spring Boot Starter - Transactional Event Queue JMS Sample</description>
19+
20+
<organization>
21+
<name>Oracle America, Inc.</name>
22+
<url>https://www.oracle.com</url>
23+
</organization>
24+
25+
<developers>
26+
<developer>
27+
<name>Oracle</name>
28+
<email>obaas_ww at oracle.com</email>
29+
<organization>Oracle America, Inc.</organization>
30+
<organizationUrl>https://www.oracle.com</organizationUrl>
31+
</developer>
32+
</developers>
33+
34+
<licenses>
35+
<license>
36+
<name>The Universal Permissive License (UPL), Version 1.0</name>
37+
<url>https://oss.oracle.com/licenses/upl/</url>
38+
<distribution>repo</distribution>
39+
</license>
40+
</licenses>
41+
42+
<scm>
43+
<url>https://github.com/oracle/spring-cloud-oracle</url>
44+
<connection>scm:git:https://github.com/oracle/spring-cloud-oracle.git</connection>
45+
<developerConnection>scm:git:git@github.com:oracle/spring-cloud-oracle.git</developerConnection>
46+
</scm>
47+
48+
<dependencies>
49+
<dependency>
50+
<groupId>org.springframework.boot</groupId>
51+
<artifactId>spring-boot-starter-jdbc</artifactId>
52+
</dependency>
53+
<dependency>
54+
<groupId>com.oracle.database.spring</groupId>
55+
<artifactId>oracle-spring-boot-starter-aqjms</artifactId>
56+
<version>${project.version}</version>
57+
</dependency>
58+
</dependencies>
59+
60+
<build>
61+
<plugins>
62+
<plugin>
63+
<groupId>org.springframework.boot</groupId>
64+
<artifactId>spring-boot-maven-plugin</artifactId>
65+
</plugin>
66+
</plugins>
67+
</build>
68+
69+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.oracle.database.spring.txeventqjms.consumer;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class ConsumerApplication {
8+
9+
public static void main(String[] args) {
10+
SpringApplication.run(ConsumerApplication.class, args);
11+
}
12+
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.oracle.database.spring.txeventqjms.consumer.service;
2+
3+
import org.slf4j.Logger;
4+
import org.slf4j.LoggerFactory;
5+
import org.springframework.jms.annotation.JmsListener;
6+
import org.springframework.stereotype.Service;
7+
8+
@Service
9+
public class Consumer {
10+
11+
private static final Logger log = LoggerFactory.getLogger(Consumer.class);
12+
13+
@JmsListener(destination = "${txeventq.topic.name}")
14+
public void receiveMessage(String message) {
15+
log.info("Received message: {}", message);
16+
}
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
spring:
2+
application:
3+
name: consumer
4+
5+
datasource:
6+
url: jdbc:oracle:thin:@//localhost:1521/freepdb1
7+
username: testuser
8+
password: Welcome12345
9+
driver-class-name: oracle.jdbc.OracleDriver
10+
type: oracle.ucp.jdbc.PoolDataSource
11+
oracleucp:
12+
connection-factory-class-name: oracle.jdbc.pool.OracleDataSource
13+
connection-pool-name: ConsumerConnectionPool
14+
initial-pool-size: 15
15+
min-pool-size: 10
16+
max-pool-size: 30
17+
18+
txeventq:
19+
topic:
20+
name: my_txeventq
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
____
2+
/ ___|___ _ __ ___ _ _ _ __ ___ ___ _ __
3+
| | / _ \| '_ \/ __| | | | '_ ` _ \ / _ \ '__|
4+
| |__| (_) | | | \__ \ |_| | | | | | | __/ |
5+
\____\___/|_| |_|___/\__,_|_| |_| |_|\___|_|
6+
7+
Powered by Spring Boot ${spring-boot.version}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!-- Copyright (c) 2024, Oracle and/or its affiliates. -->
3+
<!-- Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. -->
4+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
6+
<modelVersion>4.0.0</modelVersion>
7+
<parent>
8+
<artifactId>oracle-spring-boot-starter-samples</artifactId>
9+
<groupId>com.oracle.database.spring</groupId>
10+
<version>24.3.0</version>
11+
<relativePath>../../pom.xml</relativePath>
12+
</parent>
13+
14+
<artifactId>oracle-spring-boot-sample-txeventqjms-producer</artifactId>
15+
<version>24.3.0</version>
16+
17+
<name>Oracle Spring Boot Starter - Transactional Event Queue JMS Sample</name>
18+
<description>Oracle Spring Boot Starter - Transactional Event Queue JMS Sample</description>
19+
20+
<organization>
21+
<name>Oracle America, Inc.</name>
22+
<url>https://www.oracle.com</url>
23+
</organization>
24+
25+
<developers>
26+
<developer>
27+
<name>Oracle</name>
28+
<email>obaas_ww at oracle.com</email>
29+
<organization>Oracle America, Inc.</organization>
30+
<organizationUrl>https://www.oracle.com</organizationUrl>
31+
</developer>
32+
</developers>
33+
34+
<licenses>
35+
<license>
36+
<name>The Universal Permissive License (UPL), Version 1.0</name>
37+
<url>https://oss.oracle.com/licenses/upl/</url>
38+
<distribution>repo</distribution>
39+
</license>
40+
</licenses>
41+
42+
<scm>
43+
<url>https://github.com/oracle/spring-cloud-oracle</url>
44+
<connection>scm:git:https://github.com/oracle/spring-cloud-oracle.git</connection>
45+
<developerConnection>scm:git:git@github.com:oracle/spring-cloud-oracle.git</developerConnection>
46+
</scm>
47+
48+
<dependencies>
49+
<dependency>
50+
<groupId>org.springframework.boot</groupId>
51+
<artifactId>spring-boot-starter-jdbc</artifactId>
52+
</dependency>
53+
<dependency>
54+
<groupId>org.springframework.boot</groupId>
55+
<artifactId>spring-boot-starter-web</artifactId>
56+
</dependency>
57+
<dependency>
58+
<groupId>com.oracle.database.spring</groupId>
59+
<artifactId>oracle-spring-boot-starter-aqjms</artifactId>
60+
<version>${project.version}</version>
61+
</dependency>
62+
</dependencies>
63+
64+
<build>
65+
<plugins>
66+
<plugin>
67+
<groupId>org.springframework.boot</groupId>
68+
<artifactId>spring-boot-maven-plugin</artifactId>
69+
</plugin>
70+
</plugins>
71+
</build>
72+
73+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.oracle.database.spring.txeventq.producer;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class ProducerApplication {
8+
9+
public static void main(String[] args) {
10+
SpringApplication.run(ProducerApplication.class, args);
11+
}
12+
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.oracle.database.spring.txeventq.producer.controller;
2+
3+
import com.oracle.database.spring.txeventq.producer.service.Producer;
4+
import org.springframework.web.bind.annotation.PostMapping;
5+
import org.springframework.web.bind.annotation.RequestMapping;
6+
import org.springframework.web.bind.annotation.RequestParam;
7+
import org.springframework.web.bind.annotation.RestController;
8+
9+
@RestController
10+
@RequestMapping("/api/v1")
11+
public class MessageController {
12+
Producer producer;
13+
14+
public MessageController(Producer producer) {
15+
this.producer = producer;
16+
}
17+
18+
@PostMapping("/message")
19+
public String receiveMessage(@RequestParam("message") String message) {
20+
producer.sendMessageToTopic(message);
21+
return "Message was sent successfully";
22+
}
23+
}
24+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.oracle.database.spring.txeventq.producer.service;
2+
3+
import org.slf4j.Logger;
4+
import org.slf4j.LoggerFactory;
5+
import org.springframework.beans.factory.annotation.Value;
6+
import org.springframework.stereotype.Service;
7+
import org.springframework.jms.core.JmsTemplate;
8+
9+
@Service
10+
public class Producer {
11+
12+
private static final Logger log = LoggerFactory.getLogger(Producer.class);
13+
14+
JmsTemplate jmsTemplate;
15+
16+
@Value("${txeventq.topic.name}")
17+
private String topic;
18+
19+
public Producer(JmsTemplate jmsTemplate) {
20+
this.jmsTemplate = jmsTemplate;
21+
}
22+
23+
public void sendMessageToTopic(String message)
24+
{
25+
jmsTemplate.convertAndSend(topic,message);
26+
log.info("Sending message: {} to topic {}", message, topic);
27+
}
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
spring:
2+
application:
3+
name: producer
4+
5+
datasource:
6+
url: jdbc:oracle:thin:@//localhost:1521/freepdb1
7+
username: testuser
8+
password: Welcome12345
9+
driver-class-name: oracle.jdbc.OracleDriver
10+
type: oracle.ucp.jdbc.PoolDataSource
11+
oracleucp:
12+
connection-factory-class-name: oracle.jdbc.pool.OracleDataSource
13+
connection-pool-name: ConsumerConnectionPool
14+
initial-pool-size: 15
15+
min-pool-size: 10
16+
max-pool-size: 30
17+
18+
txeventq:
19+
topic:
20+
name: my_txeventq

0 commit comments

Comments
 (0)