Class: KafkaProducer

Inherits:
Object
  • Object
show all
Defined in:
lib/kafka_producer.rb

Instance Method Summary collapse

Constructor Details

#initializeKafkaProducer

Returns a new instance of KafkaProducer.



3
4
5
# File 'lib/kafka_producer.rb', line 3

def initialize
  @configs = YAML.load_file("#{Rails.root}/config/ruby_kafka_retry.yml")[Rails.env]
end

Instance Method Details

#get_kafka_instanceObject



7
8
9
# File 'lib/kafka_producer.rb', line 7

def get_kafka_instance
  Kafka.new(@configs["brokers"], client_id: @configs["client_id"], ssl_ca_certs_from_system: @configs["ssl_ca_certs_from_system"])
end

#publish_to_topic(topic, message) ⇒ Object



11
12
13
14
# File 'lib/kafka_producer.rb', line 11

def publish_to_topic(topic, message)
  kafka = get_kafka_instance
  kafka.deliver_message(message.to_json, topic: topic)
end