OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Can't produce message from Python for spring boot consumer

  • Thread starter Thread starter vunhatchuong
  • Start date Start date
V

vunhatchuong

Guest
I make a multi-method listener consumer by following this tutorial. I'm able to consume messages from a Spring Boot producer following that exact tutorial. But unable to send consumes any message produced using Python Kafka library.

Code:
import json
from kafka import KafkaProducer

producer = KafkaProducer(
    bootstrap_servers='localhost:9092',
)

producer.send('input-topic', value=b"hello")
producer.flush()

The error is either:

Code:
Caused by: org.springframework.kafka.KafkaException:
Ambiguous methods for payload type: class java.util.LinkedHashMap: handleUserProfiles and handleComments

or

Code:
Caused by: com.fasterxml.jackson.core.JsonParseException:
Unrecognized token 'hello': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')
at [Source: REDACTED (StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION disabled); line: 1, column: 6]
<p>I make a multi-method listener consumer by following <a href="https://www.baeldung.com/spring-kafka#2-use-a-custom-messageconverter-in-the-consumer" rel="nofollow noreferrer">this tutorial</a>. I'm able to consume messages from a Spring Boot producer following that exact tutorial. But unable to send consumes any message produced using Python Kafka library.</p>
<pre class="lang-py prettyprint-override"><code>import json
from kafka import KafkaProducer

producer = KafkaProducer(
bootstrap_servers='localhost:9092',
)

producer.send('input-topic', value=b"hello")
producer.flush()
</code></pre>
<p>The error is either:</p>
<pre><code>Caused by: org.springframework.kafka.KafkaException:
Ambiguous methods for payload type: class java.util.LinkedHashMap: handleUserProfiles and handleComments
</code></pre>
<p>or</p>
<pre><code>Caused by: com.fasterxml.jackson.core.JsonParseException:
Unrecognized token 'hello': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')
at [Source: REDACTED (StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION disabled); line: 1, column: 6]
</code></pre>
 
Top