WaterDrop Getting Started
Maciej Mensfeld edited this page Oct 25, 2023
·
2 revisions
Important
GitHub Wiki is just a mirror of our online documentation.
We highly recommend using our website docs due to Github Wiki limitations. Only some illustrations, links, screencasts, and code examples will work here, and the formatting may be broken.
Please use https://karafka.io/docs.
!!! info ""
If you want to both produce and consume messages, please use [Karafka](https://karafka.io/docs/Getting-Started/). It integrates WaterDrop automatically.
To get started with WaterDrop:
- Add it to your Gemfile:
bundle add waterdrop
- Create and configure a producer:
producer = WaterDrop::Producer.new do |config|
config.deliver = true
config.kafka = {
'bootstrap.servers': 'localhost:9092',
'request.required.acks': 1
}
end
- Use it as follows:
# And use it
producer.produce_sync(topic: 'my-topic', payload: 'my message')
# or for async
producer.produce_async(topic: 'my-topic', payload: 'my message')
# or in batches
producer.produce_many_sync(
[
{ topic: 'my-topic', payload: 'my message'},
{ topic: 'my-topic', payload: 'my message'}
]
)
# both sync and async
producer.produce_many_async(
[
{ topic: 'my-topic', payload: 'my message'},
{ topic: 'my-topic', payload: 'my message'}
]
)
!!! info ""
For additional WaterDrop usage examples, please refer to the [Usage](https://karafka.io/docs/WaterDrop-Usage/) section of this documentation.
Home | Getting started | Components | Producing Messages | Consuming messages | Concurrency and multithreading | Error handling and back off policy
This wiki is tracked by git and publicly editable. You are welcome to fix errors and typos. Any defacing or vandalism of content will result in your changes being reverted and you being blocked.