Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/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 Boot_Spring Cloud Stream_Kafka Producer Api - Fatal编程技术网

Spring boot 春云溪,;卡夫卡:卡夫卡生产者序列化错误

Spring boot 春云溪,;卡夫卡:卡夫卡生产者序列化错误,spring-boot,spring-cloud-stream,kafka-producer-api,Spring Boot,Spring Cloud Stream,Kafka Producer Api,我对春天的云流和卡夫卡都很陌生。在有效负载中发送字符串时,我从卡夫卡制作人处收到以下错误。非常感谢您的任何帮助或见解。我试着使用bytearray序列化器/反序列化器以及json,而不是纯文本 错误消息: org.apache.kafka.common.errors.SerializationException:无法将类[B]的值转换为value.serializer中指定的类org.apache.kafka.common.serialization.StringSerializer 错误堆栈:

我对春天的云流和卡夫卡都很陌生。在有效负载中发送字符串时,我从卡夫卡制作人处收到以下错误。非常感谢您的任何帮助或见解。我试着使用bytearray序列化器/反序列化器以及json,而不是纯文本

错误消息: org.apache.kafka.common.errors.SerializationException:无法将类[B]的值转换为value.serializer中指定的类org.apache.kafka.common.serialization.StringSerializer

错误堆栈:

2019-10-25 16:13:40.762错误4628---[XNIO-1 task-1]o.z.problem.spring.common.AdviceTraits:内部服务器错误
org.springframework.messaging.MessageHandlingException:消息处理程序[org.springframework.cloud.stream.binder.kafka.KafkaMessageChannelBinder]中出现错误$ProducerConfigurationMessageHandler@ebad77c];嵌套异常为org.apache.kafka.common.errors.SerializationException:无法转换类的值[B到value.serializer中指定的类org.apache.kafka.common.serialization.StringSerializer
在org.springframework.integration.support.utils.IntegrationUtils.wrapinHandlingExceptionIfNeeded上(IntegrationUtils.java:189)
位于org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:186)
位于org.springframework.cloud.stream.binder.AbstractMessageChannelBinder$SendingHandler.handleMessageInternal(AbstractMessageChannelBinder.java:1095)
位于org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:176)
位于org.springframework.integration.dispatcher.AbstractDispatcher.tryoOptimizedDispatch(AbstractDispatcher.java:115)
位于org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:132)
位于org.springframework.integration.dispatcher.UnicastingDispatcher.dispatcher(UnicastingDispatcher.java:105)
位于org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:73)
位于org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:453)
位于org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:401)
在com.ll.kafkaservice.greeting.GreetingsService.sendGreeting上(GreetingsService.java:30)
在com.ll.kafkaservice.greeting.GreetingsController.greetings上(GreetingsController.java:29)
在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)处
....
原因:org.apache.kafka.common.errors.SerializationException:无法将类[B]的值转换为value.serializer中指定的类org.apache.kafka.common.serialization.StringSerializer
原因:java.lang.ClassCastException:[B不能转换为java.lang.String
位于org.apache.kafka.common.serialization.StringSerializer.serialize(StringSerializer.java:28)
位于org.apache.kafka.common.serialization.Serializer.serialize(Serializer.java:62)
位于org.apache.kafka.clients.producer.KafkaProducer.doSend(KafkaProducer.java:894)
位于org.apache.kafka.clients.producer.KafkaProducer.send(KafkaProducer.java:856)
位于org.springframework.kafka.core.DefaultKafkaProducerFactory$CloseSafeProducer.send(DefaultKafkaProducerFactory.java:470)
位于org.springframework.kafka.core.KafkaTemplate.doSend(KafkaTemplate.java:407)
位于org.springframework.kafka.core.KafkaTemplate.send(KafkaTemplate.java:242)
位于org.springframework.integration.kafka.outbound.KafkaProducerMessageHandler.handleRequestMessage(KafkaProducerMessageHandler.java:382)
位于org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:123)
位于org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:176)
位于org.springframework.cloud.stream.binder.AbstractMessageChannelBinder$SendingHandler.handleMessageInternal(AbstractMessageChannelBinder.java:1095)
位于org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:176)
位于org.springframework.integration.dispatcher.AbstractDispatcher.tryoOptimizedDispatch(AbstractDispatcher.java:115)
位于org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:132)
位于org.springframework.integration.dispatcher.UnicastingDispatcher.dispatcher(UnicastingDispatcher.java:105)
位于org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:73)
位于org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:453)
位于org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:401)
在com.ll.kafkaservice.greeting.GreetingsService.sendGreeting上(GreetingsService.java:30)

默认情况下,在com.ll.kafkaservice.greeting.GreetingsController.greetings(GreetingsController.java:29)
上,SCSt框架将有效负载转换为
字节[]
,并使用
ByteArraySerializers

由于已将绑定配置为使用自定义序列化程序,因此必须将
usenativeencode
设置为
true
。请参阅

使用NativeEncode

设置为true时,出站消息由客户端库直接序列化,客户端库必须进行相应配置(例如,设置适当的Kafka生产者值序列化程序)。使用此配置时,出站消息封送不基于绑定的contentType。使用本机编码时,使用者有责任使用适当的解码器(例如,Kafka使用者值反序列化器)反序列化入站消息
kafka:
consumer:
  key.deserializer: org.apache.kafka.common.serialization.StringDeserializer
  value.deserializer: org.apache.kafka.common.serialization.StringDeserializer
  bootstrap.servers: localhost:9092
  group.id: fixed-asset-service
  auto.offset.reset: earliest
producer:
  key.serializer: org.apache.kafka.common.serialization.StringSerializer
  value.serializer: org.apache.kafka.common.serialization.StringSerializer
  bootstrap.servers: localhost:9092
key.serializer = class org.apache.kafka.common.serialization.ByteArraySerializer