这是该question的续集。我可以将“普通” Apache Kafka Binder与功能模型一起使用吗?到目前为止,我已经使用基于注释的配置将public class DeviceAccess
{
private Container _container;
public DeviceAccess() {}
public async ValueTask OpenAsync(Database database) {
if (_container == null)
_container = await GetContainerAsync(database);
}
public async Task<Device> GetDeviceAsync(string deviceId)
{
var container = _container ?? throw new InvalidOperationException("not open");
return await doSomething(container); // might be able to inline the "await" here
}
}
和spring-cloud-stream-binder-kafka
混合在一起,以便于在一个应用程序中进行简单的消费/制作。
spring-cloud-stream-binder-kafka-streams
活页夹似乎仅支持功能模型,并且如果我尝试混合使用这两种方法-基于注释的简单用法和流功能,则不会注册流绑定。
streams
spring.cloud:
stream:
function:
definition: processStream
bindings:
processStream-in-0:
destination: my-topic
simple-binding-in:
destination: another-topic
public interface SimpleBinding {
String INPUT = "simple-binding-in";
@Input(INPUT)
SubscribableChannel simpleIn();
}
@Component
public class SimpleListener {
@StreamListener(SimpleBinding.INPUT)
public void listen(@Payload SomeDto payload) {
}
}
@Configuration
public class FunctionalStream {
@Bean
public Consumer<KStream<String>> processStream() {
return eventStream -> eventStream.map()
}
}
存在于配置类中。是否像上述描述那样将两者混合使用还是首选还是受支持?即使是为了简单地使用消息,我也应该使用@EnableBinding(SimpleBinding.class)
吗?
答案 0 :(得分:0)
对于Kafka Binder,您可以而且绝对应该使用功能模型,而完全不必考虑StreamListener。这样,它将与您的KStream功能模型保持一致。
spring.cloud:
stream:
function:
definition: processStream
bindings:
processStream-in-0:
destination: my-topic
listen-in-0:
destination: another-topic
@Component
public class SimpleListener {
@Bean
public Consumer<SomeDto> listen() {
return payload -> ...
}
}
@Configuration
public class FunctionalStream {
@Bean
public Consumer<KStream<String>> processStream() {
return eventStream -> eventStream.map()
}
}