generated from oracle/template-repo
-
Notifications
You must be signed in to change notification settings - Fork 11
TxEventQ JMS Sample #150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
TxEventQ JMS Sample #150
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
65 changes: 65 additions & 0 deletions
65
...ng-boot-starter-samples/oracle-spring-boot-starter-sample-txeventqjms/README.md
This file contains hidden or 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 @@ | ||
# Oracle Transactional Event Queues (TxEventQ) Producer and Consumer Example | ||
|
||
[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. | ||
|
||
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. | ||
|
||
## Install an Oracle Database 23ai | ||
|
||
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: | ||
|
||
```shell | ||
docker run --name free23ai -d -p 1521:1521 -e ORACLE_PWD=Welcome12345 \ | ||
container-registry.oracle.com/database/free:latest-lite | ||
``` | ||
|
||
## Create user and the Transactional Event Queue (TxEventQ) | ||
|
||
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`. | ||
|
||
## Start the Consumer application | ||
|
||
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`. | ||
|
||
## Start the Producer application | ||
|
||
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`. | ||
|
||
## Send a message | ||
|
||
Open a terminal window and execute the following command to send a message via the Producer `/api/v1/message` endpoint: | ||
|
||
```shell | ||
curl -X POST http://localhost:8080/api/v1/message?message=MyMessage | ||
``` | ||
|
||
The command returns the message `Message was sent successfully`. | ||
|
||
In the Producer terminal window you will get a notification that looks like this: | ||
|
||
```log | ||
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 | ||
``` | ||
|
||
In the Consumer terminal window you will get a notification that looks like this: | ||
|
||
```log | ||
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 | ||
``` | ||
|
||
## Configure your project to use Oracle Spring Boot Starter for TxEventQ and JMS | ||
|
||
To use Oracle Spring Boot Starter for TxEventQ and JMS for your Spring Boot application, add the following Maven dependency to your project: | ||
|
||
```xml | ||
<dependency> | ||
<groupId>com.oracle.database.spring</groupId> | ||
<artifactId>oracle-spring-boot-starter-aqjms</artifactId> | ||
</dependency> | ||
``` | ||
|
||
or if you are using Gradle: | ||
|
||
```text | ||
implementation 'com.oracle.database.spring:oracle-spring-boot-starter-aqjms:24.3.0' | ||
``` |
69 changes: 69 additions & 0 deletions
69
...pring-boot-starter-samples/oracle-spring-boot-starter-sample-txeventqjms/consumer/pom.xml
This file contains hidden or 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,69 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- Copyright (c) 2024, Oracle and/or its affiliates. --> | ||
<!-- Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. --> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<artifactId>oracle-spring-boot-starter-samples</artifactId> | ||
<groupId>com.oracle.database.spring</groupId> | ||
<version>24.3.0</version> | ||
<relativePath>../../pom.xml</relativePath> | ||
</parent> | ||
|
||
<artifactId>oracle-spring-boot-sample-txeventqjms-consumer</artifactId> | ||
<version>24.3.0</version> | ||
|
||
<name>Oracle Spring Boot Starter - Transactional Event Queue JMS Sample</name> | ||
<description>Oracle Spring Boot Starter - Transactional Event Queue JMS Sample</description> | ||
|
||
<organization> | ||
<name>Oracle America, Inc.</name> | ||
<url>https://www.oracle.com</url> | ||
</organization> | ||
|
||
<developers> | ||
<developer> | ||
<name>Oracle</name> | ||
<email>obaas_ww at oracle.com</email> | ||
<organization>Oracle America, Inc.</organization> | ||
<organizationUrl>https://www.oracle.com</organizationUrl> | ||
</developer> | ||
</developers> | ||
|
||
<licenses> | ||
<license> | ||
<name>The Universal Permissive License (UPL), Version 1.0</name> | ||
<url>https://oss.oracle.com/licenses/upl/</url> | ||
<distribution>repo</distribution> | ||
</license> | ||
</licenses> | ||
|
||
<scm> | ||
<url>https://github.com/oracle/spring-cloud-oracle</url> | ||
<connection>scm:git:https://github.com/oracle/spring-cloud-oracle.git</connection> | ||
<developerConnection>scm:git:git@github.com:oracle/spring-cloud-oracle.git</developerConnection> | ||
</scm> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-jdbc</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.oracle.database.spring</groupId> | ||
<artifactId>oracle-spring-boot-starter-aqjms</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
13 changes: 13 additions & 0 deletions
13
...er/src/main/java/com/oracle/database/spring/txeventqjms/consumer/ConsumerApplication.java
This file contains hidden or 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,13 @@ | ||
package com.oracle.database.spring.txeventqjms.consumer; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
public class ConsumerApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(ConsumerApplication.class, args); | ||
} | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
...sumer/src/main/java/com/oracle/database/spring/txeventqjms/consumer/service/Consumer.java
This file contains hidden or 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,17 @@ | ||
package com.oracle.database.spring.txeventqjms.consumer.service; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.jms.annotation.JmsListener; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class Consumer { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(Consumer.class); | ||
|
||
@JmsListener(destination = "${txeventq.topic.name}") | ||
public void receiveMessage(String message) { | ||
log.info("Received message: {}", message); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...racle-spring-boot-starter-sample-txeventqjms/consumer/src/main/resources/application.yaml
This file contains hidden or 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,20 @@ | ||
spring: | ||
application: | ||
name: consumer | ||
|
||
datasource: | ||
url: jdbc:oracle:thin:@//localhost:1521/freepdb1 | ||
username: testuser | ||
password: Welcome12345 | ||
driver-class-name: oracle.jdbc.OracleDriver | ||
type: oracle.ucp.jdbc.PoolDataSource | ||
oracleucp: | ||
connection-factory-class-name: oracle.jdbc.pool.OracleDataSource | ||
connection-pool-name: ConsumerConnectionPool | ||
initial-pool-size: 15 | ||
min-pool-size: 10 | ||
max-pool-size: 30 | ||
|
||
txeventq: | ||
topic: | ||
name: my_txeventq |
7 changes: 7 additions & 0 deletions
7
...ples/oracle-spring-boot-starter-sample-txeventqjms/consumer/src/main/resources/banner.txt
This file contains hidden or 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,7 @@ | ||
____ | ||
/ ___|___ _ __ ___ _ _ _ __ ___ ___ _ __ | ||
| | / _ \| '_ \/ __| | | | '_ ` _ \ / _ \ '__| | ||
| |__| (_) | | | \__ \ |_| | | | | | | __/ | | ||
\____\___/|_| |_|___/\__,_|_| |_| |_|\___|_| | ||
|
||
Powered by Spring Boot ${spring-boot.version} |
73 changes: 73 additions & 0 deletions
73
...pring-boot-starter-samples/oracle-spring-boot-starter-sample-txeventqjms/producer/pom.xml
This file contains hidden or 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,73 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- Copyright (c) 2024, Oracle and/or its affiliates. --> | ||
<!-- Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. --> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<artifactId>oracle-spring-boot-starter-samples</artifactId> | ||
<groupId>com.oracle.database.spring</groupId> | ||
<version>24.3.0</version> | ||
<relativePath>../../pom.xml</relativePath> | ||
</parent> | ||
|
||
<artifactId>oracle-spring-boot-sample-txeventqjms-producer</artifactId> | ||
<version>24.3.0</version> | ||
|
||
<name>Oracle Spring Boot Starter - Transactional Event Queue JMS Sample</name> | ||
<description>Oracle Spring Boot Starter - Transactional Event Queue JMS Sample</description> | ||
|
||
<organization> | ||
<name>Oracle America, Inc.</name> | ||
<url>https://www.oracle.com</url> | ||
</organization> | ||
|
||
<developers> | ||
<developer> | ||
<name>Oracle</name> | ||
<email>obaas_ww at oracle.com</email> | ||
<organization>Oracle America, Inc.</organization> | ||
<organizationUrl>https://www.oracle.com</organizationUrl> | ||
</developer> | ||
</developers> | ||
|
||
<licenses> | ||
<license> | ||
<name>The Universal Permissive License (UPL), Version 1.0</name> | ||
<url>https://oss.oracle.com/licenses/upl/</url> | ||
<distribution>repo</distribution> | ||
</license> | ||
</licenses> | ||
|
||
<scm> | ||
<url>https://github.com/oracle/spring-cloud-oracle</url> | ||
<connection>scm:git:https://github.com/oracle/spring-cloud-oracle.git</connection> | ||
<developerConnection>scm:git:git@github.com:oracle/spring-cloud-oracle.git</developerConnection> | ||
</scm> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-jdbc</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.oracle.database.spring</groupId> | ||
<artifactId>oracle-spring-boot-starter-aqjms</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
13 changes: 13 additions & 0 deletions
13
...ducer/src/main/java/com/oracle/database/spring/txeventq/producer/ProducerApplication.java
This file contains hidden or 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,13 @@ | ||
package com.oracle.database.spring.txeventq.producer; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
public class ProducerApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(ProducerApplication.class, args); | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
.../main/java/com/oracle/database/spring/txeventq/producer/controller/MessageController.java
This file contains hidden or 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,24 @@ | ||
package com.oracle.database.spring.txeventq.producer.controller; | ||
|
||
import com.oracle.database.spring.txeventq.producer.service.Producer; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/api/v1") | ||
public class MessageController { | ||
Producer producer; | ||
|
||
public MessageController(Producer producer) { | ||
this.producer = producer; | ||
} | ||
|
||
@PostMapping("/message") | ||
public String receiveMessage(@RequestParam("message") String message) { | ||
producer.sendMessageToTopic(message); | ||
return "Message was sent successfully"; | ||
} | ||
} | ||
|
28 changes: 28 additions & 0 deletions
28
...producer/src/main/java/com/oracle/database/spring/txeventq/producer/service/Producer.java
This file contains hidden or 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,28 @@ | ||
package com.oracle.database.spring.txeventq.producer.service; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.jms.core.JmsTemplate; | ||
|
||
@Service | ||
public class Producer { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(Producer.class); | ||
|
||
JmsTemplate jmsTemplate; | ||
|
||
@Value("${txeventq.topic.name}") | ||
private String topic; | ||
|
||
public Producer(JmsTemplate jmsTemplate) { | ||
this.jmsTemplate = jmsTemplate; | ||
} | ||
|
||
public void sendMessageToTopic(String message) | ||
{ | ||
jmsTemplate.convertAndSend(topic,message); | ||
log.info("Sending message: {} to topic {}", message, topic); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...racle-spring-boot-starter-sample-txeventqjms/producer/src/main/resources/application.yaml
This file contains hidden or 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,20 @@ | ||
spring: | ||
application: | ||
name: producer | ||
|
||
datasource: | ||
url: jdbc:oracle:thin:@//localhost:1521/freepdb1 | ||
username: testuser | ||
password: Welcome12345 | ||
driver-class-name: oracle.jdbc.OracleDriver | ||
type: oracle.ucp.jdbc.PoolDataSource | ||
oracleucp: | ||
connection-factory-class-name: oracle.jdbc.pool.OracleDataSource | ||
connection-pool-name: ConsumerConnectionPool | ||
initial-pool-size: 15 | ||
min-pool-size: 10 | ||
max-pool-size: 30 | ||
|
||
txeventq: | ||
topic: | ||
name: my_txeventq |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.