event your life with kafka

25
Event your life with Kafka Mari Gutiérrez :: Madrid.rb :: Dec 2014

Upload: mari-carmen-gutierrez

Post on 12-Jul-2015

232 views

Category:

Software


0 download

TRANSCRIPT

Page 1: Event your life with Kafka

Event your life with Kafka

Mari Gutiérrez :: Madrid.rb :: Dec 2014

Page 2: Event your life with Kafka

@valakirka

Page 3: Event your life with Kafka

kafka /ˈkɑːfkɑː/

“Kafka is a distributed, partitioned, replicated commit log service. It provides the functionality of a

messaging system, but with a unique design.”

Page 4: Event your life with Kafka
Page 5: Event your life with Kafka

zookeeper /ˈzuːˌkiːpə/

“ZooKeeper is a centralized service for maintaining configuration information, naming, providing distributed

synchronization, and providing group services.”

Page 6: Event your life with Kafka
Page 7: Event your life with Kafka

topic

Page 8: Event your life with Kafka

partition

Page 9: Event your life with Kafka

broker

Page 10: Event your life with Kafka

producer

Page 11: Event your life with Kafka

consumer

Page 12: Event your life with Kafka

consumer group

Page 13: Event your life with Kafka

kafka in Ruby: Poseidon /bpot/poseidon

Page 14: Event your life with Kafka

require 'poseidon' !class MyProducer def initialize partitioner = lambda { |key, partition_count| key.to_i % partition_count } @producer = Poseidon::Producer.new( ['localhost:9092'], self.class.name, partitioner: partitioner) end ! def send_message(body) message = Poseidon::MessageToSend.new( 'mytopic', body, Time.now.to_i.to_s) ! @producer.send_messages([message]) end end

Page 15: Event your life with Kafka

require 'poseidon' !class MyConsumer def initialize(offset) @consumer = Poseidon::PartitionConsumer. consumer_for_partition(self.class.name, ['localhost:9092'], 'mytopic', 0, offset) end ! def run loop do @consumer.fetch.each do |event| puts event.value end end end end

Page 16: Event your life with Kafka

consumer = MyConsumer.new(0) consumer.run !producer = MyProducer.new producer.send_message('hola Madrid.rb')

Page 17: Event your life with Kafka

require 'poseidon' require 'poseidon_cluster' !class MyConsumerGroup def initialize @group = Poseidon::ConsumerGroup.new( self.class.name, ['localhost:9092'], ['localhost:2181'], 'mytopic') end ! def run @group.fetch_loop do |partition, messages| messages.each { |m| puts m.value } end end end

Page 18: Event your life with Kafka

why kafka? usage pattern

Page 19: Event your life with Kafka

offset & retention

Page 20: Event your life with Kafka

batch/offline consumers

Page 21: Event your life with Kafka

ordered delivery

Page 22: Event your life with Kafka

event sourcing /ɪˈvɛnt ˈsɔːsɪŋ/

“Capture all changes to an application state as a sequence of events.”

Page 23: Event your life with Kafka
Page 24: Event your life with Kafka

¡gracias!

Page 25: Event your life with Kafka

sourceshttp://kafka.apache.org/documentation.html !http://zookeeper.apache.org/ !https://kafka.apache.org/08/ops.html !https://cwiki.apache.org/confluence/display/KAFKA/A+Guide+To+The+Kafka+Protocol !http://www.infoq.com/articles/apache-kafka !https://engineering.linkedin.com/kafka/benchmarking-apache-kafka-2-million-writes-second-three-cheap-machines !https://cwiki.apache.org/confluence/display/KAFKA/Ecosystem !https://github.com/bpot/poseidon !https://github.com/bsm/poseidon_cluster !http://martinfowler.com/eaaDev/EventSourcing.html !http://harpers.org/wp-content/uploads/whykafka-final.jpg !https://github.com/valakirka/kafka_example