#!/usr/bin/env ruby require "kafkr" require "readline" # Parsing command line arguments for host and port host = ARGV[0] || "localhost" port = ARGV[1] || 4000 Kafkr.log "Running on host: #{host} and port: #{port}" begin require "kafkr" rescue LoadError => e Kafkr.log "Failed to load Kafkr: #{e.message}" exit(1) end begin Kafkr::Producer.configure do |config| config.host = host config.port = port end while line = Readline.readline("> ", true) break if line == "exit" if line.include? "<=>" Kafkr.log Kafkr::Producer.send_message_and_wait(line) else Kafkr::Producer.send_message(line) end end rescue => e Kafkr.log "An error occurred: #{e.message}" exit(1) rescue Interrupt Kafkr.log "\nProducer server shutting down gracefully..." exit(0) end