Skip to content

Commit

Permalink
Merge pull request #52 from oracle/okafka-example-23.4
Browse files Browse the repository at this point in the history
Fix Okafka example 23.4
  • Loading branch information
pasimoes authored Aug 15, 2024
2 parents 88ca668 + 3415f48 commit 4d6e361
Show file tree
Hide file tree
Showing 19 changed files with 194 additions and 1,084 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ clients/.project
clients/.settings/
examples/.project
examples/.settings/
examples/ojdbc.properties
examples/consumer/.classpath
examples/consumer/.project
examples/consumer/.settings/
Expand Down
34 changes: 10 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ To run `OKafka application` against Oracle Database, a database user must be cre

```roomsql
create user <user> identified by <password>
GRANT CONNECT , RESOURCE to user;
GRANT UNLIMITED TABLESPACE to user;
GRANT AQ_USER_ROLE to user;
GRANT CONNECT, RESOURCE, unlimited tablespace to user;
GRANT EXECUTE on DBMS_AQ to user;
GRANT EXECUTE on DBMS_AQADM to user;
GRANT EXECUTE on DBMS_AQIN to user;
Expand All @@ -34,7 +35,8 @@ GRANT SELECT on GV_$INSTANCE to user;
GRANT SELECT on GV_$LISTENER_NETWORK to user;
GRANT SELECT on GV_$PDBS to user;
GRANT SELECT on USER_QUEUE_PARTITION_ASSIGNMENT_TABLE to user;
exec DBMS_AQADM.GRANT_PRIV_FOR_RM_PLAN('user');
GRANT SELECT on SYS.DBA_RSRC_PLAN_DIRECTIVES to user;
EXEC DBMS_AQADM.GRANT_PRIV_FOR_RM_PLAN('user');
```

Note:
Expand Down Expand Up @@ -134,29 +136,13 @@ gradle javadoc

## Examples

Repository contains 7 common OKafka application examples in `examples` folder.

`1. CreateTopic.java` -
Connects to Oracle Database and create a topic TXEQ with 10 partitions with default retention time of 7 days.

`2. DeleteTopic.java`
Deletes already created OKafka topic.

`3. SimpleProducer.java`
Produces 100 messages into TxEQ topic.

`4. SimpleConsumer.java`
Consumes 100 messages from TxEQ topic.

`5. TransactionalProducer.java`
Retrieves the Oracle Database Connection object from OKafka producer. Atomically performs a DML operation and sends a record.

`6. TransactionalConsumer.java`
Retrieves the Oracle Database Connection object from OKafka consumer. Atomically consumes a batch of records and perform DML operation for each record.
Repository contains 2 common OKafka application examples in `examples` folder.

`1. ProducerOKafka.java`
Produces 10 messages into TxEQ topic.

`7. TransactionalProduceConsume.java`
Atomically consumes a batch of messages from TXEQ topic using OKafka Consumer, processes records from the batch and produces them in the tpic TxEQ_2 using OKafka Producer. To achieve atomicity for this these consume-process-produce operations, application retrieves the Oracle Database Connection object from OKafka Consumer and pass it to create an OKafka Producer.
`2. ConsumerOKafka.java`
Consumes 10 messages from TxEQ topic.

## Kafka Java Client APIs supported

Expand Down
97 changes: 51 additions & 46 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ allprojects {
options.windowTitle = "Oracle Database Transactional Event Queues Java API Reference"
options.header = """<b>Oracle&reg; Database Transactional Event Queues Java API Reference<br>23ai</b><br>FF46992-04<br>"""
options.bottom = """<center><small>Copyright &copy; 2001, 2024, Oracle and/or its affiliates. All rights reserved.<small></center><p><small><br></small></p>"""
}
}
}

ext {
gradleVersion = '7.3'
minJavaVersion = JavaVersion.VERSION_1_8
gradleVersion = '8.8'
minJavaVersion = JavaVersion.VERSION_17

mavenUrl = project.hasProperty('mavenUrl') ? project.mavenUrl : ''
mavenUsername = project.hasProperty('mavenUsername') ? project.mavenUsername : ''
Expand All @@ -42,41 +42,41 @@ ext {

project(':clients') {
apply plugin : 'java-library'

sourceCompatibility = minJavaVersion
targetCompatibility = minJavaVersion

sourceSets {
main {
java {
srcDir 'src/main/java'
exclude 'tests/**'
exclude 'test/**'
}
}
}
main {
java {
srcDir 'src/main/java'
exclude 'tests/**'
exclude 'test/**'
}
}
}

println 'Creating okafka-23.4.0.0.jar'
println 'Building okafka 23.4.0.0 Java API jar'

dependencies {

// These dependencies are used by the application.
implementation group: 'com.oracle.database.jdbc', name: 'ojdbc11', version: '23.4.0.24.05'
implementation group: 'com.oracle.database.messaging', name: 'aqapi', version: '23.3.0.0'
implementation group: 'javax.transaction', name: 'jta', version: '1.1'
implementation group: 'javax.jms', name: 'javax.jms-api', version: '2.0'
implementation group: 'com.oracle.database.security', name: 'oraclepki', version: '23.4.0.24.05'
implementation group: 'org.slf4j', name: 'slf4j-api', version: '2.0.0-alpha0'
implementation group: 'org.apache.kafka', name: 'kafka-clients', version: '3.7.1'
// Use JUnit test framework
implementation group: 'junit', name: 'junit', version: '4.12'
// Test dependencies
testImplementation group: 'org.easymock', name: 'easymock', version: '3.6'
testImplementation group: 'org.powermock', name: 'powermock-module-junit4', version: '2.0.0-beta.5'
testImplementation group: 'org.powermock', name: 'powermock-api-support', version: '2.0.5'
testImplementation group: 'org.powermock', name: 'powermock-api-easymock', version: '2.0.0-beta.5'
// These dependencies are used by the application.
implementation group: 'com.oracle.database.jdbc', name: 'ojdbc11', version: '23.4.0.24.05'
implementation group: 'com.oracle.database.messaging', name: 'aqapi', version: '23.3.0.0'
implementation group: 'javax.transaction', name: 'jta', version: '1.1'
implementation group: 'javax.jms', name: 'javax.jms-api', version: '2.0'
implementation group: 'com.oracle.database.security', name: 'oraclepki', version: '23.4.0.24.05'
implementation group: 'org.slf4j', name: 'slf4j-api', version: '2.0.0-alpha0'
implementation group: 'org.apache.kafka', name: 'kafka-clients', version: '3.7.1'
// Use JUnit test framework
implementation group: 'junit', name: 'junit', version: '4.12'

// Test dependencies
testImplementation group: 'org.easymock', name: 'easymock', version: '3.6'
testImplementation group: 'org.powermock', name: 'powermock-module-junit4', version: '2.0.0-beta.5'
testImplementation group: 'org.powermock', name: 'powermock-api-support', version: '2.0.5'
testImplementation group: 'org.powermock', name: 'powermock-api-easymock', version: '2.0.0-beta.5'

}

javadoc {
Expand All @@ -87,18 +87,21 @@ project(':clients') {
}

tasks.named('jar') {
description('Creating JAR okafka-23.4.0.0.jar ')
description('Generates okafka 23.4.0.0 API jar ')
archiveBaseName = 'okafka'
archiveVersion = '23.4.0.0'

from "${rootProject.projectDir}/LICENSE.txt"
from "${rootProject.projectDir}/NOTICE"

manifest {
attributes (
'Version': '23.4.0.0',
'Build-Time-ISO-8601':new Date().format("yyyy-MM-dd HH:mm:ss")
)
}
manifest {
attributes (
'Implementation-Title' : 'okafka',
'Implementation-Version': project.version,
'Version': '23.4.0.0',
'Build-Time-ISO-8601':new Date().format("yyyy-MM-dd HH:mm:ss")
)
}
}

tasks.register('fullJar', Jar) {
Expand All @@ -107,7 +110,7 @@ project(':clients') {

manifest {
attributes( 'Implementation-Title' : 'okafka',
'Implementation-Version': project.version)
'Implementation-Version': project.version)
}

from "${rootProject.projectDir}/LICENSE.txt"
Expand Down Expand Up @@ -137,6 +140,7 @@ project(':examples:consumer') {
implementation project(':clients')
implementation group: 'com.oracle.database.security', name: 'oraclepki', version: '23.4.0.24.05'
implementation group: 'org.apache.kafka', name: 'kafka-clients', version: '3.7.1'
implementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.5.6'
}


Expand All @@ -150,14 +154,14 @@ project(':examples:consumer') {

manifest {
attributes( 'Implementation-Title' : 'okafka consumer',
'Implementation-Version': project.version)
'Implementation-Version': project.version)
}
}

tasks.named('run') {
description('Run okafka client consumer')
description('Run okafka client simple consumer')
application {
mainClass = 'org.oracle.okafka.examples.Consumer'
mainClass = 'org.oracle.okafka.examples.ConsumerOKafka'
}
}
}
Expand All @@ -174,10 +178,11 @@ project(':examples:producer') {
implementation project(':clients')
implementation group: 'com.oracle.database.security', name: 'oraclepki', version: '23.4.0.24.05'
implementation group: 'org.apache.kafka', name: 'kafka-clients', version: '3.7.1'
implementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.5.6'
}

tasks.named('jar') {
description('Generates okafka client producer jar ')
description('Generates okafka client simple producer jar ')
archiveBaseName = 'okafka'
archiveClassifier = 'producer'

Expand All @@ -186,14 +191,14 @@ project(':examples:producer') {

manifest {
attributes( 'Implementation-Title' : 'okafka producer',
'Implementation-Version': project.version)
'Implementation-Version': project.version)
}
}

tasks.named('run') {
description('Run okafka client producer')
description('Run okafka client simple producer')
application {
mainClass = 'org.oracle.okafka.examples.Producer'
mainClass = 'org.oracle.okafka.examples.ProducerOKafka'
}
}
}
Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit 4d6e361

Please sign in to comment.