无法将消息发布到消息中心

时间:2016-06-21 11:24:57

标签: java apache-kafka message message-hub

// Asynchronous response from Message Hub / Kafka.
kafkaProducer.send(record,
new Callback() {
   public void onCompletion(RecordMetadata m, Exception e) {
       if(e != null) {
       e.printStackTrace();
       } else { 
    log.debug(" **** Message sent, offset: " + m.offset() + 
    " @ partition " + m.partition());
    log.debug(" <<<< " +
    " document_id " + key +
    " @ " + account.getActivityId());
    }
   }
});

尝试使用上述代码将消息发布到Message Hub时,我们始终会收到以下错误。

  

2016-06-21 18:38:22- [INFO]   com.ibm.cloudant.streaming.messageHub.Client.send(476):&gt;&gt;&gt;&gt;发出   document_id julia30 @ my_database       2016-06-21 18:38:22- [DEBUG] org.apache.kafka.clients.NetworkClient $ DefaultMetadataUpdater.maybeUpdate(623):   初始化到节点-1的连接以发送元数据请求       2016-06-21 18:38:22- [DEBUG] org.apache.kafka.clients.NetworkClient.initiateConnect(487):   在。处启动与节点-1的连接   kafka01-prod01.messagehub.services.us-south.bluemix.net:9093。       2016-06-21 18:38:22- [DEBUG] org.apache.kafka.common.security.authenticator.SaslClientAuthenticator $ 1.run(105):   创建SaslClient:   client=multiuser-adapter@multiuser.messagehub.ibm.com;服务=卡夫卡; serviceHostname = kafka01-prod01.messagehub.services.us-south.bluemix.net;机甲= [GSSAPI]       2016-06-21 18:38:22- [DEBUG] com.ibm.cloudant.streaming.messageHub.AccountManager。(53):   进程ID:15825       2016-06-21 18:38:22- [INFO] org.apache.kafka.common.network.SaslChannelBuilder.buildChannel(92):   由于创建频道失败       org.apache.kafka.common.KafkaException:无法配置SaslClientAuthenticator       在org.apache.kafka.common.security.authenticator.SaslClientAuthenticator.configure(SaslClientAuthenticator.java:96)       在org.apache.kafka.common.network.SaslChannelBuilder.buildChannel(SaslChannelBuilder.java:89)       在org.apache.kafka.common.network.Selector.connect(Selector.java:162)       在org.apache.kafka.clients.NetworkClient.initiateConnect(NetworkClient.java:489)       在org.apache.kafka.clients.NetworkClient.access $ 400(NetworkClient.java:47)       在org.apache.kafka.clients.NetworkClient $ DefaultMetadataUpdater.maybeUpdate(NetworkClient.java:624)       在org.apache.kafka.clients.NetworkClient $ DefaultMetadataUpdater.maybeUpdate(NetworkClient.java:543)       在org.apache.kafka.clients.NetworkClient.poll(NetworkClient.java:254)       在org.apache.kafka.clients.producer.internals.Sender.run(Sender.java:216)       在org.apache.kafka.clients.producer.internals.Sender.run(Sender.java:128)       在java.lang.Thread.run(Thread.java:745)       引起:org.apache.kafka.common.KafkaException:创建SaslClient失败       在org.apache.kafka.common.security.authenticator.SaslClientAuthenticator.createSaslClient(SaslClientAuthenticator.java:112)       在org.apache.kafka.common.security.authenticator.SaslClientAuthenticator.configure(SaslClientAuthenticator.java:94)       ......还有10个       引起:javax.security.sasl.SaslException:PLAIN:必须指定授权标识和密码       在com.sun.security.sasl.PlainClient。(PlainClient.java:58)       at com.sun.security.sasl.ClientFactoryImpl.createSaslClient(ClientFactoryImpl.java:97)       在javax.security.sasl.Sasl.createSaslClient(Sasl.java:384)       在com.ibm.messagehub.login.MessageHubSaslClientFactory.createSaslClient(MessageHubSaslClientFactory.java:77)       在javax.security.sasl.Sasl.createSaslClient(Sasl.java:384)       在org.apache.kafka.common.security.authenticator.SaslClientAuthenticator $ 1.run(SaslClientAuthenticator.java:107)       在org.apache.kafka.common.security.authenticator.SaslClientAuthenticator $ 1.run(SaslClientAuthenticator.java:102)       at java.security.AccessController.doPrivileged(Native Method)       在javax.security.auth.Subject.doAs(Subject.java:422)       在org.apache.kafka.common.security.authenticator.SaslClientAuthenticator.createSaslClient(SaslClientAuthenticator.java:102)       ......还有11个       2016-06-21 18:38:22- [ERROR] org.apache.kafka.clients.producer.internals.Sender.run(130):Uncaught   kafka生产者I / O线程中的错误:       org.apache.kafka.common.KafkaException:org.apache.kafka.common.KafkaException:配置失败   SaslClientAuthenticator       在org.apache.kafka.common.network.SaslChannelBuilder.buildChannel(SaslChannelBuilder.java:93)       在org.apache.kafka.common.network.Selector.connect(Selector.java:162)       在org.apache.kafka.clients.NetworkClient.initiateConnect(NetworkClient.java:489)       在org.apache.kafka.clients.NetworkClient.access $ 400(NetworkClient.java:47)       在org.apache.kafka.clients.NetworkClient $ DefaultMetadataUpdater.maybeUpdate(NetworkClient.java:624)       在org.apache.kafka.clients.NetworkClient $ DefaultMetadataUpdater.maybeUpdate(NetworkClient.java:543)       在org.apache.kafka.clients.NetworkClient.poll(NetworkClient.java:254)       在org.apache.kafka.clients.producer.internals.Sender.run(Sender.java:216)       在org.apache.kafka.clients.producer.internals.Sender.run(Sender.java:128)       在java.lang.Thread.run(Thread.java:745)       引起:org.apache.kafka.common.KafkaException:无法配置SaslClientAuthenticator       在org.apache.kafka.common.security.authenticator.SaslClientAuthenticator.configure(SaslClientAuthenticator.java:96)       在org.apache.kafka.common.network.SaslChannelBuilder.buildChannel(SaslChannelBuilder.java:89)       ......还有9个       引起:org.apache.kafka.common.KafkaException:创建SaslClient失败       在org.apache.kafka.common.security.authenticator.SaslClientAuthenticator.createSaslClient(SaslClientAuthenticator.java:112)       在org.apache.kafka.common.security.authenticator.SaslClientAuthenticator.configure(SaslClientAuthenticator.java:94)       ......还有10个       引起:javax.security.sasl.SaslException:PLAIN:必须指定授权标识和密码       在com.sun.security.sasl.PlainClient。(PlainClient.java:58)       at com.sun.security.sasl.ClientFactoryImpl.createSaslClient(ClientFactoryImpl.java:97)       在javax.security.sasl.Sasl.createSaslClient(Sasl.java:384)       在com.ibm.messagehub.login.MessageHubSaslClientFactory.createSaslClient(MessageHubSaslClientFactory.java:77)       在javax.security.sasl.Sasl.createSaslClient(Sasl.java:384)       在org.apache.kafka.common.security.authenticator.SaslClientAuthenticator $ 1.run(SaslClientAuthenticator.java:107)       在org.apache.kafka.common.security.authenticator.SaslClientAuthenticator $ 1.run(SaslClientAuthenticator.java:102)       at java.security.AccessController.doPrivileged(Native Method)       在javax.security.auth.Subject.doAs(Subject.java:422)       在org.apache.kafka.common.security.authenticator.SaslClientAuthenticator.createSaslClient(SaslClientAuthenticator.java:102)       ......还有11个       2016-06-21 18:38:22- [ERROR] org.apache.kafka.clients.producer.internals.Sender.run(130):Uncaught   kafka生产者I / O线程中的错误:       显示java.lang.NullPointerException       在org.apache.kafka.common.network.Selector.poll(Selector.java:268)       在org.apache.kafka.clients.NetworkClient.poll(NetworkClient.java:256)       在org.apache.kafka.clients.producer.internals.Sender.run(Sender.java:216)       在org.apache.kafka.clients.producer.internals.Sender.run(Sender.java:128)       在java.lang.Thread.run(Thread.java:745)

制作人的设置如下:

```

 compression.type = none
 metric.reporters = []
 metadata.max.age.ms = 300000
 metadata.fetch.timeout.ms = 60000
 reconnect.backoff.ms = 50
 sasl.kerberos.ticket.renew.window.factor = 0.8
 bootstrap.servers = [kafka01-prod01.messagehub.services.us-south.bluemix.net:9093]
 retry.backoff.ms = 100
 sasl.kerberos.kinit.cmd = /usr/bin/kinit
 buffer.memory = 33554432
 timeout.ms = 30000
 key.serializer = class org.apache.kafka.common.serialization.StringSerializer
 sasl.kerberos.service.name = null
 sasl.kerberos.ticket.renew.jitter = 0.05
 ssl.keystore.type = JKS
 ssl.trustmanager.algorithm = PKIX
 block.on.buffer.full = false
 ssl.key.password = null
 max.block.ms = 60000
 sasl.kerberos.min.time.before.relogin = 60000
 connections.max.idle.ms = 540000
 ssl.truststore.password = [hidden]
 max.in.flight.requests.per.connection = 5
 metrics.num.samples = 2
 client.id = kafka01-prod01.messagehub.services.us-south.bluemix.net%3A9093_8qp87X32V6PK5epv.1
 ssl.endpoint.identification.algorithm = HTTPS
 ssl.protocol = TLSv1.2
 request.timeout.ms = 30000
 ssl.provider = null
 ssl.enabled.protocols = [TLSv1.2]
 acks = -1
 batch.size = 16384
 ssl.keystore.location = null
 receive.buffer.bytes = 32768
 ssl.cipher.suites = null
 ssl.truststore.type = JKS
 security.protocol = SASL_SSL
 retries = 1
 max.request.size = 1048576
 value.serializer = class  org.apache.kafka.common.serialization.StringSerializer
 ssl.truststore.location = /Users/jiangph/tools/liberty/usr/shared/resources/keystore.jks
 ssl.keystore.password = null
 ssl.keymanager.algorithm = SunX509
 metrics.sample.window.ms = 30000
 send.buffer.bytes = 131072
 linger.ms = 0

```

使用上述设置,使用Message Hub rest API创建主题没有问题。尝试发布消息时会出现问题。

任何想法都受到高度赞赏。

3 个答案:

答案 0 :(得分:3)

MessageHub REST客户端API以与Java Kafka客户端不同的方式进行身份验证。

我发现您的日志中存在身份验证错误:  javax.security.sasl.SaslException: PLAIN: authorization ID and password must be specified at com.sun.security.sasl.PlainClient.

为MessageHub SASL身份验证配置java客户端, 请参阅以下的java示例:

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

请注意,您的生产者属性应包含以下内容:

https://github.com/ibm-messaging/message-hub-samples/blob/master/java/message-hub-kafka-ssl/resources/producer.properties

你的jaas.conf文件看起来应该是

KafkaClient { com.ibm.messagehub.login.MessageHubLoginModule required serviceName="kafka" username="your-username" password="your-password"; }; 并且您必须在类路径中拥有MessageHub登录jar。

HTH, 江户时代

答案 1 :(得分:1)

原来问题与身份验证完全无关,而且与密钥/值序列化有关。改变

    props.setProperty("key.serializer", 
            "org.apache.kafka.common.serialization.StringSerializer");
    props.setProperty("value.serializer", 
            "org.apache.kafka.common.serialization.StringSerializer")

    props.setProperty("key.serializer", "org.apache.kafka.common.serialization.ByteArraySerializer");
    props.setProperty("value.serializer", "org.apache.kafka.common.serialization.ByteArraySerializer");

解决了javax.security.sasl.SaslException

奇怪的是,一旦你成功使用了ByteArraySerialization,你甚至可以切换回StringSerialization,事情会继续发挥作用。

答案 2 :(得分:1)

我可以使用StringSerializer运行使用者或生产者样本,并且从未需要切换。 序列化程序不适用于SASL身份验证。