package com.palmnest.model.kafka;


import java.util.Properties;

import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerRecord;

/**
 * kafka生产者类
 *
 * @author wangxz
 * <p>
 * 2018年10月29日
 */
public class KafkaProducerServer {

	private Properties properties;

	public KafkaProducerServer() {
	}

	public KafkaProducerServer(Properties properties) {
		super();
		this.properties = properties;
	}

	public Properties getProperties() {
		return properties;
	}

	public void setProperties(Properties properties) {
		this.properties = properties;
	}

	public void sendMessage(String topic, String key, String msg) {

		KafkaProducer<String, String> producer = new KafkaProducer<String, String>(properties);

		ProducerRecord<String, String> record = new ProducerRecord<String, String>(topic == null ? properties.getProperty("topic") : topic,
				key, msg);
		producer.send(record);

		producer.close();

	}

}