我正在与一个应用程序一起工作,在该应用程序中,处理器应该处理多个域模型对象;例如,用户和角色
在我的处理器中,因此我试图处理多个主题;
SharedChrome
}
,流配置为;
@StreamListener(target = "uinput", copyHeaders = "true")
@SendTo(value = { "uoutput" })
public KStream<UUID, Event> processu(KStream<UUID, Event> ustream) {...}
@StreamListener(target = "rinput", copyHeaders = "true")
@SendTo(value = { "routput" })
public KStream<UUID, Event> processu(KStream<UUID, Event> ustream) {...}
public class TestRepositoryResponseListener {
@StreamListener(target = "uminput", copyHeaders = "true")
public void process(@Payload Event event) {
log.debug("Processing User {}", event);
// log.debug("Processing2 {}",eventSaved);
}
=测试流
spring.kafka.consumer.key-deserializer=org.springframework.kafka.support.serializer.JsonDeserializer
spring.kafka.consumer.value-deserializer=org.springframework.kafka.support.serializer.JsonDeserializer
spring.kafka.consumer.group-id=user-repository-client-group
spring.kafka.consumer.client-id=user-repository-client
spring.kafka.consumer.auto-offset-reset=earliest
spring.kafka.consumer.properties.spring.json.trusted.packages=com.xx.yy
spring.kafka.producer.key-serializer=org.springframework.kafka.support.serializer.JsonSerializer
spring.kafka.producer.value-serializer=org.springframework.kafka.support.serializer.JsonSerializer
spring.kafka.producer.client-id=user-repository-producer
spring.cloud.stream.kafka.streams.binder.application-id=user-repository
spring.cloud.stream.kafka.streams.binder.configuration.default.key.serde=org.springframework.kafka.support.serializer.JsonSerde
spring.cloud.stream.kafka.streams.binder.configuration.default.value.serde=org.springframework.kafka.support.serializer.JsonSerde
spring.cloud.stream.kafka.streams.binder.configuration.spring.json.trusted.packages=com.xx.yy
spring.cloud.stream.bindings.uinput.destination=uinput
spring.cloud.stream.bindings.uinput.group=user-processor
spring.cloud.stream.bindings.uinput.contentType=application/java-serialized-object
spring.cloud.stream.bindings.uinput.consumer.header-mode=raw
spring.cloud.stream.bindings.uinput.consumer.use-native-decoding=true
spring.cloud.stream.bindings.uoutput.destination=uoutput
spring.cloud.stream.bindings.uoutput.contentType=application/java-serialized-object
spring.cloud.stream.bindings.uoutput.producer.header-mode=raw
spring.cloud.stream.bindings.uoutput.producer.use-native-encoding=true
====启用此选项会导致错误
spring.cloud.stream.bindings.umoutput.destination=uinput
spring.cloud.stream.bindings.umoutput.contentType=application/java-serialized-object
spring.cloud.stream.bindings.umoutput.producer.header-mode=raw
spring.cloud.stream.bindings.umoutput.producer.use-native-encoding=true
我希望为每个“处理器”和“响应侦听器”设置多个Stream侦听器,这似乎比我的预期更具挑战性。请帮忙提出一个有关kstreams和可测试的usign junit 5的示例,该示例正在使用以下代码;
spring.cloud.stream.bindings.uminput.destination=uoutput
spring.cloud.stream.bindings.uminput.contentType=application/java-serialized-object
spring.cloud.stream.bindings.uminput.group=user-processor-test-listener
spring.cloud.stream.bindings.uminput.consumer.header-mode=raw
spring.cloud.stream.bindings.uminput.consumer.use-native-decoding=true
[ERROR] 2019-01-31 08:26:51,967 org.springframework.kafka.listener.LoggingErrorHandler.handle(LoggingErrorHandler.java:37) - Error while processing: null
.
另外,如果有人使用Kstream与@StreamListener(... condition =“ payload.x.x”)配合使用,我也需要ur inout
我已经解决了这里建议的问题;
Multiple StreamListeners with Spring Cloud Stream connected to Kafka
现在可能要克服的最后一个问题是RuntimeError处理,正如我粘贴的代码中显而易见的那样,这是一个Spring Repo,它可以引发各种org.springframework.dao.DataAccessException,需要将其传播回给调用方,在这种情况下,Web公开了服务层。请帮助