From a2495bc9207df8329719ad66e64dafe110146352 Mon Sep 17 00:00:00 2001 From: Oleg Zhurakousky Date: Wed, 3 Nov 2021 16:31:07 +0100 Subject: [PATCH] GH-2243 Document spring.cloud.stream.dynamic-destination-cache-size property Resolves #2243 --- README.adoc | 2 +- docs/src/main/asciidoc/_configprops.adoc | 5 ----- .../src/main/asciidoc/spring-cloud-stream.adoc | 18 ++++++++++++------ 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/README.adoc b/README.adoc index 207dcc47b..1d4453d54 100644 --- a/README.adoc +++ b/README.adoc @@ -193,7 +193,7 @@ compatibility you can still bring `spring-cloud-stream-reactive` from previous v [[spring-cloud-stream-preface-notable-deprecations]] === Notable Deprecations -- Annotation-based programming model. Basically the @EnableBinding, @StreamListener and all related annotations are now deprecated in +- Annotation-based programming model. Basically the @EnableBInding, @StreamListener and all related annotations are now deprecated in favor of the functional programming model. See <> for more details. - _Reactive module_ (`spring-cloud-stream-reactive`) is discontinued and no longer distributed in favor of native support via spring-cloud-function. For backward diff --git a/docs/src/main/asciidoc/_configprops.adoc b/docs/src/main/asciidoc/_configprops.adoc index fe3533b31..45e42323f 100644 --- a/docs/src/main/asciidoc/_configprops.adoc +++ b/docs/src/main/asciidoc/_configprops.adoc @@ -20,11 +20,6 @@ |spring.cloud.stream.metrics.schedule-interval | `60s` | Interval expressed as Duration for scheduling metrics snapshots publishing. Defaults to 60 seconds |spring.cloud.stream.override-cloud-connectors | `false` | This property is only applicable when the cloud profile is active and Spring Cloud Connectors are provided with the application. If the property is false (the default), the binder detects a suitable bound service (for example, a RabbitMQ service bound in Cloud Foundry for the RabbitMQ binder) and uses it for creating connections (usually through Spring Cloud Connectors). When set to true, this property instructs binders to completely ignore the bound services and rely on Spring Boot properties (for example, relying on the spring.rabbitmq.* properties provided in the environment for the RabbitMQ binder). The typical usage of this property is to be nested in a customized environment when connecting to multiple systems. |spring.cloud.stream.pollable-source | `none` | A semi-colon delimited list of binding names of pollable sources. Binding names follow the same naming convention as functions. For example, name '...pollable-source=foobar' will be accessible as 'foobar-iin-0'' binding -|spring.cloud.stream.poller.cron | | Cron expression value for the Cron Trigger. -|spring.cloud.stream.poller.fixed-delay | `1000` | Fixed delay for default poller. -|spring.cloud.stream.poller.initial-delay | `0` | Initial delay for periodic triggers. -|spring.cloud.stream.poller.max-messages-per-poll | `1` | Maximum messages per poll for the default poller. -|spring.cloud.stream.poller.time-unit | | The TimeUnit to apply to delay values. |spring.cloud.stream.sendto.destination | `none` | The name of the header used to determine the name of the output destination |spring.cloud.stream.source | | A colon delimited string representing the names of the sources based on which source bindings will be created. This is primarily to support cases where source binding may be required without providing a corresponding Supplier. (e.g., for cases where the actual source of data is outside of scope of spring-cloud-stream - HTTP -> Stream) diff --git a/docs/src/main/asciidoc/spring-cloud-stream.adoc b/docs/src/main/asciidoc/spring-cloud-stream.adoc index ee6131478..f685d6cf5 100644 --- a/docs/src/main/asciidoc/spring-cloud-stream.adoc +++ b/docs/src/main/asciidoc/spring-cloud-stream.adoc @@ -595,12 +595,14 @@ public class WebSourceApplication { Here we autowire a `StreamBridge` bean which allows us to send data to an output binding effectively bridging non-stream application with spring-cloud-stream. Note that preceding example does not have any -source functions defined (e.g., Supplier bean) leaving the framework with no trigger to create source bindings, which would be typical for cases where -configuration contains function beans. -So to trigger the creation of source binding we use `spring.cloud.stream.source` property where you can declare the name of your sources. +source functions defined (e.g., Supplier bean) leaving the framework with no trigger to create source bindings in advance, which would be typical for cases where configuration contains function beans. And that is fine, since `StreamBridge` will initiate creation of output bindings (as well as +destination auto-provisioning if necessary) for non existing bindings on the first call to its `send(..)` operation caching it for +subsequent reuse (see <> for more details). + +However, if you want to pre-create an output binding at the initialization (startup) time you can benefit from `spring.cloud.stream.source` property where you can declare the name of your sources. The provided name will be used as a trigger to create a source binding. So in the preceding example the name of the output binding will be `toStream-out-0` which is consistent with the binding naming -convention used by functions (see <>). You can use `;` to signify multiple sources +convention used by functions (see <>). You can use `;` to signify multiple sources (multiple output bindings) (e.g., `--spring.cloud.stream.source=foo;bar`) Also, note that `streamBridge.send(..)` method takes an `Object` for data. This means you can send POJO or `Message` to it and it @@ -669,13 +671,17 @@ public class WebSourceApplication { ---- As you can see inside of `delegateToSupplier` method we're using StreamBridge to send data to `myBinidng` binding. And here you're also benefiting from -the dynamic features of StreamBridge where if `myBinidng` doesn't exist it will be created automatically, otherwise existing binding will be used. +the dynamic features of `StreamBridge` where if `myBinidng` doesn't exist it will be created automatically and cached, otherwise existing binding will be used. + +NOTE: Caching dynamic destinations (bindings) could result in memory leaks in the event there are many dynamic destinations. To have some level of control +we provide a self-evicting caching mechanism for output bindings with default cache size of 10. This means that if your dynamic destination size goes above that number, there is a possibility that an existing binding will be evicted and thus would need to be recreated which could cause minor performance degradation. You can increase the cache size via `spring.cloud.stream.dynamic-destination-cache-size` property setting it to the desired value. + ---- curl -H "Content-Type: text/plain" -X POST -d "hello from the other side" http://localhost:8080/ ---- -By showing two example we want to emphasize the approach will work with any type of foreign sources. +By showing two examples we want to emphasize the approach will work with any type of foreign sources. ====== Output Content Type with StreamBridge