我遇到了#34;复制因子:比可用的代理大1:多节点集群上的0"在多节点kafka集群中,尝试使用下面提到的createTopics函数创建主题时。我有3个kafka经纪人,我试图为每个主题创建2个分区并将复制因子保持为1.不确定为什么会出现此错误。在单节点设置(1个zookeeper和1个kafka经纪人)中完全相同。
非常感谢任何帮助/
错误:
kafka.admin.AdminOperationException: replication factor: 1 larger than available brokers: 0
at kafka.admin.AdminUtils$.assignReplicasToBrokers(AdminUtils.scala:117)
at kafka.admin.AdminUtils$.createTopic(AdminUtils.scala:403)
at kafka.admin.AdminUtils.createTopic(AdminUtils.scala)
at io.confluent.examples.producer.ZookeeperUtil.createTopics(ZookeeperUtil.java:98)
at io.confluent.examples.producer.ProducerGroup.<init>(ProducerGroup.java:50)
at io.confluent.examples.producer.ProducerGroup.main(ProducerGroup.java:124)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:297)
at java.lang.Thread.run(Thread.java:745)
private static final int DEFAULT_SESSION_TIMEOUT = 10 * 1000;
private static final int DEFAULT_CONNECTION_TIMEOUT = 8 * 1000;
private static final String ZOOKEEPER_CONNECT = "zNode01:2181,zNode02:2181,zNode03:2181";
/**
* Opens a new ZooKeeper client to access the Kafka broker.
*/
private static ZkClient connectToZookeeper ()
{
return new ZkClient(ZOOKEEPER_CONNECT,
DEFAULT_SESSION_TIMEOUT,
DEFAULT_CONNECTION_TIMEOUT,
ZKStringSerializer$.MODULE$);
}
/**
* Given a ZooKeeper client instance, accesses the broker and returns
* information about Kafka's contents.
*
* @param zookeeperClient A ZooKeeper client to access broker information
* through.
*/
private static ZkUtils zookeeperUtility (ZkClient zookeeperClient)
{
boolean isSecureCluster = false;
return new ZkUtils(zookeeperClient,
new ZkConnection(ZOOKEEPER_CONNECT),
isSecureCluster);
}
public static void createTopics (ArrayList<String> names, int partitions, int replication)
{
ZkClient zkClient = connectToZookeeper();
ZkUtils zkUtils = zookeeperUtility(zkClient);
try{
for (String name: names)
{
if (existsTopic(name))
continue;
AdminUtils.createTopic(zkUtils, name, partitions, replication, new Properties(),RackAwareMode.Disabled$.MODULE$);
}
} catch (Exception ex) {
ex.printStackTrace();
} finally {
if (zkClient != null) {
zkClient.close();
}
}
}
我按照以下说明设置了多节点kafka群集。
设置多节点Apache ZooKeeper集群
在群集的每个节点上,将以下行添加到文件kafka / config / zookeeper.properties
server.1=zNode01:2888:3888
server.2=zNode02:2888:3888
server.3=zNode03:2888:3888
#add here more servers if you want
initLimit=5
syncLimit=2
在群集的每个节点上,在dataDir属性表示的文件夹中创建名为myid的文件(默认情况下,文件夹为/ tmp / zookeeper)。 myid文件应该只包含znode的id(zNode01为'1',ZNode02为'2'等等)
设置多代理Apache Kafka集群
在群集的每个节点上修改文件kafka / config / server.properties中的属性zookeeper.connect:
zookeeper.connect=zNode01:2181,zNode02:2181,zNode03:2181
在群集的每个节点上,从文件kafka / config / server.properties修改属性host.name: host.name = zNode0x
在群集的每个节点上,从文件kafka / config / server.properties修改属性broker.id(群集中的每个代理都应具有唯一ID)
答案 0 :(得分:0)
错误是说您的代理没有运行,而不是您不能为客户端使用多个 Zookeeper 地址(是的,您可以)
在较新版本的 Kafka 中,您会将 AdminClient
与 bootstrap.server
一起使用,而不是 zookeeper.connect