README.md in delivery_boy-0.2.8.beta1 vs README.md in delivery_boy-0.2.8
- old
+ new
@@ -57,12 +57,39 @@
end
```
In addition to improving response time, delivering messages asynchronously also protects your application against Kafka availability issues -- if messages cannot be delivered, they'll be buffered for later and retried automatically.
-Both `deliver` and `deliver_async` take the following options:
+A third method is to produce messages first (without delivering the messages to Kafka yet), and deliver them synchronously later.
+```ruby
+ # app/controllers/comments_controller.rb
+ class CommentsController < ApplicationController
+ def create
+ @comment = Comment.create!(params)
+
+ event = {
+ name: "comment_created",
+ data: {
+ comment_id: @comment.id
+ user_id: current_user.id
+ }
+ }
+
+ # This will queue the two messages in the internal buffer.
+ DeliveryBoy.produce(comment.to_json, topic: "comments")
+ DeliveryBoy.produce(event.to_json, topic: "activity")
+
+ # This will deliver all messages in the buffer to Kafka.
+ # This call is blocking.
+ DeliveryBoy.deliver_messages
+ end
+ end
+```
+
+The methods `deliver`, `deliver_async` and `produce` take the following options:
+
* `topic` – the Kafka topic that should be written to (required).
* `key` – the key that should be set on the Kafka message (optional).
* `partition` – a specific partition number that should be written to (optional).
* `partition_key` – a string that can be used to deterministically select the partition that should be written to (optional).
@@ -101,10 +128,14 @@
##### `client_id`
This is how the client will identify itself to the Kafka brokers. Default is `delivery_boy`.
+##### `log_level`
+
+The log level for the logger.
+
#### Message delivery
##### `delivery_interval`
The number of seconds between background message deliveries. Default is 10 seconds. Disable timer-based background deliveries by setting this to 0.
@@ -229,20 +260,20 @@
```ruby
describe PostsController do
describe "#show" do
it "emits an event to Kafka" do
post = Post.create!(body: "hello")
-
+
get :show, id: post.id
-
+
# Use this API to extract all messages written to a Kafka topic.
messages = DeliveryBoy.testing.messages_for("post_views")
-
+
expect(messages.count).to eq 1
-
+
# In addition to #value, you can also pull out #key and #partition_key.
event = JSON.parse(messages.first.value)
-
+
expect(event["post_id"]).to eq post.id
end
end
end
```