Skip to content

Instantly share code, notes, and snippets.

@dasch
Last active August 16, 2017 11:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dasch/4c166c3b4b9a2fa91fda5334735963f7 to your computer and use it in GitHub Desktop.
Save dasch/4c166c3b4b9a2fa91fda5334735963f7 to your computer and use it in GitHub Desktop.
# app/controllers/posts_controller.rb
class PostsController < ApplicationController
def show
@post = Post.find(params[:id])
event = {
post_id: @post.id,
ip_address: request.remote_ip,
timestamp: Time.now,
}
# Calling `deliver_async` will enqueue the message in an asynchronous
# Kafka producer that will periodically deliver all pending messages.
DeliveryBoy.deliver_async(event.to_json, topic: "post-views")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment