Skip to content

Instantly share code, notes, and snippets.

unless File.exist?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'rails', github: 'rails/rails'
gem 'arel', github: 'rails/arel'
gem 'rack', github: 'rack/rack'
gem 'i18n', github: 'svenfuchs/i18n'
GEMFILE
system 'bundle'
class Country < Struct.new(:request, :ip, :country_code, :country_code2, :country_code3, :country_name, :continent_code)
20:20:43 ~$ irb
irb(main):001:0> load "boom.rb"
=> true
irb(main):002:0> load "boom.rb"
Traceback (most recent call last):
4: from /usr/local/bin/irb:11:in `<main>'
3: from (irb):2
2: from (irb):2:in `load'
1: from boom.rb:1:in `<top (required)>'
TypeError (superclass mismatch for class Country)
class Country < Struct.new(:request, :ip, :country_code, :country_code2, :country_code3, :country_name, :continent_code)
end
Starting polling from Java bids consumer:
key: 4, payload: {"bid_amount":4,"producer_id":"producer_1"}
key: 9, payload: {"bid_amount":9,"producer_id":"producer_2"}
key: 6, payload: {"bid_amount":12,"producer_id":"producer_1"}
key: 9, payload: {"bid_amount":18,"producer_id":"producer_2"}
key: 5, payload: {"bid_amount":15,"producer_id":"producer_2"}
key: 8, payload: {"bid_amount":24,"producer_id":"producer_1"}
key: 2, payload: {"bid_amount":8,"producer_id":"producer_1"}
key: 6, payload: {"bid_amount":24,"producer_id":"producer_2"}
key: 2, payload: {"bid_amount":10,"producer_id":"producer_1"}
19:54:19 kafka_rb$ be ruby producer.rb
producer_2: Starting to publish messages...
producer_2: Publishing message with key=9 message={"bid_amount":9,"producer_id":"producer_2"}
producer_1: Starting to publish messages...
producer_1: Publishing message with key=4 message={"bid_amount":4,"producer_id":"producer_1"}
producer_1: Publishing message with key=6 message={"bid_amount":12,"producer_id":"producer_1"}
producer_2: Publishing message with key=9 message={"bid_amount":18,"producer_id":"producer_2"}
producer_2: Publishing message with key=5 message={"bid_amount":15,"producer_id":"producer_2"}
producer_1: Publishing message with key=8 message={"bid_amount":24,"producer_id":"producer_1"}
producer_1: Publishing message with key=2 message={"bid_amount":8,"producer_id":"producer_1"}
public static void main(String[] args) {
KafkaConsumer consumer = new KafkaConsumer(getProperties());
consumer.subscribe(Collections.singletonList("bids"));
System.out.println("Starting polling from Java bids consumer:");
while(true) {
ConsumerRecords<String, String> records = consumer.poll(100);
require "kafka"
require "json"
class Producer
def initialize(producer_id)
@producer_id = producer_id
@kafka = Kafka.new(["localhost:9092"], client_id: @producer_id)
@count = 0
end
@victorarias
victorarias / java_consumer.java
Last active March 21, 2018 20:17
Ruby + Java via Kafka integration
public static void main(String[] args) {
KafkaConsumer consumer = new KafkaConsumer(getProperties());
consumer.subscribe(Collections.singletonList("bids"));
System.out.println("Starting polling from Java bids consumer:");
while(true) {
ConsumerRecords<String, String> records = consumer.poll(100);
class Connection
# .. rest of the class .. #
def accept_connection(io)
@io = io
# new connection code
end
def to_io