Skip to content

Batch Message Splitting in Spring Cloud Function #1242

Open
@2tsumo-hitori

Description

@2tsumo-hitori

Is your feature request related to a problem? Please describe.

  • I am using Spring Cloud Stream with spring.cloud.function.definition, where my function returns a Collection type.
  • Currently, when batch mode is enabled, all consumed messages are aggregated into a single List inside a single message.

This causes potential issues:

  • Increased memory usage and processing overhead for subscribers when messages are large.
  • No built-in way to split the messages within the function unless reactive programming is used.

Describe the solution you'd like

The goal is to introduce an option that allows batch messages to be split into individual messages.

  • Add a boolean field (enableSplitting) to the FunctionInvocationWrapper class.
    • When set to true, the function will process each message individually instead of aggregating them into a single message.
    • When set to false (default), the current behavior remains unchanged.
  • Additionally, I plan to create a related issue in Spring Cloud Stream to introduce a new splitMode option in ProducerProperties.
    • When enabled (true), List type messages will be published as individual messages.

Describe alternatives you've considered

  1. Using Reactive Programming

    • Requires changes to function signatures and dependencies, making it difficult to apply universally.
  2. Manually publishing individual messages using StreamBridge

    • Developers would need to manually iterate over List<Message<Object>> and publish each message separately.
    • This approach prevents the use of the functional interface (Function<T, R>), reducing code simplicity.

Additional context

  • I also plan to open an issue in the Spring Cloud Stream repository, as it calls SimpleFunctionRegistry internally.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions