def __init__(self, configFile, topic): self.conf = ccloud_lib.read_ccloud_config(configFile) self.producer_conf = ccloud_lib.pop_schema_registry_params_from_config( self.conf) self.producer = Producer(self.producer_conf) self.topic = topic ccloud_lib.create_topic(self.conf, topic)
def create_producer(config_file, topic): conf = ccloud_lib.read_ccloud_config(config_file) producer = Producer({ 'bootstrap.servers': conf['bootstrap.servers'], 'sasl.mechanisms': conf['sasl.mechanisms'], 'security.protocol': conf['security.protocol'], 'sasl.username': conf['sasl.username'], 'sasl.password': conf['sasl.password'], }) # Create topic if needed ccloud_lib.create_topic(conf, topic) return producer
# Initialization args = ccloud_lib.parse_args() config_file = args.config_file topic = args.topic conf = ccloud_lib.read_ccloud_config(config_file) # Create Producer instance p = Producer({ 'bootstrap.servers': conf['bootstrap.servers'], 'sasl.mechanisms': conf['sasl.mechanisms'], 'security.protocol': conf['security.protocol'], 'sasl.username': conf['sasl.username'], 'sasl.password': conf['sasl.password'], }) # Create topic if needed ccloud_lib.create_topic(conf, topic) # Optional per-message on_delivery handler (triggered by poll() or flush()) # when a message has been successfully delivered or # permanently failed delivery (after retries). def acked(err, msg): """Delivery report handler called on successful or failed delivery of message """ if err is not None: print("Failed to deliver message: {}".format(err)) else: print("Produced record to topic {} partition [{}] @ offset {}". format(msg.topic(), msg.partition(), msg.offset())) for n in range(10):
# Create Producer instance producer = Producer({ 'bootstrap.servers': conf['bootstrap.servers'], 'sasl.mechanisms': conf['sasl.mechanisms'], 'security.protocol': conf['security.protocol'], 'sasl.username': conf['sasl.username'], 'sasl.password': conf['sasl.password'], }) # Delete Topics ccloud_lib.delete_topic( conf, ["credit_payment_history", "credit_utilization", "credit_applications"]) # Create Topics ccloud_lib.create_topic(conf, "credit_payment_history") ccloud_lib.create_topic(conf, "credit_utilization") ccloud_lib.create_topic(conf, "credit_applications") delivered_records = 0 def acked(err, msg): global delivered_records if err is not None: print("Failed to deliver message: {}".format(err)) else: delivered_records += 1 print("Produced record to topic {} partition [{}] @ offset {}".format( msg.topic(), msg.partition(), msg.offset()))