Skip to content

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 2 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions database/starters/oracle-spring-boot-starter-samples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,24 @@

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.

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

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.

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

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.

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

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)

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.

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

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.
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.

## [Oracle Transactional Event Queues Producer and Consumer Example](./oracle-spring-boot-starter-sample-txeventqjms/)

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 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'
```
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>
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);
}

}
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);
}
}
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
____
/ ___|___ _ __ ___ _ _ _ __ ___ ___ _ __
| | / _ \| '_ \/ __| | | | '_ ` _ \ / _ \ '__|
| |__| (_) | | | \__ \ |_| | | | | | | __/ |
\____\___/|_| |_|___/\__,_|_| |_| |_|\___|_|

Powered by Spring Boot ${spring-boot.version}
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>
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);
}

}
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";
}
}

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);
}
}
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
Loading
Loading