Spring Integration Documentation

repository·main·Indexed 23 days ago

https://github.com/spring-projects/spring-integration

Spring Integration extends the Spring programming model to support Enterprise Integration Patterns (EIP), enabling lightweight messaging and declarative adapters for integrating with external systems via messaging, remoting, and scheduling. It provides key abstractions such as Channel Adapters, Gateways, and support for protocols including Apache Kafka, R2DBC, Redis Streams, ZeroMQ, AMQP, and TCP/UDP.

Tokens
251.5K
Snippets
535
Records
1K
Agent score
82%

What's inside Spring Integration

  1. Overview of Spring Integration testing modules

    main

    Spring Integration testing support is divided into two primary modules:

    • spring-integration-test-support: Contains core items, shared utilities, rules, and matchers for standalone unit testing. It has no dependencies on Spring Integration itself.
    • spring-integration-test: Provides high-level APIs for integration testing, including mocking components and configuring application contexts to verify whole flows or individual parts.

    The framework is built upon JUnit, Hamcrest, and Mockito, and integrates with the Spring Test Framework.

  2. Use the Java DSL for TCP Components

    main

    The TCP DSL provides specialized support for building integration flows involving TCP connections. Key components include:

    • Adapters and Gateways: Specs for both inbound and outbound communication.
    • Tcp class: Provides factory methods to create connection factory beans (e.g., Tcp.netServer, Tcp.nioClient, Tcp.inboundAdapter, Tcp.outboundGateway).
    • TcpCodecs class: Provides factory methods to create serializers and deserializers (e.g., TcpCodecs.lengthHeader1()).
  3. FTP Outbound Gateway Overview

    main

    The FTP outbound gateway allows interaction with remote FTP or FTPS servers using a specific set of commands. It acts as a gateway to perform file operations such as listing, retrieving, sending, moving, or removing files.

    Supported Commands:

    • ls (list files)
    • nlst (list file names)
    • get (retrieve file)
    • mget (retrieve file(s))
    • rm (remove file(s))
    • mv (move/rename file)
    • put (send file)
    • mput (send multiple files)
  4. Explore Spring Integration Integration Endpoints

    main

    Spring Integration provides a wide array of protocol-specific channel adapters and gateways to connect your application to external systems. Supported integration endpoints include:

    • Messaging Protocols: AMQP, MQTT, RSocket, STOMP, WebSockets, XMPP, ZeroMQ, and Syslog.
    • Databases & Persistence: JDBC, JPA, Cassandra, MongoDB, Redis, and R2DBC.
    • File & Network Systems: File, FTP/FTPS, SFTP, SMB, TCP/UDP, and Spring Resources.
    • Web & APIs: HTTP, WebFlux, GraphQL, Web Services (SOAP), and XML (XPath).
    • Messaging & Streaming: Apache Kafka, JMS, Apache Camel, and Debezium CDC.
    • Other Integrations: Spring ApplicationEvent, JMX, Mail, Hazelcast, and Zookeeper.
  5. New Components in Spring Integration 6.0

    main

    Spring Integration 6.0 introduced several new components and modules:

    • Groovy DSL: A new implementation for defining integration flows using Groovy.
    • MQTT ClientManager: Supports reusable MQTT connections across different channel adapters.
    • GraphQL Support: New support for GraphQL.
    • Apache Camel Support: Ability to integrate Apache Camel routes.
    • Hazelcast Support: Migrated to the spring-integration-hazelcast module.
    • SMB Support: Added via the spring-integration-smb module, including a Java DSL factory (org.springframework.integration.smb.dsl.Smb), SmbStreamingMessageSource, and SmbOutboundGateway.
    • PostgreSQL Push Notifications: PostgresSubscribableChannel allows receiving push notifications via PostgresChannelMessageTableSubscriber when new messages are added to a JdbcChannelMessageStore.
    • RabbitMQ Stream Queue Support: Enhanced AMQP module for inbound and outbound channel adapters using RabbitMQ Stream Queues.
    • Apache MINA SFTP: SFTP modules reworked to use org.apache.sshd:sshd-sftp instead of JCraft JSch.
    • Micrometer Observation: Support for enabling observation for timers and tracing using Micrometer.
    • GraalVM Polyglot Support: PolyglotScriptExecutor implementation for scripting, providing modern JavaScript support.
    • Apache Cassandra Support: Migrated to the spring-integration-cassandra module.
    • Kotlin Coroutines: Native support for Kotlin Coroutines introduced.
    • Native Images: Support for creating GraalVM native images.
  6. Understand the Spring Integration Samples structure

    main

    Samples are organized into four categories based on the developer's expertise and the sample's goal:

    • Basic (samples/basic): Best for getting started. Focuses on technical use cases, bare minimum configuration, and core concepts like Service Activators, Messaging Gateways, and Enterprise Integration Patterns (EIP).
    • Intermediate (samples/intermediate): For developers familiar with the framework who need guidance on advanced technical problems, such as error handling or complex aggregator configurations.
    • Advanced (samples/advanced): For experts looking to extend the framework using the public API, such as implementing custom channels, consumers, or adapters.
    • Applications (samples/applications): Focuses on business use cases (e.g., loan brokers, travel agents) to demonstrate how to solve real-world problems using message-driven architecture.
  7. SFTP Outbound Gateway Overview

    main

    The SFTP outbound gateway allows you to interact with a remote SFTP server using a specific set of commands. It acts as a gateway to perform file operations such as listing, retrieving, removing, moving, and sending files.

    Supported commands include:

    • ls (list files)
    • nlst (list file names)
    • get (retrieve a file)
    • mget (retrieve multiple files)
    • rm (remove file(s))
    • mv (move and rename file)
    • put (send a file)
    • mput (send multiple files)
  8. What is a Service Activator

    main

    A Service Activator is an endpoint type used to connect any Spring-managed object to an input channel, allowing that object to act as a service. It is a generic endpoint that invokes a method on a target object using an input message (payload and headers).

    Key characteristics:

    • Input/Output: It consumes messages from an input channel. If the service produces output, it can be connected to an output-channel. If no output channel is defined, it uses the replyChannel header from the inbound message.
    • Versatility: It serves as the foundation for many specialized components like outbound gateways and outbound channel adapters.
    • Return Behavior: If the method returns a non-null value, the framework attempts to send a reply. If the method returns void or null, the service activator exits without sending a signal.
  9. What is the Claim Check pattern

    main
    The Claim Check (or Store-in-a-Library) pattern is used to handle large message payloads in distributed systems. Instead of passing a large payload through every processing step—which can cause performance degradation, security risks, or debugging difficulties—the payload is stored in a central MessageStore. A 'claim check' (a unique pointer, implemented as a UUID) is then passed as the message payload. Components only retrieve the actual data from the store when they specifically need it.
  10. What is a Channel Adapter

    main

    A channel adapter is a message endpoint that connects a single sender or receiver to a message channel. Spring Integration provides various adapters for different transports (JMS, file, HTTP, etc.), but the core concept includes method-invoking adapters that allow you to use any Spring-managed object as a source or destination for messages.

    • Inbound Channel Adapter: Invokes a method on a source object and sends the non-null return value to a MessageChannel as a Message.
    • Outbound Channel Adapter: Connects a MessageChannel to a POJO consumer method, invoking it with the message payload.
  11. What is the Scatter-Gather pattern

    main

    The Scatter-Gather pattern is a compound endpoint used to send a single message to multiple recipients (the 'scatter' phase) and then aggregate their individual replies into a single result (the 'gather' phase). It is ideal for scenarios like a "best quote" request, where you query multiple suppliers and decide on the best option based on the combined results.

    In Spring Integration, the ScatterGatherHandler implements this pattern by combining a scatterer (either a PublishSubscribeChannel or a RecipientListRouter) with an aggregator (AggregatingMessageHandler).

  12. Overview of Spring Integration Core Concepts

    main

    Spring Integration implements Enterprise Integration Patterns (EIP) to facilitate messaging-based communication between different systems. The core architecture is built around several key abstractions:

    • Core Messaging: The fundamental building blocks including Messages, Message Channels, and Messaging Endpoints.
    • Message Routing: Components that direct messages to specific channels, such as Routers, Splitters, Aggregators, and Filters.
    • Message Transformation: Components that modify message content or structure, including Transformers, Content Enrichers, Claim Checks, and Codecs.
    • Messaging Endpoints: The points where messages enter or leave the integration flow, such as Service Activators, Gateways, and Adapters.

    You can define these integration flows using several Domain Specific Languages (DSLs):

    • Java DSL
    • Groovy DSL
    • Kotlin DSL