Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/apache-kafka/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot Spring Cloud Kafka活页夹转换错误(消费者)_Spring Boot_Apache Kafka_Spring Cloud_Apache Kafka Streams_Spring Cloud Stream - Fatal编程技术网

Spring boot Spring Cloud Kafka活页夹转换错误(消费者)

Spring boot Spring Cloud Kafka活页夹转换错误(消费者),spring-boot,apache-kafka,spring-cloud,apache-kafka-streams,spring-cloud-stream,Spring Boot,Apache Kafka,Spring Cloud,Apache Kafka Streams,Spring Cloud Stream,我构建了一个SpringBoot应用程序,使用SpringCloudStream、SpringKafka等依赖项访问kafka。目前,我正在尝试从Topic访问数据到我的consumer类,但出现以下错误 Caused by: java.lang.IllegalArgumentException: This converter can only convert byte[] to String at org.springframework.util.Assert.isTrue(Asser

我构建了一个SpringBoot应用程序,使用SpringCloudStream、SpringKafka等依赖项访问kafka。目前,我正在尝试从Topic访问数据到我的consumer类,但出现以下错误

Caused by: java.lang.IllegalArgumentException: This converter can only convert byte[] to String
    at org.springframework.util.Assert.isTrue(Assert.java:121) ~[spring-core-5.2.9.RELEASE.jar:5.2.9.RELEASE]
我使用producer成功地将数据插入主题,命令行kafka consumer显示如下所示的数据

Comment [content=kkklskjdflsjdf, author=kkkkk]
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.cloud.stream.messaging.Sink;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Service;

import com.ust.kafkaspringstream.springstream.Service.IConsumer;
import com.ust.kafkaspringstream.springstream.model.Comment;

@Service
@EnableBinding(Sink.class)
public class Consumer implements IConsumer{
    @StreamListener(target = Sink.INPUT)
    public void handle(@Payload Comment comment) {
        System.out.println(comment.getContent());
    }
}
下面是我用来将数据推入主题的代码

        Comment comment = new Comment();
        comment.setAuthor("kkkkk");
        comment.setContent("kkklskjdflsjdf");
        producer.getMySource()
            .output()
            .send(MessageBuilder.withPayload(comment)
                    .setHeader("type", "chat")
                    .build());
下面给出了我的消费者分类

Comment [content=kkklskjdflsjdf, author=kkkkk]
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.cloud.stream.messaging.Sink;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Service;

import com.ust.kafkaspringstream.springstream.Service.IConsumer;
import com.ust.kafkaspringstream.springstream.model.Comment;

@Service
@EnableBinding(Sink.class)
public class Consumer implements IConsumer{
    @StreamListener(target = Sink.INPUT)
    public void handle(@Payload Comment comment) {
        System.out.println(comment.getContent());
    }
}
我的财产列在下面

spring.cloud.stream.default-binder=kstream
spring.cloud.stream.kafka.binder.brokers=localhost:9092
spring.cloud.stream.bindings.input.binder=kafka
spring.cloud.stream.bindings.input.destination=wtTopic
spring.cloud.stream.bindings.input.content-type=text/plain
spring.cloud.stream.bindings.input.group=input-group-1
spring.cloud.stream.bindings.output.binder=kafka
spring.cloud.stream.bindings.output.destination=wtTopic
spring.cloud.stream.bindings.output.content-type=text/plain
spring.cloud.stream.bindings.output.group=output-group-1


我只需要将我的消息转换回我用于将数据推送到主题中的相同pojo,在SpringCloudStream和SpringBoot应用程序中有什么方法可以做到这一点吗?我正在使用spring boot 2.3.4版

对于输入和输出内容类型,您应该使用内容类型application/json而不是text/plain(或者迁移到AVRO以获得更好的性能)。另外,你能和我们分享你的Spring POM依赖项吗?最后,我认为制作人不能有一个群组,因为群组只用于消费。