Stream Application DSL
Stream Application DSL 可用于为每个 Spring Cloud Stream applications 定义绑定属性。有关详细信息,请参阅网站的Stream Application DSL部分。
public interface Barista {
@Input
SubscribableChannel orders();
@Output
MessageChannel hotDrinks();
@Output
MessageChannel coldDrinks();
}
或者像创建Kafka Streams应用程序时一样,
interface KStreamKTableBinding {
@Input
KStream<?, ?> inputStream();
@Input
KTable<?, ?> inputTable();
}
在具有多个输入和输出绑定的这些情况下,Data Flow 无法对从一个 application到另一个 application 的数据流进行任何逻辑判断。因此,开发人员需要设置绑定属性来“连接”应用程序。 Stream Application DSL 使用double pipe
,代替pipe symbol
,Data Flow 不应该配置应用程序的绑定属性。将||
视为'并行'的含义,例如:
dataflow:> stream create --definition "orderGeneratorApp || baristaApp || hotDrinkDeliveryApp || coldDrinkDeliveryApp" --name myCafeStream
在这个流中有四个应用程序。baristaApp有两个输出目的地,hotDrinkDeliveryApp和coldDrinkDeliveryApp。部署此流时,您需要设置绑定属性,以便baristaApp
将 hotDrink 消息发送到hotDrinkDeliveryApp
目标,并将 coldDrink 消息发送到coldDrinkDeliveryApp
目标。例如
app.baristaApp.spring.cloud.stream.bindings.hotDrinks.destination=hotDrinksDest
app.baristaApp.spring.cloud.stream.bindings.coldDrinks.destination=coldDrinksDest
app.hotDrinkDeliveryApp.spring.cloud.stream.bindings.input.destination=hotDrinksDest
app.coldDrinkDeliveryApp.spring.cloud.stream.bindings.input.destination=coldDrinksDest
如果要使用用户组,则需要分别设置Spring Cloud Stream应用程序属性spring.cloud.stream.bindings.<channelName>.producer.requiredGroups
以及spring.cloud.stream.bindings.<channelName>.group
分别对生产者和消费者应用程序进行分组。
Stream Application DSL 的另一个常见用例是部署http网关application,该application 向 Kafka 或 RabbitMQ application 发送同步请求/回复消息。在这种情况下,http网关和Kafka或RabbitMQ 的 application 都可以是不使用Spring Cloud Stream 框架。
还可以使用 Stream application DSL 部署单个应用程序。
Last updated
Was this helpful?