question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Kafka Consumer - StringIndexOutOfBoundsException from EmbeddedHeadersMessageConverter

See original GitHub issue

I’m troubleshooting an issue with my spring-cloud project where despite binding successfully to my Kafka cluster, producing and consuming messages, the consumer is throwing an exception in my logs.

I dug into KafkaMessageChannelBinder and EmbeddedHeadersMessageConverter. It seems like it is expecting a header on my message where one may not exist? I sent these messages from the Kafka console producer.

Here’s the stacktrace:

2015-11-24T14:30:29.89-0600 [App/0]      OUT 2015-11-24 20:30:29.892 ERROR 36 ---  --- [pool-2-thread-1] fkaMessageChannelBinder$ReceivingHandler : Could not convert message: 6D794B61666B614D65737361676546726F6D436F6E736F6C6550726F6475636572
2015-11-24T14:30:29.89-0600 [App/0]      OUT java.lang.StringIndexOutOfBoundsException: String index out of range: 123
2015-11-24T14:30:29.89-0600 [App/0]      OUT    at java.lang.String.checkBounds(String.java:385)
2015-11-24T14:30:29.89-0600 [App/0]      OUT    at java.lang.String.<init>(String.java:425)
2015-11-24T14:30:29.89-0600 [App/0]      OUT    at org.springframework.cloud.stream.binder.EmbeddedHeadersMessageConverter.oldExtractHeaders(EmbeddedHeadersMessageConverter.java:131)
2015-11-24T14:30:29.89-0600 [App/0]      OUT    at org.springframework.cloud.stream.binder.EmbeddedHeadersMessageConverter.extractHeaders(EmbeddedHeadersMessageConverter.java:104)
2015-11-24T14:30:29.89-0600 [App/0]      OUT    at org.springframework.cloud.stream.binder.kafka.KafkaMessageChannelBinder$ReceivingHandler.handleRequestMessage(KafkaMessageChannelBinder.java:845)
2015-11-24T14:30:29.89-0600 [App/0]      OUT    at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:99)
2015-11-24T14:30:29.89-0600 [App/0]      OUT    at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:127)
2015-11-24T14:30:29.89-0600 [App/0]      OUT    at org.springframework.integration.channel.FixedSubscriberChannel.send(FixedSubscriberChannel.java:69)
2015-11-24T14:30:29.89-0600 [App/0]      OUT    at org.springframework.integration.channel.FixedSubscriberChannel.send(FixedSubscriberChannel.java:63)
2015-11-24T14:30:29.89-0600 [App/0]      OUT    at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:115)
2015-11-24T14:30:29.89-0600 [App/0]      OUT    at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:45)
2015-11-24T14:30:29.89-0600 [App/0]      OUT    at org.springframework.messaging.core.AbstractMessageSendingTemplate.send(AbstractMessageSendingTemplate.java:105)
2015-11-24T14:30:29.89-0600 [App/0]      OUT    at org.springframework.integration.endpoint.MessageProducerSupport.sendMessage(MessageProducerSupport.java:105)
2015-11-24T14:30:29.89-0600 [App/0]      OUT    at org.springframework.integration.kafka.inbound.KafkaMessageDrivenChannelAdapter.access$300(KafkaMessageDrivenChannelAdapter.java:43)
2015-11-24T14:30:29.89-0600 [App/0]      OUT    at org.springframework.integration.kafka.inbound.KafkaMessageDrivenChannelAdapter$AutoAcknowledgingChannelForwardingMessageListener.doOnMessage(KafkaMessageDrivenChannelAdapter.java:171)
2015-11-24T14:30:29.89-0600 [App/0]      OUT    at org.springframework.integration.kafka.listener.AbstractDecodingMessageListener.onMessage(AbstractDecodingMessageListener.java:50)
2015-11-24T14:30:29.89-0600 [App/0]      OUT    at org.springframework.integration.kafka.listener.QueueingMessageListenerInvoker$KafkaMessageDispatchingSubscriber.onNext(QueueingMessageListenerInvoker.java:138)
2015-11-24T14:30:29.89-0600 [App/0]      OUT    at org.springframework.integration.kafka.listener.QueueingMessageListenerInvoker$KafkaMessageDispatchingSubscriber.onNext(QueueingMessageListenerInvoker.java:127)
2015-11-24T14:30:29.89-0600 [App/0]      OUT    at reactor.core.processor.util.RingBufferSubscriberUtils.route(RingBufferSubscriberUtils.java:62)
2015-11-24T14:30:29.89-0600 [App/0]      OUT    at reactor.core.processor.RingBufferProcessor$BatchSignalProcessor.run(RingBufferProcessor.java:786)
2015-11-24T14:30:29.89-0600 [App/0]      OUT    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
2015-11-24T14:30:29.89-0600 [App/0]      OUT    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
2015-11-24T14:30:29.89-0600 [App/0]      OUT    at java.lang.Thread.run(Thread.java:745)
2015-11-24T14:30:29.89-0600 [App/0]      OUT 2015-11-24 20:30:29.893 ERROR 36 ---  --- [pool-2-thread-1] com.foo.KafkaConsumer                    : *** KafkaConsumer payload message myKafkaMessageFromConsoleProducer

That message was produced by using this command from the Kafka command line tools: ./kafka-console-producer.sh --broker-list=10.245.0.11:9092 --topic bar4 Then, entering the text message of myKafkaMessageFromConsoleProducer and hitting enter.

As you can see from the last line of the stacktrace, it retrieved my message. And, I can see it from Java. But, it’s logging out this exception for the header which could really be a problem for my logs. But, I’m probably misunderstanding something about headers.

Setup: I’m running this locally on my Linux Mint workstation with BOSH and Cloud Foundry installed. I’ve pushed my Spring Boot app using cf push. And, I’m binding to Kafka using my custom service broker. The Kafka cluster has been pushed via BOSH directly and functions normally from the command line tools. It’s using the Open JDK Buildpack with CF, Java8, BOSH 1.3123.0, cf version 6.13.0-e68ce0f-2015-10-15T22:53:58+00:0.

I pushed a small repository that reproduces this exception for me. See com.foo.KafkaConsumer: https://github.com/Blackbaud-KevinHutson/spring-cloud-kafka-sample

Thanks for any info you can provide. If I just need to override something that would also be acceptable.

Thanks! Kevin

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

6reactions
mbogoevicicommented, Apr 11, 2016

Hi, the correct property name is now:

spring.cloud.stream.bindings.input.consumer.headerMode=raw

Our documentation for RC2 missed it. Also see https://github.com/spring-cloud/spring-cloud-stream/issues/477

5reactions
devrajramcommented, Aug 25, 2017

Although this is very old post but here is the property for YAML, currently:

spring:
  cloud:
    stream:
      bindings:
        input:
          consumer: 
            header-mode: raw

Hope this helps some one.

Read more comments on GitHub >

github_iconTop Results From Across the Web

EmbeddedHeadersMessageCon...
Spring Cloud Stream Kafka - EmbeddedHeadersMessageConverter - java.lang.StringIndexOutOfBoundsException: String index out of range in · apache- ...
Read more >
spring cloud - java.lang.StringIndexOutOfBoundsException: String ...
extractHeaders(EmbeddedHeadersMessageConverter.java:104) 2015-11-24T14:30:29.89-0600 [App/0] OUT at org.springframework.cloud.stream.binder.kafka.
Read more >
StringIndexOutOfBoundsException из ...
extractHeaders(EmbeddedHeadersMessageConverter.java:104) ~[spring-cloud-stream-1.0.0.RC1.jar:1.0.0.RC1] at org.springframework.cloud.stream.binder.kafka.
Read more >
microservice messaging db-assigned identifiers - Coder guy Q&A
I have a question about how messaging via kafka is typically done in a microservice architecture. We're planning to have a coordination layer...
Read more >
Java 将kafka日志消息重定向到单独的日志(catalina.out除外 ...
Spring Kafka正在生成大量日志消息,它们会自动转到catalina.out。 ... NetworkClient : [Consumer clientId=consumer-12, groupId=DataRiver1] 10 partitions have ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found