Add the library to the test section in your application's Gemfile:
group :test do
gem 'testcontainers-kafka'
endAnd then execute:
$ bundle installOr install it yourself as:
$ gem install testcontainers-kafkarequire "testcontainers/kafka"
require "rdkafka"
container = Testcontainers::KafkaContainer.new.start
begin
container.wait_for_tcp_port(9092)
config = {
"bootstrap.servers": container.connection_url,
"group.id": "ruby-example",
"auto.offset.reset": "earliest"
}
producer = Rdkafka::Config.new(config).producer
producer.produce(payload: "hello", topic: "example").wait
consumer = Rdkafka::Config.new(config).consumer
consumer.subscribe("example")
puts consumer.each { |msg| break msg.payload }
ensure
container.stop if container.running?
container.remove if container.exists?
endBug reports and pull requests are welcome on GitHub at https://github.com/testcontainers/testcontainers-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
The gem is available as open source under the terms of the MIT License.
Everyone interacting in the Testcontainers project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.