Kafka Producer超时问题连接到Bluemix上的消息中心

时间:2016-11-22 23:31:43

标签: ibm-cloud message-hub

我正在尝试连接到IBM Bluemix消息中心,并使用java按照示例

生成消息

https://github.com/ibm-messaging/message-hub-samples/tree/master/java/message-hub-kafka-ssl

producer.properties

key.serializer=org.apache.kafka.common.serialization.ByteArraySerializer
value.serializer=org.apache.kafka.common.serialization.ByteArraySerializer
acks=-1
security.protocol=SASL_SSL
sasl.mechanism=PLAIN
ssl.protocol=TLSv1.2
ssl.enabled.protocols=TLSv1.2
ssl.truststore.password=changeit
ssl.truststore.type=JKS
ssl.endpoint.identification.algorithm=HTTPS
ssl.truststore.location=/Library/Java/JavaVirtualMachines/jdk1.8.0_66.jdk/Contents/Home/jre/lib/security/cacerts

jaas.conf.template

KafkaClient {
    com.ibm.messagehub.login.MessageHubLoginModule required
    serviceName="kafka"
    user="$USERNAME"
    password="$PASSWORD";
};

Producer.java代码段

ProducerRecord<byte[], byte[]> record = new ProducerRecord<byte[], byte[]>(
                "MyTopic",
                KEY.getBytes("UTF-8"),
                "MESSAGE".getBytes("UTF-8"));

        // Synchronously wait for a response from Message Hub / Kafka.
        RecordMetadata m = kafkaProducer.send(record).get();

问题是,当我尝试获取Future RecordMetadata

时,我收到超时异常
java.util.concurrent.ExecutionException: org.apache.kafka.common.errors.TimeoutException: Failed to update metadata after 60000 ms.
at org.apache.kafka.clients.producer.KafkaProducer$FutureFailure.<init>(KafkaProducer.java:730)
at org.apache.kafka.clients.producer.KafkaProducer.doSend(KafkaProducer.java:483)
at org.apache.kafka.clients.producer.KafkaProducer.send(KafkaProducer.java:430)
at org.apache.kafka.clients.producer.KafkaProducer.send(KafkaProducer.java:353)

阅读同一主题的早期帖子

Timeout connecting to message-hub on Bluemix

提到的可能原因是主题没有创建。我可以在bluemix控制台中查看主题并进行验证,在调用消息之前,我调用了其余服务来获取主题列表

RESTRequest restApi = new RESTRequest(getRestHost(),getApiKey());

String topics = restApi.get("/admin/topics", false);

logger.info("Topics present in the system: " + topics);

它返回我试图推送消息的主题,但我收到超时错误。

有人可以帮我调试问题

更新

根据评论,我为kafka启用了调试日志,这是日志序列

2016-11-23 08:48:20.906 DEBUG 72885 --- [sage-hub-sample]    org.apache.kafka.clients.NetworkClient   : Initialize connection to node -5 for sending metadata request
2016-11-23 08:48:20.906 DEBUG 72885 --- [sage-hub-sample] org.apache.kafka.clients.NetworkClient   : Initiating connection to node -5 at kafka05-prod01.messagehub.services.us-south.bluemix.net:9093.
2016-11-23 08:48:20.914 DEBUG 72885 --- [sage-hub-sample] o.a.k.c.s.a.SaslClientAuthenticator      : Set SASL client state to SEND_HANDSHAKE_REQUEST
2016-11-23 08:48:20.915 DEBUG 72885 --- [sage-hub-sample] o.a.k.c.s.a.SaslClientAuthenticator      : Creating SaslClient: client=messagehub/ignorehost@messagehub.ibm.com;service=kafka;serviceHostname=kafka05-prod01.messagehub.services.us-south.bluemix.net;mechs=[PLAIN]
2016-11-23 08:48:20.979 DEBUG 72885 --- [sage-hub-sample] org.apache.kafka.common.metrics.Metrics  : Added sensor with name node--5.bytes-sent
2016-11-23 08:48:20.980 DEBUG 72885 --- [sage-hub-sample] org.apache.kafka.common.metrics.Metrics  : Added sensor with name node--5.bytes-received
2016-11-23 08:48:20.980 DEBUG 72885 --- [sage-hub-sample] org.apache.kafka.common.metrics.Metrics  : Added sensor with name node--5.latency
2016-11-23 08:48:20.982 DEBUG 72885 --- [sage-hub-sample] org.apache.kafka.clients.NetworkClient   : Completed connection to node -5
2016-11-23 08:48:21.080 DEBUG 72885 --- [sage-hub-sample] o.a.k.c.s.a.SaslClientAuthenticator      : Set SASL client state to RECEIVE_HANDSHAKE_RESPONSE

2016-11-23 08:48:21.264 DEBUG 72885 --- [sage-hub-sample] o.a.k.c.s.a.SaslClientAuthenticator      : Set SASL client state to INITIAL
2016-11-23 08:48:21.265 DEBUG 72885 --- [sage-hub-sample] o.a.k.c.s.a.SaslClientAuthenticator      : Set SASL client state to INTERMEDIATE
2016-11-23 08:48:21.284 DEBUG 72885 --- [sage-hub-sample]  o.apache.kafka.common.network.Selector   : Connection with kafka05-prod01.messagehub.services.us-south.bluemix.net/23.246.202.55 disconnected

java.io.EOFException: null
at org.apache.kafka.common.network.SslTransportLayer.read(SslTransportLayer.java:488)
at org.apache.kafka.common.network.NetworkReceive.readFromReadableChannel(NetworkReceive.java:81)
at org.apache.kafka.common.network.NetworkReceive.readFrom(NetworkReceive.java:71)
at org.apache.kafka.common.security.authenticator.SaslClientAuthenticator.receiveResponseOrToken(SaslClientAuthenticator.java:239)
at org.apache.kafka.common.security.authenticator.SaslClientAuthenticator.authenticate(SaslClientAuthenticator.java:182)
at org.apache.kafka.common.network.KafkaChannel.prepare(KafkaChannel.java:64)
at org.apache.kafka.common.network.Selector.pollSelectionKeys(Selector.java:318)
at org.apache.kafka.common.network.Selector.poll(Selector.java:283)
at org.apache.kafka.clients.NetworkClient.poll(NetworkClient.java:260)
at org.apache.kafka.clients.producer.internals.Sender.run(Sender.java:229)
at org.apache.kafka.clients.producer.internals.Sender.run(Sender.java:134)
at java.lang.Thread.run(Thread.java:745)

以上5个经纪人中的任何一个都记录了以上所有内容。这些都是调试语句,所以我不确定它们是否是错误。

-Tatha

2 个答案:

答案 0 :(得分:1)

我可以看到您的JAAS文件存在一些问题:

  • 您所引用的示例使用的是Kafka 0.10.0.X,因此您不应将旧的Message Hub登录模块用于Kafka 0.9。 所以替换&#34; com.ibm.messagehub.login.MessageHubLoginModule&#34; by&#34; org.apache.kafka.common.security.plain.PlainLoginModule"

  • 用户名的字段名为&#34; username&#34;而不是&#34;用户&#34;。 它应该是username =&#34; $ USERNAME&#34;

答案 1 :(得分:0)

请启用log4j DEBUG级别,Kafka客户端跟踪可以帮助识别任何连接问题。 尝试将最后一行更改为 log4j.logger.org.apache.kafka=DEBUGlog4j.properties文件中,重建并查看详细输出。随意重新发布。