Want the familiar Kafka Java APIs without standing up and managing a separate Kafka cluster? Oracle’s **OKafka** (Kafka Java Client for Transactional Event Queues) lets you produce and consume events straight from your Oracle Database — with full transactional guarantees and exactly-once semantics.
Here’s everything you need to know to get started quickly and build reliable event-driven applications on Oracle AI Database.
Why OKafka?
- Use standard Kafka Java producer/consumer code
- Events are stored and processed inside the database
- Atomic transactions between database changes and event publishing
- No separate message broker to operate and scale
- Works with Oracle Database 23ai Free and above
Quick Start: Database Setup
First, create a database user with the required privileges:
CREATE USER okafka_user IDENTIFIED BY Oracle123;
GRANT AQ_USER_ROLE TO okafka_user;
GRANT CONNECT, RESOURCE, UNLIMITED TABLESPACE TO okafka_user;
GRANT EXECUTE ON DBMS_AQ TO okafka_user;
GRANT EXECUTE ON DBMS_AQADM TO okafka_user;
GRANT SELECT ON GV_$SESSION TO okafka_user;
-- ... (full list in documentation)
Then create your first topic:
BEGIN
DBMS_AQADM.CREATE_DATABASE_KAFKA_TOPIC(
topicname => 'MY_TOPIC',
partition_num => 5,
retentiontime => 7*24*3600
);
END;
Connection Configuration
Option 1: PLAINTEXT (Simple)
security.protocol=PLAINTEXT
bootstrap.servers=your-host:port
oracle.service.name=your_service
oracle.net.tns_admin=/path/to/ojdbc.properties
Option 2: SSL (Recommended for Production)
Use Oracle Wallet for secure mTLS connections.
Building Your First OKafka App
- Clone the OKafka distribution
- Build with Gradle:
./gradlew jaror./gradlew fullJar - Add the resulting JAR to your project
Producer Example
Properties props = new Properties();
props.put("bootstrap.servers", "your-host:port");
props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
KafkaProducer producer = new KafkaProducer<>(props);
ProducerRecord record = new ProducerRecord<>("MY_TOPIC", "key1", "Hello from OKafka!");
producer.send(record).get();
producer.close();
Consumer Example
KafkaConsumer consumer = new KafkaConsumer<>(props);
consumer.subscribe(Collections.singletonList("MY_TOPIC"));
while (true) {
ConsumerRecords records = consumer.poll(Duration.ofMillis(100));
for (ConsumerRecord record : records) {
System.out.println("Received: " + record.value());
}
}
Best Practices
- Use transactions for atomic database + event operations
- Always handle proper error paths and rollbacks
- Test with Testcontainers + Oracle Database Free
- Monitor queue depth and consumer lag
- Start with PLAINTEXT for development, move to SSL in production
Conclusion
OKafka brings the power and familiarity of Kafka directly into Oracle Database. You get enterprise-grade messaging with transactional integrity, high availability, and zero additional infrastructure to manage.
Whether you’re building microservices, event-driven architectures, or real-time analytics, OKafka lets you leverage your existing Oracle investment for reliable pub/sub messaging.