Last active
May 30, 2023 03:51
-
-
Save armando-couto/966a3abd18b0c864aa79a94f269d12f3 to your computer and use it in GitHub Desktop.
Revisions
-
armando-couto revised this gist
May 30, 2023 . No changes.There are no files selected for viewing
-
armando-couto created this gist
May 30, 2023 .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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ require 'kafka' # Set up Kafka client kafka = Kafka.new( seed_brokers: ['localhost:9092'], client_id: 'my_kafka_client' ) # Create a producer producer = kafka.producer # Create a consumer consumer = kafka.consumer(group_id: 'my_consumer_group') # Define the topic topic = 'my_topic' # Publish messages to Kafka producer.produce('Hello, Kafka!', topic: topic) producer.deliver_messages # Subscribe to the topic and consume messages consumer.subscribe(topic) # Start consuming messages consumer.each_message do |message| puts "Received message: #{message.value}" end # Close connections producer.shutdown consumer.stop