kafka 创建topic 并使用java/.net 连接
2020-12-13 05:51
标签:depend git end val lis linq ext prot 消息 创建 topic javatest bin/kafka-topics.sh --bootstrap-server localhost:9092 --create --topic javatest --partitions 3 --replication-factor 1 java 连接:https://www.cnblogs.com/duanjt/p/10132116.html pom.xml 特别注意的需要设置:advertised.listeners 然后附上连接的 Producer 和Consumer 的代码 使用kafka-net 也可以连接。 另外java 的全部源代码地址: https://github.com/fmyuan2000/kafka01 kafka 创建topic 并使用java/.net 连接 标签:depend git end val lis linq ext prot 消息 原文地址:https://www.cnblogs.com/wenwenxiaoxing/p/11152214.html
kafka-clientsimport java.util.Properties;
import java.util.Random;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerConfig;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.common.serialization.StringSerializer;
public class Producer {
public static String topic = "javatest";//定义主题
public static void main(String[] args) throws InterruptedException {
Properties p = new Properties();
p.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "www.top1novel.com:9092");//kafka地址,多个地址用逗号分割
p.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
p.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
KafkaProducer
import java.util.Collections;
import java.util.Properties;
import org.apache.kafka.clients.consumer.ConsumerConfig;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.kafka.clients.consumer.ConsumerRecords;
import org.apache.kafka.clients.consumer.KafkaConsumer;
import org.apache.kafka.common.serialization.StringDeserializer;
public class Consumer {
public static void main(String[] args) {
Properties p = new Properties();
p.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, "www.top1novel.com:9092");
p.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
p.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
p.put(ConsumerConfig.GROUP_ID_CONFIG, "test-consumer-group");
KafkaConsumer
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using KafkaNet;
using KafkaNet.Model;
using KafkaNet.Protocol;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("this ");
var options = new KafkaOptions(new Uri("http://www.top1novel.com:9092"));
var router = new BrokerRouter(options);
var producer = new Producer(router);
List
上一篇:windows dll
下一篇:windows常用环境变量
文章标题:kafka 创建topic 并使用java/.net 连接
文章链接:http://soscw.com/essay/31881.html