Apache kafka Can';t通过java代码从windows连接到远程卡夫卡制作者

Apache kafka Can';t通过java代码从windows连接到远程卡夫卡制作者,apache-kafka,Apache Kafka,我试图测试我的卡夫卡制作者代码,从windows eclipse到远程卡夫卡制作者(在AWS云中运行),但我在下面遇到了错误,我附加了我的代码和错误,我搜索了很多,但仍然不起作用 public static void main(String[] args) { Properties props = new Properties(); props.put("metadata.broker.list", "52.74.109.118:9092"); props.put("

我试图测试我的卡夫卡制作者代码,从windows eclipse到远程卡夫卡制作者(在AWS云中运行),但我在下面遇到了错误,我附加了我的代码和错误,我搜索了很多,但仍然不起作用

public static void main(String[] args) {

    Properties props = new Properties();
    props.put("metadata.broker.list", "52.74.109.118:9092");

    props.put("serializer.class", "kafka.serializer.StringEncoder");
    props.put("advertised.host.name", "kafka");
    // props.put("serializer.class",
    // com.funspot.utils.SerializerUtils.class);
    props.put("request.required.acks", "1");
    ProducerConfig config = new ProducerConfig(props);
    Producer<String, String> kafkaProducer = new Producer<String, String>(
            config);

    String msg = "hai";
    KeyedMessage<String, String> keyedMessage = new KeyedMessage<String, String>(
            "messaging.sms", msg);
    System.out.println(msg);

    kafkaProducer.send(keyedMessage);

    System.out.println("message sent");
}
Server.properties

# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# see kafka.server.KafkaConfig for additional details and defaults

############################# Server Basics #############################

# The id of the broker. This must be set to a unique integer for each broker.
broker.id=0

############################# Socket Server Settings #############################

# The port the socket server listens on
port=9092

# Hostname the broker will bind to. If not set, the server will bind to all interfaces
host.name=kafka

# Hostname the broker will advertise to producers and consumers. If not set, it uses the
# value for "host.name" if configured.  Otherwise, it will use the value returned from
# java.net.InetAddress.getCanonicalHostName().
# advertised.host.name=<>

# The port to publish to ZooKeeper for clients to use. If this is not set,
# it will publish the same port that the broker binds to.
# advertised.port=<>

# The number of threads handling network requests
num.network.threads=3

# The number of threads doing disk I/O
num.io.threads=8
# The send buffer (SO_SNDBUF) used by the socket server
socket.send.buffer.bytes=102400

# The receive buffer (SO_RCVBUF) used by the socket server
socket.receive.buffer.bytes=102400

# The maximum size of a request that the socket server will accept (protection against OOM)
socket.request.max.bytes=104857600


############################# Log Basics #############################

# A comma seperated list of directories under which to store log files
log.dirs=/home/ubuntu/kafka-logs

# The default number of log partitions per topic. More partitions allow greater
# parallelism for consumption, but this will also result in more files across
# the brokers.
num.partitions=1

# The number of threads per data directory to be used for log recovery at startup and flushing at shutdown.
# This value is recommended to be increased for installations with data dirs located in RAID array.
num.recovery.threads.per.data.dir=1

############################# Log Flush Policy #############################

# Messages are immediately written to the filesystem but by default we only fsync() to sync
# the OS cache lazily. The following configurations control the flush of data to disk.
# There are a few important trade-offs here:
#    1. Durability: Unflushed data may be lost if you are not using replication.
#    2. Latency: Very large flush intervals may lead to latency spikes when the flush does occur as there will be a lot of data to flush.
#    3. Throughput: The flush is generally the most expensive operation, and a small flush interval may lead to exceessive seeks.
# The settings below allow one to configure the flush policy to flush data after a period of time or
# every N messages (or both). This can be done globally and overridden on a per-topic basis.

# The number of messages to accept before forcing a flush of data to disk
#log.flush.interval.messages=10000

# The maximum amount of time a message can sit in a log before we force a flush
#log.flush.interval.ms=1000

############################# Log Retention Policy #############################


# The following configurations control the disposal of log segments. The policy can
# be set to delete segments after a period of time, or after a given size has accumulated.
# A segment will be deleted whenever *either* of these criteria are met. Deletion always happens
# from the end of the log.

# The minimum age of a log file to be eligible for deletion
log.retention.hours=168

# A size-based retention policy for logs. Segments are pruned from the log as long as the remaining
# segments don't drop below log.retention.bytes.
#log.retention.bytes=1073741824

# The maximum size of a log segment file. When this size is reached a new log segment will be created.
log.segment.bytes=1073741824

# The interval at which log segments are checked to see if they can be deleted according
# to the retention policies
log.retention.check.interval.ms=300000

# By default the log cleaner is disabled and the log retention policy will default to just delete segments after their retention expires.
# If log.cleaner.enable=true is set the cleaner will be enabled and individual logs can then be marked for log compaction.
log.cleaner.enable=false

############################# Zookeeper #############################

# Zookeeper connection string (see zookeeper docs for details).
# This is a comma separated host:port pairs, each corresponding to a zk
# server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002".
# You can also append an optional chroot string to the urls to specify the
# root directory for all kafka znodes.
zookeeper.connect=zookeeper:2181

# Timeout in ms for connecting to zookeeper
zookeeper.connection.timeout.ms=6000
<代码>被授予Apache软件基金会(ASF)以下一个或多个 #贡献者许可协议。请参阅随附的通知文件 #本作品提供了有关版权所有权的更多信息。 #ASF根据Apache许可证2.0版将此文件许可给您 #(以下简称“许可证”);除非符合以下要求,否则不得使用此文件 #执照。您可以通过以下方式获得许可证副本: # # http://www.apache.org/licenses/LICENSE-2.0 # #除非适用法律要求或书面同意,软件 #根据许可证进行的分发是按“原样”进行分发的, #无任何明示或暗示的保证或条件。 #请参阅许可证以了解管理权限和权限的特定语言 #许可证下的限制。 #有关更多详细信息和默认值,请参见kafka.server.kafkanconfig #############################服务器基础############################# #代理的id。对于每个代理,必须将其设置为唯一的整数。 broker.id=0 #############################套接字服务器设置############################# #套接字服务器侦听的端口 端口=9092 #代理将绑定到的主机名。如果未设置,服务器将绑定到所有接口 host.name=kafka #代理将向生产者和消费者公布主机名。如果未设置,则使用 #“host.name”的值(如果已配置)。否则,它将使用从返回的值 #java.net.InetAddress.getCanonicalHostName()。 #advised.host.name= #要发布到ZooKeeper供客户端使用的端口。如果没有设置, #它将发布代理绑定到的同一端口。 #A.港口= #处理网络请求的线程数 num.network.threads=3 #执行磁盘I/O的线程数 num.io.threads=8 #套接字服务器使用的发送缓冲区(sou SNDBUF) socket.send.buffer.bytes=102400 #套接字服务器使用的接收缓冲区(SO_RCVBUF) socket.receive.buffer.bytes=102400 #套接字服务器将接受的请求的最大大小(针对OOM的保护) socket.request.max.bytes=104857600 #############################日志基础############################# #以逗号分隔的目录列表,用于存储日志文件 log.dirs=/home/ubuntu/kafka日志 #每个主题的默认日志分区数。更多的分区允许更大的容量 #并行性,但这也会导致跨 #经纪人。 num.partitions=1 #启动时用于日志恢复和关闭时用于刷新的每个数据目录的线程数。 #对于数据目录位于RAID阵列中的安装,建议增加此值。 num.recovery.threads.per.data.dir=1 #############################日志刷新策略############################# #消息会立即写入文件系统,但默认情况下,我们只需fsync()进行同步 #操作系统缓存很慢。以下配置控制数据到磁盘的刷新。 #这里有几个重要的权衡: # 1. 持久性:如果不使用复制,未刷新的数据可能会丢失。 # 2. 延迟:当确实发生刷新时,非常大的刷新间隔可能会导致延迟峰值,因为将有大量数据要刷新。 # 3. 吞吐量:刷新通常是最昂贵的操作,较小的刷新间隔可能导致过度搜索。 #下面的设置允许用户配置刷新策略,以便在一段时间或之后刷新数据 #每N条消息(或两者都有)。这可以在全局范围内完成,并在每个主题的基础上覆盖。 #强制将数据刷新到磁盘之前要接受的消息数 #log.flush.interval.messages=10000 #在我们强制刷新之前,消息在日志中的最长时间 #log.flush.interval.ms=1000 #############################日志保留策略############################# #以下配置控制日志段的处理。政策可以 #设置为在一段时间后或在给定大小累积后删除段。 #只要满足这些条件中的*任一*项,就会删除一个段。删除总是发生的 #从日志的末尾。 #符合删除条件的日志文件的最短期限 log.retention.hours=168 #基于大小的日志保留策略。只要剩余的部分被删除,就从日志中删除这些部分 #段不会下降到log.retention.bytes以下。 #log.retention.bytes=1073741824 #日志段文件的最大大小。当达到此大小时,将创建一个新的日志段。 log.segment.bytes=1073741824 #检查日志段以查看是否可以根据需要删除日志段的间隔 #保留策略 log.retention.check.interval.ms=300000 #默认情况下,日志清理器处于禁用状态,日志保留策略将默认为在保留期到期后仅删除段。 #如果设置了log.cleaner.enable=true,则将启用清洁器,然后可以标记单个日志以进行日志压缩。 log.cleaner.enable=false #############################动物园管理员############################# #Zookeeper连接字符串(有关详细信息,请参阅Zookeeper文档)。 #这是一个逗号分隔的主机:端口对,每个对应一个zk #服务器。e、 g.“127.0.0.1:3000127.0.0.1:3001127.0.0.1:3002”。 #您还可以将可选的chroot字符串附加到URL以指定 #所有kafka znode的根目录。 zookeeper.connect=zookeeper:2181 #连接到zookeeper的超时(毫秒) zookeeper.connection.timeout.ms=6000 问题已修复 在kafka配置中的server.properties中添加了该行
advised.host.name=ec2ap-southerast-1.compute.amazonaws.com
(您必须提供完全合格的
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# see kafka.server.KafkaConfig for additional details and defaults

############################# Server Basics #############################

# The id of the broker. This must be set to a unique integer for each broker.
broker.id=0

############################# Socket Server Settings #############################

# The port the socket server listens on
port=9092

# Hostname the broker will bind to. If not set, the server will bind to all interfaces
host.name=kafka

# Hostname the broker will advertise to producers and consumers. If not set, it uses the
# value for "host.name" if configured.  Otherwise, it will use the value returned from
# java.net.InetAddress.getCanonicalHostName().
# advertised.host.name=<>

# The port to publish to ZooKeeper for clients to use. If this is not set,
# it will publish the same port that the broker binds to.
# advertised.port=<>

# The number of threads handling network requests
num.network.threads=3

# The number of threads doing disk I/O
num.io.threads=8
# The send buffer (SO_SNDBUF) used by the socket server
socket.send.buffer.bytes=102400

# The receive buffer (SO_RCVBUF) used by the socket server
socket.receive.buffer.bytes=102400

# The maximum size of a request that the socket server will accept (protection against OOM)
socket.request.max.bytes=104857600


############################# Log Basics #############################

# A comma seperated list of directories under which to store log files
log.dirs=/home/ubuntu/kafka-logs

# The default number of log partitions per topic. More partitions allow greater
# parallelism for consumption, but this will also result in more files across
# the brokers.
num.partitions=1

# The number of threads per data directory to be used for log recovery at startup and flushing at shutdown.
# This value is recommended to be increased for installations with data dirs located in RAID array.
num.recovery.threads.per.data.dir=1

############################# Log Flush Policy #############################

# Messages are immediately written to the filesystem but by default we only fsync() to sync
# the OS cache lazily. The following configurations control the flush of data to disk.
# There are a few important trade-offs here:
#    1. Durability: Unflushed data may be lost if you are not using replication.
#    2. Latency: Very large flush intervals may lead to latency spikes when the flush does occur as there will be a lot of data to flush.
#    3. Throughput: The flush is generally the most expensive operation, and a small flush interval may lead to exceessive seeks.
# The settings below allow one to configure the flush policy to flush data after a period of time or
# every N messages (or both). This can be done globally and overridden on a per-topic basis.

# The number of messages to accept before forcing a flush of data to disk
#log.flush.interval.messages=10000

# The maximum amount of time a message can sit in a log before we force a flush
#log.flush.interval.ms=1000

############################# Log Retention Policy #############################


# The following configurations control the disposal of log segments. The policy can
# be set to delete segments after a period of time, or after a given size has accumulated.
# A segment will be deleted whenever *either* of these criteria are met. Deletion always happens
# from the end of the log.

# The minimum age of a log file to be eligible for deletion
log.retention.hours=168

# A size-based retention policy for logs. Segments are pruned from the log as long as the remaining
# segments don't drop below log.retention.bytes.
#log.retention.bytes=1073741824

# The maximum size of a log segment file. When this size is reached a new log segment will be created.
log.segment.bytes=1073741824

# The interval at which log segments are checked to see if they can be deleted according
# to the retention policies
log.retention.check.interval.ms=300000

# By default the log cleaner is disabled and the log retention policy will default to just delete segments after their retention expires.
# If log.cleaner.enable=true is set the cleaner will be enabled and individual logs can then be marked for log compaction.
log.cleaner.enable=false

############################# Zookeeper #############################

# Zookeeper connection string (see zookeeper docs for details).
# This is a comma separated host:port pairs, each corresponding to a zk
# server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002".
# You can also append an optional chroot string to the urls to specify the
# root directory for all kafka znodes.
zookeeper.connect=zookeeper:2181

# Timeout in ms for connecting to zookeeper
zookeeper.connection.timeout.ms=6000
advertised.host.name