
com.github.hackerwin7.mysql.tracker.monitor.MonitorToKafkaProducer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mysql-tracker Show documentation
Show all versions of mysql-tracker Show documentation
mysql-tracker is a mysql binlog dumper that fetch and parse the binlog event
The newest version!
package com.github.hackerwin7.mysql.tracker.monitor;
import kafka.javaapi.producer.Producer;
import kafka.producer.KeyedMessage;
import kafka.producer.ProducerConfig;
import java.util.Properties;
/**
* Created by hp on 14-9-26.
*/
public class MonitorToKafkaProducer {
private String brokerList = "localhost:9092";
private String serializerClass = "kafka.serializer.StringEncoder";
private String partitionerClass = "SimplePartitioner";
private String acks = "1";
private String topic = "mysql_tracker_parser";
private ProducerConfig config = null;
private Properties props = null;
private Producer producer = null;
public MonitorToKafkaProducer() {
}
public MonitorToKafkaProducer(String broker, String serializer, String partitioner, String acks) {
brokerList = broker;
serializerClass = serializer;
partitionerClass = partitioner;
this.acks = acks;
}
public void open() throws Exception {
props = new Properties();
props.put("metadata.broker.list", brokerList);
props.put("serializer.class", serializerClass);
props.put("partitioner.class", partitionerClass);
props.put("request.required.acks", acks);
config = new ProducerConfig(props);
producer = new Producer(config);
}
public void send(String key ,String msg) throws Exception {
if(config == null) {
throw new NullPointerException("process open function first!!!");
}
KeyedMessage message = new KeyedMessage(topic, key, msg);
producer.send(message);
}
public void close() throws Exception {
producer.close();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy