我想使用Spring Cloud Stream框架创建一个kafka端点,它将有一个http post api来/{topic_name}
。如何动态更改spring.cloud.stream.bindings.<channelName>.destination={topic_name}
属性
我可以使用confluent Kafka REST Proxy
实现来实现上述功能,但想知道是否有可能在春季开发它。
以下示例演示了这些类型的用例,其中它使用基于 http 触发器的动态目标。 查看代码和自述文件。
https://github.com/spring-cloud/spring-cloud-stream-samples/tree/master/source-samples/dynamic-destination-source-kafka
您可以将 StreamBridge 与 kafka-topicname 一起使用,spring-cloud 会在运行时自动绑定它。该方法还可以自动创建主题(如果不存在(,您可以将其关闭。
@Autowired
private final StreamBridge streamBridge;
public void sendDynamically(Message message, String topicName) {
streamBridge.send(route, topicName);
}
它只需要:spring.cloud.stream.kafka.binder.brokers: ${KAFKA_HOST}:${KAFKA_PORT}
https://docs.spring.io/spring-cloud-stream/docs/current/reference/html/spring-cloud-stream.html#_streambridge_and_dynamic_destinations