我正在运行一个spring-boot应用程序,它向kafka生成消息。当我运行应用程序来查询我的本地Kafka一切都是好的。但一旦我尝试查询在ec2示例上运行的一个,我就会得到:
java.net.UnknownHostException: ip-172-31-32-47.us-east-2.compute.internal
at java.base/java.net.InetAddress$CachedAddresses.get(InetAddress.java:797) ~[na:na]
at java.base/java.net.InetAddress.getAllByName0(InetAddress.java:1505) ~[na:na]
at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1364) ~[na:na]
at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1298) ~[na:na]
at org.apache.kafka.clients.ClientUtils.resolve(ClientUtils.java:110) ~[kafka-clients-2.5.0.jar:na]
at org.apache.kafka.clients.ClusterConnectionStates$NodeConnectionState.currentAddress(ClusterConnectionStates.java:403) ~[kafka-clients-2.5.0.jar:na]
at org.apache.kafka.clients.ClusterConnectionStates$NodeConnectionState.access$200(ClusterConnectionStates.java:363) ~[kafka-clients-2.5.0.jar:na]
at org.apache.kafka.clients.ClusterConnectionStates.currentAddress(ClusterConnectionStates.java:151) ~[kafka-clients-2.5.0.jar:na]
at org.apache.kafka.clients.NetworkClient.initiateConnect(NetworkClient.java:955) ~[kafka-clients-2.5.0.jar:na]
at org.apache.kafka.clients.NetworkClient.ready(NetworkClient.java:293) ~[kafka-clients-2.5.0.jar:na]
at org.apache.kafka.clients.admin.KafkaAdminClient$AdminClientRunnable.sendEligibleCalls(KafkaAdminClient.java:1018) ~[kafka-clients-2.5.0.jar:na]
at org.apache.kafka.clients.admin.KafkaAdminClient$AdminClientRunnable.processRequests(KafkaAdminClient.java:1260) ~[kafka-clients-2.5.0.jar:na]
at org.apache.kafka.clients.admin.KafkaAdminClient$AdminClientRunnable.run(KafkaAdminClient.java:1203) ~[kafka-clients-2.5.0.jar:na]
at java.base/java.lang.Thread.run(Thread.java:834) ~[na:na]
在此处输入图像描述
知道这是应用程序配置:
spring.cloud.stream.kafka.binder.brokers=ec2-18-221-154-81.us-east-2.compute.amazonaws.com:9092
sending.message.timeout.ms=5000
spring.cloud.stream.bindings.output.destination=meetupTopic
spring.cloud.stream.bindings.output.producer.partitionCount=1
spring.cloud.stream.bindings.output.content-type=text/plain
spring.cloud.stream.bindings.output.producer.headerMode=none
这是制片人班:
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;
import org.springframework.web.socket.WebSocketMessage;
@Component
@EnableBinding(Source.class)
public class RsvpsKafkaProducer {
@Value("${sending.message.timeout.ms}")
private int timeout;
private final Source source;
public RsvpsKafkaProducer(Source source) {
this.source = source;
}
public void sendRsvpMessage(WebSocketMessage<?> message) {
source.output().send(MessageBuilder.withPayload(message.getPayload()).build(), timeout);
}
}
我尝试了很多修补程序,例如更改区域、编辑运行kafka的示例上的/etc/hosts文件、检查安全组、更改操作系统。这可能是Kafka的问题与它的配置有关。有什么解决办法或建议吗?
1条答案
按热度按时间6jjcrrmo1#
我必须在apachekafka配置中添加ec2dns,即: