Skip to content
This repository was archived by the owner on Mar 12, 2025. It is now read-only.
Open
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
41 changes: 40 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,42 @@
# Apache Kafka example for Ruby

## UNDER DEVELOPMENT
## Setup

Make sure you have any modern version of Ruby up and running.
Then install bundler and dependencies for this codebase.

```bash
cd ruby-kafka-example
gem install bundler && bundle
```

Create your account on [cloudkarafka], and set this environment variables:

```bash
export CLOUDKARAFKA_BROKERS=a....cloudkafka.com:9094,a....cloudkafka.com:9094,ar....cloudkafka.com:9094
export CLOUDKARAFKA_USERNAME=your-username
export CLOUDKARAFKA_PASSWORD=your-password
export CLOUDKARAFKA_TOPIC_PREFIX=topic_prefix-
```

Visit Dashboard on [cloudkarafka] and create a topic with name similar to this `topic_prefix-test`.


Bootup the [consumer.rb](consumer.rb)

```bash
ruby consumer.rb
```

Then run the [producer.rb](producer.rb) that will generate some messages:

```bash
ruby producer.rb
```

And you sould be good to go with your experiments.

Fin.


[cloudkarafka]:https://www.cloudkarafka.com/
6 changes: 3 additions & 3 deletions consumer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
require 'rdkafka'

config = {
:"bootstrap.servers" => ENV['CLOUDKARAFKA_BROKERS'],
:"bootstrap.servers" => ENV.fetch('CLOUDKARAFKA_BROKERS'),
:"group.id" => "cloudkarafka-example",
:"sasl.username" => ENV['CLOUDKARAFKA_USERNAME'],
:"sasl.password" => ENV['CLOUDKARAFKA_PASSWORD'],
:"sasl.username" => ENV.fetch('CLOUDKARAFKA_USERNAME'),
:"sasl.password" => ENV.fetch('CLOUDKARAFKA_PASSWORD'),
:"security.protocol" => "SASL_SSL",
:"sasl.mechanisms" => "SCRAM-SHA-256"
}
Expand Down
10 changes: 5 additions & 5 deletions producer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
require 'rdkafka'

config = {
:"bootstrap.servers" => ENV['CLOUDKARAFKA_BROKERS'],
:"bootstrap.servers" => ENV.fetch('CLOUDKARAFKA_BROKERS'),
:"group.id" => "cloudkarafka-example",
:"sasl.username" => ENV['CLOUDKARAFKA_USERNAME'],
:"sasl.password" => ENV['CLOUDKARAFKA_PASSWORD'],
:"sasl.username" => ENV.fetch('CLOUDKARAFKA_USERNAME'),
:"sasl.password" => ENV.fetch('CLOUDKARAFKA_PASSWORD'),
:"security.protocol" => "SASL_SSL",
:"sasl.mechanisms" => "SCRAM-SHA-256"
}
Expand All @@ -14,11 +14,11 @@
rdkafka = Rdkafka::Config.new(config)
producer = rdkafka.producer

100.times do |i|
1000.times do |i|
puts "Producing message #{i}"
producer.produce(
topic: topic,
payload: "Payload #{i}",
payload: "This is my payload #{i} TEST 2",
key: "Key #{i}"
).wait
end