Sha256: 84ce8c00fa4c625483173d9c5fec213034a0f3cb9d4b0162af8c635e796e149e
Contents?: true
Size: 1.61 KB
Versions: 2
Compression:
Stored size: 1.61 KB
Contents
require "optparse" require "racecar/rails_config_file_loader" module Racecar class Ctl ProduceMessage = Struct.new(:value, :key, :topic) def self.main(args) command = args.shift or raise Racecar::Error, "no command specified" ctl = new if ctl.respond_to?(command) ctl.send(command, args) else raise Racecar::Error, "invalid command: #{command}" end end def produce(args) message = ProduceMessage.new parser = OptionParser.new do |opts| opts.banner = "Usage: racecarctl produce [options]" opts.on("-v", "--value VALUE", "Set the message value") do |value| message.value = value end opts.on("-k", "--key KEY", "Set the message key") do |key| message.key = key end opts.on("-t", "--topic TOPIC", "Set the message topic") do |topic| message.topic = topic end end parser.parse!(args) if message.topic.nil? raise Racecar::Error, "no topic specified" end if message.value.nil? raise Racecar::Error, "no message value specified" end RailsConfigFileLoader.load! Racecar.config.validate! kafka = Kafka.new( client_id: Racecar.config.client_id, seed_brokers: Racecar.config.brokers, logger: Racecar.logger, connect_timeout: Racecar.config.connect_timeout, socket_timeout: Racecar.config.socket_timeout, ) kafka.deliver_message(message.value, key: message.key, topic: message.topic) $stderr.puts "=> Delivered message to Kafka cluster" end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
racecar-0.3.1 | lib/racecar/ctl.rb |
racecar-0.3.0 | lib/racecar/ctl.rb |