# Stream Application DSL

Stream Application DSL 可用于为每个 Spring Cloud Stream applications 定义绑定属性。有关详细信息，请参阅网站的[Stream Application DSL](https://dataflow.spring.io/docs/feature-guides/streams/stream-application-dsl/)部分。

```java
public interface Barista {

    @Input
    SubscribableChannel orders();

    @Output
    MessageChannel hotDrinks();

    @Output
    MessageChannel coldDrinks();
}
```

或者像创建Kafka Streams应用程序时一样，

```java
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`

{% hint style="info" %}
重大更新！SCDF Local，Cloud Foundry 1.7.0到1.7.2和SCDF Kubernetes 1.7.0到1.7.1的版本使用该`comma`字符作为应用程序之间的分隔符。这导致了传统Stream DSL的重大变化。虽然不理想，但改变分隔符特性被认为是对现有用户影响最小的最佳解决方案。
{% endhint %}

在这个流中有四个应用程序。baristaApp有两个输出目的地，hotDrinkDeliveryApp和coldDrinkDeliveryApp。部署此流时，您需要设置绑定属性，以便`baristaApp`将 hotDrink 消息发送到`hotDrinkDeliveryApp`目标，并将 coldDrink 消息发送到`coldDrinkDeliveryApp`目标。例如

```yaml
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  部署单个应用程序。
