我正在尝试连接到消息中心服务。如果我使用 REST API,我可以连接,但是当我尝试从我的 Java 程序连接时,总是会超时
我正在使用下一个配置:
Properties producerProps = new Properties();
producerProps.put(SslConfigs.SSL_PROTOCOL_CONFIG, "TLSv1.2");
producerProps.put(SslConfigs.SSL_ENABLED_PROTOCOLS_CONFIG, "TLSv1.2");
producerProps.put(SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG, "/Library/Java/JavaVirtualMachines/jdk1.8.0_66.jdk/Contents/Home/jre/lib/security/cacerts");
producerProps.put(SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG, "changeit");
producerProps.put(SslConfigs.SSL_TRUSTSTORE_TYPE_CONFIG, "JKS");
producerProps.put(SslConfigs.SSL_ENDPOINT_IDENTIFICATION_ALGORITHM_CONFIG, "HTTPS");
producerProps.put(CommonClientConfigs.SECURITY_PROTOCOL_CONFIG, "SSL");
producerProps.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, org.apache.kafka.common.serialization.ByteArraySerializer.class);
producerProps.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, org.apache.kafka.common.serialization.ByteArraySerializer.class);
producerProps.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "kafka01-prod01.messagehub.services.us-south.bluemix.net:9093,kafka02-prod01.messagehub.services.us-south.bluemix.net:9093,kafka03-prod01.messagehub.services.us-south.bluemix.net:9093,kafka04-prod01.messagehub.services.us-south.bluemix.net:9093,kafka05-prod01.messagehub.services.us-south.bluemix.net:9093");
producerProps.put(ProducerConfig.CLIENT_ID_CONFIG, "myApiKey");
KafkaProducer<byte[], byte[]> kafkaProducer = new KafkaProducer<>(producerProps);
ProducerRecord<byte[], byte[]> producerRecord = new ProducerRecord<>("myTopic", "records".getBytes(), "[{ \"value\" : \"test\" }]".getBytes());
RecordMetadata metadata = kafkaProducer.send(producerRecord).get();
System.out.println("Offset: " + metadata.offset());
kafkaProducer.close();
过了一会儿,错误是
Exception in thread "main" java.util.concurrent.ExecutionException: org.apache.kafka.common.errors.TimeoutException: Failed to update metadata after 231 ms.
at org.apache.kafka.clients.producer.KafkaProducer$FutureFailure.<init>(KafkaProducer.java:706)
at org.apache.kafka.clients.producer.KafkaProducer.send(KafkaProducer.java:453)
at org.apache.kafka.clients.producer.KafkaProducer.send(KafkaProducer.java:339)
我正在使用 kafka-clients 版本 0.9.0.0
有什么想法吗?