### Build and Install Jars to Local Maven Cache Source: https://github.com/spring-projects/spring-integration/blob/main/README.md Build the project and install the generated JAR files into your local Maven repository. ```bash ./gradlew build publishToMavenLocal ``` -------------------------------- ### Create LettuceConnectionFactory in Java Source: https://github.com/spring-projects/spring-integration/blob/main/src/reference/antora/modules/ROOT/pages/redis.adoc Example of instantiating a LettuceConnectionFactory in Java for Redis connection management. ```java LettuceConnectionFactory cf = new LettuceConnectionFactory(); cf.afterPropertiesSet(); ``` -------------------------------- ### Instantiating a Polling Consumer Source: https://github.com/spring-projects/spring-integration/blob/main/src/reference/antora/modules/ROOT/pages/endpoint.adoc This example shows how to create a PollingConsumer by providing a PollableChannel and a MessageHandler. The channel must implement PollableChannel. ```java PollableChannel channel = context.getBean("pollableChannel", PollableChannel.class); PollingConsumer consumer = new PollingConsumer(channel, exampleHandler); ``` -------------------------------- ### Instantiating an Event-Driven Consumer Source: https://github.com/spring-projects/spring-integration/blob/main/src/reference/antora/modules/ROOT/pages/endpoint.adoc This example shows how to create an EventDrivenConsumer by providing a SubscribableChannel and a MessageHandler. ```java SubscribableChannel channel = context.getBean("subscribableChannel", SubscribableChannel.class); EventDrivenConsumer consumer = new EventDrivenConsumer(channel, exampleHandler); ``` -------------------------------- ### gRPC Service Definition Example Source: https://github.com/spring-projects/spring-integration/blob/main/src/reference/antora/modules/ROOT/pages/grpc.adoc An example of a gRPC service definition in Protobuf format, outlining different RPC methods. ```protobuf service TestHelloWorld { // Sends a greeting rpc SayHello(HelloRequest) returns (HelloReply) {} // Sends a greeting and something else rpc StreamSayHello(HelloRequest) returns (stream HelloReply) {} // Sends a greeting to everyone present rpc HelloToEveryOne(stream HelloRequest) returns (HelloReply) {} // Streams requests and replies rpc BidiStreamHello(stream HelloRequest) returns (stream HelloReply) {} } ``` -------------------------------- ### MessagePreparedStatementSetter Example Source: https://github.com/spring-projects/spring-integration/blob/main/src/reference/antora/modules/ROOT/pages/jdbc/outbound-channel-adapter.adoc Example of setting a MessagePreparedStatementSetter for the outbound channel adapter. This allows custom logic for preparing SQL statements based on message content. ```java ps.setBlob(2, inputStream); } catch (Exception e) { throw new MessageHandlingException(m, e); } ps.setClob(3, new StringReader(m.getHeaders().get("description", String.class))); }); return jdbcMessageHandler; } ``` -------------------------------- ### Configure AmqpChannelFactoryBean Source: https://github.com/spring-projects/spring-integration/blob/main/src/reference/antora/modules/ROOT/pages/amqp/channels.adoc Example of configuring an AmqpChannelFactoryBean to create an AMQP channel. ```java AmqpChannelFactoryBean factoryBean = new AmqpChannelFactoryBean(true); factoryBean.setConnectionFactory(connectionFactory); factoryBean.setQueueName("baz"); factoryBean.setPubSub(false); return factoryBean; ``` -------------------------------- ### CompositeDeserializer Example Source: https://github.com/spring-projects/spring-integration/blob/main/src/reference/antora/modules/ROOT/pages/ip/tcp-advanced-techniques.adoc A trivial example demonstrating the use of TcpNetConnectionSupport with a delegating deserializer that 'peeks' at the first byte to determine the appropriate deserializer. ```java public class CompositeDeserializer implements Deserializer { private final ByteArrayStxEtxSerializer stxEtx = new ByteArrayStxEtxSerializer(); private final ByteArrayCrLfSerializer crlf = new ByteArrayCrLfSerializer(); @Override ``` -------------------------------- ### Manual Acknowledgement Example Source: https://github.com/spring-projects/spring-integration/blob/main/src/reference/antora/modules/ROOT/pages/amqp/inbound-ack.adoc Demonstrates how to use manual acknowledgement with AMQP inbound endpoints. This example shows how to acknowledge or negatively acknowledge a message using the provided Channel and deliveryTag headers. ```java @ServiceActivator(inputChannel = "foo", outputChannel = "bar") public Object handle(@Payload String payload, @Header(AmqpHeaders.CHANNEL) Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) Long deliveryTag) throws Exception { // Do some processing if (allOK) { channel.basicAck(deliveryTag, false); // perhaps do some more processing } else { channel.basicNack(deliveryTag, false, true); } return someResultForDownStreamProcessing; } ``` -------------------------------- ### Starting an Integration Flow from an Existing Flow Source: https://github.com/spring-projects/spring-integration/blob/main/src/reference/antora/modules/ROOT/pages/dsl/integration-flows-composition.adoc Use `IntegrationFlow.from(IntegrationFlow)` to start a new flow from the output of a pre-defined `IntegrationFlow` bean. This allows for modular flow design. ```java @Bean IntegrationFlow templateSourceFlow() { return IntegrationFlow.fromSupplier(() -> "test data") .channel("sourceChannel") .get(); } @Bean IntegrationFlow compositionMainFlow(IntegrationFlow templateSourceFlow) { return IntegrationFlow.from(templateSourceFlow) .transform(String::toUpperCase) .channel(c -> c.queue("compositionMainFlowResult")) .get(); ``` -------------------------------- ### Micrometer Custom Metrics Example Source: https://github.com/spring-projects/spring-integration/blob/main/src/reference/antora/modules/ROOT/pages/metrics.adoc This example demonstrates how to customize Micrometer metrics names and tags by providing a subclass of `MicrometerMetricsCaptor`. It is based on the `MicrometerCustomMetricsTests` test case. ```java You can also further customize the meters by overloading the `build()` methods on builder subclasses. ``` -------------------------------- ### Clone Spring Integration Samples Repository Source: https://github.com/spring-projects/spring-integration/blob/main/src/reference/antora/modules/ROOT/pages/samples.adoc Use this command to clone the entire samples repository to your local system. Ensure you have Git installed. ```bash $ git clone https://github.com/spring-projects/spring-integration-samples.git ``` -------------------------------- ### Aggregator Configuration Example Source: https://github.com/spring-projects/spring-integration/blob/main/src/reference/antora/modules/ROOT/pages/aggregator.adoc This snippet shows a comprehensive configuration for an aggregator, including correlation, release strategies, message stores, and timeouts. ```xml ``` -------------------------------- ### Configure a Priority Channel Source: https://github.com/spring-projects/spring-integration/blob/main/src/reference/antora/modules/ROOT/pages/dsl/java-channels.adoc Use `MessageChannels.priority()` to create a `PriorityChannel`. This example shows how to specify a message store and a group for the channel, and add an interceptor. ```java @Bean public PriorityChannelSpec priorityChannel() { return MessageChannels.priority(this.mongoDbChannelMessageStore, "priorityGroup") .interceptor(wireTap()); } ``` -------------------------------- ### STOMP Frame Structure Example Source: https://github.com/spring-projects/spring-integration/blob/main/src/reference/antora/modules/ROOT/pages/stomp.adoc Illustrates the general format of a STOMP frame, including command, headers, and body. ```text .... COMMAND header1:value1 header2:value2 Body^@ .... ``` -------------------------------- ### Order Splitter Example Source: https://github.com/spring-projects/spring-integration/blob/main/src/reference/antora/modules/ROOT/pages/samples.adoc A simple splitter that takes an Order object and returns a list of OrderItem objects. ```java public class OrderSplitter { public List split(Order order) { return order.getItems(); } } ``` -------------------------------- ### Filter with Inline Subflow Source: https://github.com/spring-projects/spring-integration/blob/main/src/reference/antora/modules/ROOT/pages/dsl/java-subflows.adoc Example of a filter component configured with an inline subflow that starts with a channel. The framework implicitly adds a bridge. ```java filter(p -> p instanceof String, e -> e .discardFlow(df -> df .channel(MessageChannels.queue()) ...) ``` -------------------------------- ### Set up Local Development Environment Source: https://github.com/spring-projects/spring-integration/blob/main/CONTRIBUTING.adoc Clone the repository and configure remote origins for local development. Ensure both your fork ('origin') and the main project ('upstream') are set up. ```bash git clone --recursive git@github.com:/spring-integration.git cd spring-integration git remote show git remote add upstream git@github.com:spring-projects/spring-integration.git git remote show git fetch --all git branch -a ``` -------------------------------- ### Custom SftpClient with Request Handler (Java) Source: https://github.com/spring-projects/spring-integration/blob/main/src/reference/antora/modules/ROOT/pages/sftp/session-factory.adoc Example of overriding createSftpChannelSubsystem to add a custom RequestHandler for SFTP subsystem requests and replies, starting from version 6.1.3. ```java @Override protected ChannelSubsystem createSftpChannelSubsystem(ClientSession clientSession) { ChannelSubsystem sftpChannelSubsystem = super.createSftpChannelSubsystem(clientSession); sftpChannelSubsystem.addRequestHandler((channel, request, wantReply, buffer) -> ...); return sftpChannelSubsystem; } ``` -------------------------------- ### Configure SMB Outbound Gateway with Java DSL Source: https://github.com/spring-projects/spring-integration/blob/main/src/reference/antora/modules/ROOT/pages/smb.adoc Demonstrates configuring the SMB outbound gateway using Spring Boot and the Java DSL. This example sets up the gateway for MGET operations with recursive options and file name filtering. ```java @SpringBootApplication public class SmbJavaApplication { public static void main(String[] args) { new SpringApplicationBuilder(SmbJavaApplication.class) .web(false) .run(args); } @Bean public SmbSessionFactory smbSessionFactory() { SmbSessionFactory smbSession = new SmbSessionFactory(); smbSession.setHost("myHost"); smbSession.setPort(445); smbSession.setDomain("myDomain"); smbSession.setUsername("myUser"); smbSession.setPassword("myPassword"); smbSession.setShareAndDir("myShareAndDir"); smbSession.setSmbMinVersion(DialectVersion.SMB210); smbSession.setSmbMaxVersion(DialectVersion.SMB311); return smbSession; } @Bean public SmbOutboundGatewaySpec smbOutboundGateway() { return Smb.outboundGateway(smbSessionFactory(), AbstractRemoteFileOutboundGateway.Command.MGET, "payload") .options(AbstractRemoteFileOutboundGateway.Option.RECURSIVE) .regexFileNameFilter("(subSmbSource|.*.txt)") .localDirectoryExpression("'localDirectory/' + #remoteDirectory") .localFilenameExpression("#remoteFileName.replaceFirst('smbSource', 'localTarget')"); } @Bean public IntegrationFlow smbFlow(AbstractRemoteFileOutboundGateway smbOutboundGateway) { return f -> f .handle(smbOutboundGateway) .channel(c -> c.queue("remoteFileOutputChannel")); } } ``` -------------------------------- ### Build Reference Documentation Source: https://github.com/spring-projects/spring-integration/blob/main/README.md Generate the reference documentation for Spring Integration using Antora. The output will be in the 'build/site' directory. ```bash ./gradlew antora ``` -------------------------------- ### Configure Inbound HTTP Gateway with Java DSL Source: https://github.com/spring-projects/spring-integration/blob/main/src/reference/antora/modules/ROOT/pages/http/java-config.adoc Configure an inbound HTTP gateway using the Spring Integration Java DSL for a more fluent and concise setup. This example defines the gateway, path, HTTP method, and payload type. ```java @Bean public IntegrationFlow inbound() { return IntegrationFlow.from(Http.inboundGateway("/foo") .requestMapping(m -> m.methods(HttpMethod.POST)) .requestPayloadType(String.class)) .channel("httpRequest") .get(); } ``` -------------------------------- ### Build Complete Distribution Source: https://github.com/spring-projects/spring-integration/blob/main/README.md Create a complete distribution package including '-dist', '-docs', and '-schema' zip files. The output will be in 'build/distributions'. ```bash ./gradlew dist ``` -------------------------------- ### Spring Boot Application with Debezium Java DSL Inbound Adapter Source: https://github.com/spring-projects/spring-integration/blob/main/src/reference/antora/modules/ROOT/pages/debezium.adoc An example of a Spring Boot application configuring the Debezium inbound adapter using the Java DSL. This snippet shows the complete setup within a Spring Boot application context. ```java @SpringBootApplication public class DebeziumJavaApplication { public static void main(String[] args) { new SpringApplicationBuilder(DebeziumJavaApplication.class) .web(false) .run(args); } @Bean public IntegrationFlow debeziumInbound( DebeziumEngine.Builder> debeziumEngineBuilder) { return IntegrationFlow .from(Debezium .inboundChannelAdapter(debeziumEngineBuilder) .headerNames("special*") .contentType("application/json") .enableBatch(false)) .handle(m -> System.out.println(new String((byte[]) m.getPayload()))) .get(); } } ``` -------------------------------- ### Transformer Annotation Example Source: https://github.com/spring-projects/spring-integration/blob/main/src/reference/antora/modules/ROOT/pages/configuration/annotations.adoc A basic example of a @Transformer annotation to process messages from an input channel to an output channel. ```java public class AnnotationService { @Transformer(inputChannel = "aPollableChannel", outputChannel = "output") public String handle(String payload) { ... } } ``` -------------------------------- ### Java Configuration for Async AMQP Outbound Gateway Source: https://github.com/spring-projects/spring-integration/blob/main/src/reference/antora/modules/ROOT/pages/amqp/async-outbound-gateway.adoc Configure an asynchronous AMQP outbound gateway using traditional Java configuration. This example shows how to set up the gateway, AsyncRabbitTemplate, and the reply listener container. ```java @Configuration public class AmqpAsyncConfig { @Bean @ServiceActivator(inputChannel = "amqpOutboundChannel") public AsyncAmqpOutboundGateway amqpOutbound(AsyncRabbitTemplate asyncTemplate) { AsyncAmqpOutboundGateway outbound = new AsyncAmqpOutboundGateway(asyncTemplate); outbound.setRoutingKey("foo"); // default exchange - route to queue 'foo' return outbound; } @Bean public AsyncRabbitTemplate asyncTemplate(RabbitTemplate rabbitTemplate, SimpleMessageListenerContainer replyContainer) { return new AsyncRabbitTemplate(rabbitTemplate, replyContainer); } @Bean public SimpleMessageListenerContainer replyContainer() { SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(ccf); container.setQueueNames("asyncRQ1"); return container; } @Bean public MessageChannel amqpOutboundChannel() { return new DirectChannel(); } } ``` -------------------------------- ### MySQL JSON Function Examples Source: https://github.com/spring-projects/spring-integration/blob/main/src/reference/antora/modules/ROOT/pages/jdbc/message-store-json.adoc Examples of using MySQL JSON functions to query messages by payload fields or priority. ```sql -- Find messages by payload field SELECT * FROM JSON_CHANNEL_MESSAGE WHERE JSON_EXTRACT(MESSAGE_CONTENT, '$.payload.orderId') = 'ORDER-12345'; -- Find high-priority messages SELECT * FROM JSON_CHANNEL_MESSAGE WHERE JSON_EXTRACT(MESSAGE_CONTENT, '$.headers.priority[1]') = 'HIGH'; ``` -------------------------------- ### PostgreSQL JSONB Query Examples Source: https://github.com/spring-projects/spring-integration/blob/main/src/reference/antora/modules/ROOT/pages/jdbc/message-store-json.adoc Examples of querying JSONB columns in PostgreSQL to find messages based on payload fields or priority. ```sql -- Find messages by payload field SELECT * FROM JSON_CHANNEL_MESSAGE WHERE MESSAGE_CONTENT @> '{"payload": {"orderId": "ORDER-12345"}}'; -- Find high-priority messages SELECT * FROM JSON_CHANNEL_MESSAGE WHERE MESSAGE_CONTENT -> 'headers' @> '{"priority": ["java.lang.String", "HIGH"]}'; ``` -------------------------------- ### Configure STOMP Adapters with Java Configuration Source: https://github.com/spring-projects/spring-integration/blob/main/src/reference/antora/modules/ROOT/pages/stomp.adoc This example demonstrates a comprehensive Java configuration for STOMP adapters, including the STOMP client, session manager, inbound channel adapter, outbound message handler, and event listener. ```java @Configuration @EnableIntegration public class StompConfiguration { @Bean public ReactorNettyTcpStompClient stompClient() { ReactorNettyTcpStompClient stompClient = new ReactorNettyTcpStompClient("127.0.0.1", 61613); stompClient.setMessageConverter(new PassThruMessageConverter()); ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler(); taskScheduler.afterPropertiesSet(); stompClient.setTaskScheduler(taskScheduler); stompClient.setReceiptTimeLimit(5000); return stompClient; } @Bean public StompSessionManager stompSessionManager() { ReactorNettyTcpStompSessionManager stompSessionManager = new ReactorNettyTcpStompSessionManager(stompClient()); stompSessionManager.setAutoReceipt(true); return stompSessionManager; } @Bean public PollableChannel stompInputChannel() { return new QueueChannel(); } @Bean public StompInboundChannelAdapter stompInboundChannelAdapter() { StompInboundChannelAdapter adapter = new StompInboundChannelAdapter(stompSessionManager(), "/topic/myTopic"); adapter.setOutputChannel(stompInputChannel()); return adapter; } @Bean @ServiceActivator(inputChannel = "stompOutputChannel") public MessageHandler stompMessageHandler() { StompMessageHandler handler = new StompMessageHandler(stompSessionManager()); handler.setDestination("/topic/myTopic"); return handler; } @Bean public PollableChannel stompEvents() { return new QueueChannel(); } @Bean public ApplicationListener stompEventListener() { ApplicationEventListeningMessageProducer producer = new ApplicationEventListeningMessageProducer(); producer.setEventTypes(StompIntegrationEvent.class); producer.setOutputChannel(stompEvents()); return producer; } } ``` -------------------------------- ### Configure Inbound MQTT Adapter with Java Configuration Source: https://github.com/spring-projects/spring-integration/blob/main/src/reference/antora/modules/ROOT/pages/mqtt.adoc Example of setting up an inbound MQTT adapter using Spring's Java configuration. This includes specifying broker details, topics, and message handling. ```java @SpringBootApplication public class MqttJavaApplication { public static void main(String[] args) { new SpringApplicationBuilder(MqttJavaApplication.class) .web(false) .run(args); } @Bean public MessageChannel mqttInputChannel() { return new DirectChannel(); } @Bean public MessageProducer inbound() { MqttPahoMessageDrivenChannelAdapter adapter = new MqttPahoMessageDrivenChannelAdapter("tcp://localhost:1883", "testClient", "topic1", "topic2"); adapter.setCompletionTimeout(5000); adapter.setConverter(new DefaultPahoMessageConverter()); adapter.setQos(1); adapter.setOutputChannel(mqttInputChannel()); return adapter; } @Bean @ServiceActivator(inputChannel = "mqttInputChannel") public MessageHandler handler() { return new MessageHandler() { @Override public void handleMessage(Message message) throws MessagingException { System.out.println(message.getPayload()); } }; } } ``` -------------------------------- ### Release Strategy Expression Example Source: https://github.com/spring-projects/spring-integration/blob/main/src/reference/antora/modules/ROOT/pages/aggregator.adoc Example of a SpEL expression used for a release strategy, checking if a message with payload '5' exists in the group. ```xml release-strategy-expression="!messages.?[payload==5].empty" ``` -------------------------------- ### Gateway Configuration with Method Elements Source: https://github.com/spring-projects/spring-integration/blob/main/src/reference/antora/modules/ROOT/pages/gateway.adoc Configure gateway methods using XML elements. This example shows how to define methods, specify request channels, and set timeouts. ```xml ``` -------------------------------- ### Routing Slip Configuration with Properties Source: https://github.com/spring-projects/spring-integration/blob/main/src/reference/antora/modules/ROOT/pages/router/routing-slip.adoc Configures a routing slip using properties for channel names. This example demonstrates how to use `` to resolve routing slip paths. ```xml channel1 request.headers[myRoutingSlipChannel] ``` -------------------------------- ### JMS Message Selector Example Source: https://github.com/spring-projects/spring-integration/blob/main/src/reference/antora/modules/ROOT/pages/jms.adoc An example of a JMS message selector expression used to filter messages based on a custom JMS header property. ```xml myHeaderProperty = 'something' ``` -------------------------------- ### Implementing IntegrationFlow Directly Source: https://github.com/spring-projects/spring-integration/blob/main/src/reference/antora/modules/ROOT/pages/dsl/java-flow-adapter.adoc Shows how to implement the `IntegrationFlow` interface directly and register it as a component for scanning. ```java @Component public class MyFlow implements IntegrationFlow { @Override public void configure(IntegrationFlowDefinition f) { f.transform(String::toUpperCase); } } ``` -------------------------------- ### Example SOAP Envelope with Headers Source: https://github.com/spring-projects/spring-integration/blob/main/src/reference/antora/modules/ROOT/pages/ws.adoc An example of a SOAP envelope containing custom headers like 'auth', 'cat', 'can', and 'dog'. These headers can be selectively mapped. ```xml user pass CAT CAN DOG ... ``` -------------------------------- ### Configure ZeroMqChannel using Java DSL Source: https://github.com/spring-projects/spring-integration/blob/main/src/reference/antora/modules/ROOT/pages/zeromq.adoc This example demonstrates configuring a ZeroMQ channel using the Java DSL. It specifies the connection URL and a consume delay. ```java .channel(ZeroMq.zeroMqChannel(this.context) .connectUrl("tcp://localhost:6001:6002") .consumeDelay(Duration.ofMillis(100))) } ``` -------------------------------- ### Messaging Gateway Example Source: https://github.com/spring-projects/spring-integration/blob/main/src/reference/antora/modules/ROOT/pages/graph.adoc Defines a messaging gateway with multiple overloaded methods. This example demonstrates how Spring Integration generates graph nodes for each gateway method. ```java @MessagingGateway(defaultRequestChannel = "four") public interface Gate { void foo(String foo); void foo(Integer foo); void bar(String bar); } ``` -------------------------------- ### Configure Inbound MQTT Adapter with Java DSL Source: https://github.com/spring-projects/spring-integration/blob/main/src/reference/antora/modules/ROOT/pages/mqtt.adoc Example of setting up an inbound MQTT adapter using the Spring Integration Java DSL. This provides a fluent API for defining integration flows. ```java @SpringBootApplication public class MqttJavaApplication { public static void main(String[] args) { new SpringApplicationBuilder(MqttJavaApplication.class) .web(false) .run(args); } @Bean public IntegrationFlow mqttInbound() { return IntegrationFlow.from( ``` -------------------------------- ### Configure TCP Connection Factory with Interceptor Chain Source: https://github.com/spring-projects/spring-integration/blob/main/src/reference/antora/modules/ROOT/pages/ip/interceptors.adoc This example shows how to configure a server and a client TCP connection factory with a TcpConnectionInterceptorFactoryChain, including a HelloWorldInterceptorFactory. This is useful for adding custom negotiation or security logic to connections. ```xml ``` -------------------------------- ### XML Aggregator Configuration Example Source: https://github.com/spring-projects/spring-integration/blob/main/src/reference/antora/modules/ROOT/pages/aggregator.adoc Demonstrates a basic XML configuration for an aggregator component, specifying input, output, and discard channels, along with message store and other properties. ```xml auto-startup="true" <2> input-channel="inputChannel" <3> output-channel="outputChannel" <4> discard-channel="throwAwayChannel" <5> message-store="persistentMessageStore" <6> order="1" <7> send-partial-result-on-expiry="false" <8> send-timeout="1000" <9> ``` -------------------------------- ### Define a QueueChannel Bean Source: https://github.com/spring-projects/spring-integration/blob/main/src/reference/antora/modules/ROOT/pages/metrics.adoc Example of defining a QueueChannel bean in Spring configuration. ```java @Bean public QueueChannel noMeters() { return new QueueChannel(10); } ``` -------------------------------- ### Define Queue and Publish-Subscribe Channels Source: https://github.com/spring-projects/spring-integration/blob/main/src/reference/antora/modules/ROOT/pages/dsl/java-channels.adoc Demonstrates the creation of `QueueChannel` and `PublishSubscribeChannel` beans using the `MessageChannels` factory. ```java @Bean public QueueChannelSpec queueChannel() { return MessageChannels.queue(); } @Bean public PublishSubscribeChannelSpec publishSubscribe() { return MessageChannels.publishSubscribe(); } ``` -------------------------------- ### Create a DirectChannel (Java) Source: https://github.com/spring-projects/spring-integration/blob/main/src/reference/antora/modules/ROOT/pages/channel/configuration.adoc Use this to create a default DirectChannel instance in Java configuration. ```java @Bean public MessageChannel exampleChannel() { return new DirectChannel(); } ``` -------------------------------- ### Sample XML Message Source: https://github.com/spring-projects/spring-integration/blob/main/src/reference/antora/modules/ROOT/pages/xml/xpath-transformer.adoc An example of an XML message payload that can be processed by the XPath transformer. ```java Message message = MessageBuilder.withPayload("").build(); ``` -------------------------------- ### Configure Leader Initiator with Java Source: https://github.com/spring-projects/spring-integration/blob/main/src/reference/antora/modules/ROOT/pages/zookeeper.adoc Configures a LeaderInitiatorFactoryBean using Java. Requires a CuratorFramework bean. ```java @Bean public LeaderInitiatorFactoryBean leaderInitiator(CuratorFramework client) { return new LeaderInitiatorFactoryBean() .setClient(client) .setPath("/siTest/") .setRole("cluster"); } ``` -------------------------------- ### Configure MQTT v5 Outbound Flow with Java DSL Source: https://github.com/spring-projects/spring-integration/blob/main/src/reference/antora/modules/ROOT/pages/mqtt.adoc Demonstrates configuring an MQTT v5 outbound channel adapter with custom header mapping, async mode, and event publishing. ```java @Bean public IntegrationFlow mqttOutFlow() { Mqttv5PahoMessageHandler messageHandler = new Mqttv5PahoMessageHandler(MQTT_URL, "mqttv5SIout"); MqttHeaderMapper mqttHeaderMapper = new MqttHeaderMapper(); mqttHeaderMapper.setOutboundHeaderNames("some_user_header", MessageHeaders.CONTENT_TYPE); messageHandler.setHeaderMapper(mqttHeaderMapper); messageHandler.setAsync(true); messageHandler.setAsyncEvents(true); messageHandler.setConverter(mqttStringToBytesConverter()); return f -> f.handle(messageHandler); } ``` -------------------------------- ### Configure SMB Outbound Gateway with Java Configuration Source: https://github.com/spring-projects/spring-integration/blob/main/src/reference/antora/modules/ROOT/pages/smb.adoc Shows how to configure the SMB outbound gateway using Spring Boot and Java configuration. This includes setting up the SmbSessionFactory and the MessageHandler. ```java @SpringBootApplication public class SmbJavaApplication { public static void main(String[] args) { new SpringApplicationBuilder(SmbJavaApplication.class) .web(false) .run(args); } @Bean public SmbSessionFactory smbSessionFactory() { SmbSessionFactory smbSession = new SmbSessionFactory(); smbSession.setHost("myHost"); smbSession.setPort(445); smbSession.setDomain("myDomain"); smbSession.setUsername("myUser"); smbSession.setPassword("myPassword"); smbSession.setShareAndDir("myShareAndDir"); smbSession.setSmbMinVersion(DialectVersion.SMB210); smbSession.setSmbMaxVersion(DialectVersion.SMB311); return smbSession; } @Bean @ServiceActivator(inputChannel = "smbChannel") public MessageHandler handler() { SmbOutboundGateway smbOutboundGateway = new SmbOutboundGateway(smbSessionFactory(), "'my_remote_dir/'"); smbOutboundGateway.setOutputChannelName("replyChannel"); return smbOutboundGateway; } } ``` -------------------------------- ### Fetch All Remotes Source: https://github.com/spring-projects/spring-integration/blob/main/CONTRIBUTING.adoc Sync your local repository with all of your remotes to get the latest branches and commits. ```git git fetch --all ``` -------------------------------- ### Filter Configuration with Annotations Source: https://github.com/spring-projects/spring-integration/blob/main/src/reference/antora/modules/ROOT/pages/filter.adoc Example of configuring a filter using the @Filter annotation in a Java class. ```java public class PetFilter { ... @Filter <1> public boolean dogsOnly(String input) { ``` -------------------------------- ### Using an Asynchronous Gateway with Future Source: https://github.com/spring-projects/spring-integration/blob/main/src/reference/antora/modules/ROOT/pages/gateway.adoc Demonstrates how to call an asynchronous gateway method and retrieve the result from the returned `Future`. ```java MathServiceGateway mathService = ac.getBean("mathService", MathServiceGateway.class); Future result = mathService.multiplyByTwo(number); // do something else here since the reply might take a moment int finalResult = result.get(1000, TimeUnit.SECONDS); ``` -------------------------------- ### PojoCorrelationStrategy Implementation Source: https://github.com/spring-projects/spring-integration/blob/main/src/reference/antora/modules/ROOT/pages/aggregator.adoc An example Java implementation for a correlation strategy. It groups numbers by their last digit. ```java public class PojoCorrelationStrategy { ... public Long groupNumbersByLastDigit(Long number) { return number % 10; } } ``` -------------------------------- ### Inbound Channel Adapter Configuration Source: https://github.com/spring-projects/spring-integration/blob/main/src/reference/antora/modules/ROOT/pages/overview.adoc Example of configuring an inbound channel adapter with an endpoint ID and a poller. ```java @EndpointId("someAdapter") @InboundChannelAdapter(channel = "channel3", poller = @Poller(fixedDelay = "5000")) public MessageSource source() { return () -> { ... }; } ``` -------------------------------- ### Java Configuration for Kafka Outbound Adapter Source: https://github.com/spring-projects/spring-integration/blob/main/src/reference/antora/modules/ROOT/pages/kafka.adoc Configures a Kafka outbound channel adapter using Java. This example shows setting up the KafkaTemplate, ProducerFactory, and the MessageHandler with topic, message key, success, and failure channels. ```java @Bean @ServiceActivator(inputChannel = "toKafka") public MessageHandler handler() throws Exception { KafkaProducerMessageHandler handler = new KafkaProducerMessageHandler<>(kafkaTemplate()); handler.setTopicExpression(new LiteralExpression("someTopic")); handler.setMessageKeyExpression(new LiteralExpression("someKey")); handler.setSuccessChannel(successes()); handler.setFailureChannel(failures()); return handler; } @Bean public KafkaTemplate kafkaTemplate() { return new KafkaTemplate<>(producerFactory()); } @Bean public ProducerFactory producerFactory() { Map props = new HashMap<>(); props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, this.brokerAddress); // set more properties return new DefaultKafkaProducerFactory<>(props); } ``` -------------------------------- ### Service Activator with Input and Output Channels Source: https://github.com/spring-projects/spring-integration/blob/main/src/reference/antora/modules/ROOT/pages/configuration/annotations.adoc Example of a @ServiceActivator annotation supporting inputChannel and outputChannel properties. ```java @Service public class ThingService { ``` -------------------------------- ### Configure ZeroMQ Proxy Bean Source: https://github.com/spring-projects/spring-integration/blob/main/src/reference/antora/modules/ROOT/pages/zeromq.adoc Example of configuring a ZeroMqProxy bean with SUB/PUB type, exposing the capture socket, and setting frontend and backend ports. ```java @Bean ZeroMqProxy zeroMqProxy() { ZeroMqProxy proxy = new ZeroMqProxy(CONTEXT, ZeroMqProxy.Type.SUB_PUB); proxy.setExposeCaptureSocket(true); proxy.setFrontendPort(6001); proxy.setBackendPort(6002); return proxy; } ``` -------------------------------- ### Configure Aggregator with Message Store and Release Strategy Source: https://github.com/spring-projects/spring-integration/blob/main/src/reference/antora/modules/ROOT/pages/aggregator.adoc This example shows how to configure an aggregator with a specific message store and a release strategy. It also demonstrates setting a custom collection type for the message group factory. ```xml ``` -------------------------------- ### Groovy Filter Script Example Source: https://github.com/spring-projects/spring-integration/blob/main/src/reference/antora/modules/ROOT/pages/groovy.adoc A simple Groovy script used for filtering, checking if the 'type' header is 'good'. ```groovy headers.type == 'good' ``` -------------------------------- ### PojoReleaseStrategy Implementation Source: https://github.com/spring-projects/spring-integration/blob/main/src/reference/antora/modules/ROOT/pages/aggregator.adoc An example Java implementation for a release strategy. It determines if a group can be released based on the sum of numbers. ```java public class PojoReleaseStrategy { ... public boolean canRelease(List numbers) { int sum = 0; for (long number: numbers) { sum += number; } return sum >= maxValue; } } ``` -------------------------------- ### Configure Local Interceptor on a Channel Source: https://github.com/spring-projects/spring-integration/blob/main/src/reference/antora/modules/ROOT/pages/channel/configuration.adoc Example of configuring a local wire-tap interceptor on the 'inputChannel'. This interceptor will be applied specifically to this channel. ```xml ``` -------------------------------- ### Configure MQTT v5 Inbound Channel Adapter with Java DSL Source: https://github.com/spring-projects/spring-integration/blob/main/src/reference/antora/modules/ROOT/pages/mqtt.adoc Demonstrates setting up an MQTT v5 inbound channel adapter using Java DSL. Configures payload type, message converter, and manual acknowledgments. ```java @Bean public IntegrationFlow mqttInFlow() { Mqttv5PahoMessageDrivenChannelAdapter messageProducer = new Mqttv5PahoMessageDrivenChannelAdapter(MQTT_URL, "mqttv5SIin", "siTest"); messageProducer.setPayloadType(String.class); messageProducer.setMessageConverter(mqttStringToBytesConverter()); messageProducer.setManualAcks(true); return IntegrationFlow.from(messageProducer) .channel(c -> c.queue("fromMqttChannel")) .get(); } ``` -------------------------------- ### Aggregator Configuration with Annotations Source: https://github.com/spring-projects/spring-integration/blob/main/src/reference/antora/modules/ROOT/pages/aggregator.adoc Demonstrates configuring an aggregator, release strategy, and correlation strategy using annotations in a Java class. ```java public class Waiter { ... @Aggregator <1> public Delivery aggregatingMethod(List items) { ... } @ReleaseStrategy <2> public boolean releaseChecker(List> messages) { ... } @CorrelationStrategy <3> public String correlateBy(OrderItem item) { ... } } ``` -------------------------------- ### Bean Definition with Lazy Qualifier Source: https://github.com/spring-projects/spring-integration/blob/main/src/reference/antora/modules/ROOT/pages/configuration/annotations.adoc Example of defining a bean that depends on an inbound adapter, using @Qualifier and @Lazy annotations. ```java @Bean Thing1 dependsOnSPCA(@Qualifier("someInboundAdapter") @Lazy SourcePollingChannelAdapter someInboundAdapter) { ... } ``` -------------------------------- ### JavaDoc @author Tag Example Source: https://github.com/spring-projects/spring-integration/blob/main/CONTRIBUTING.adoc Use the `@author` tag with your real name when you change any class to ensure proper attribution. ```java /** * ... * * @author First Last */ ``` -------------------------------- ### Gateway Timeout Configuration Example Source: https://github.com/spring-projects/spring-integration/wiki/Spring-Integration-2.1-to-2.2-Migration-Guide Demonstrates how default request/reply timeouts configured in XML for an element previously overrode defaults on an @Gateway method. This behavior has been corrected. ```xml ``` -------------------------------- ### Java DSL Configuration for Async AMQP Outbound Gateway Source: https://github.com/spring-projects/spring-integration/blob/main/src/reference/antora/modules/ROOT/pages/amqp/async-outbound-gateway.adoc Configure an asynchronous AMQP outbound gateway using Java DSL. This example sets up a gateway that sends messages to 'queue1' using a provided AsyncRabbitTemplate. ```java @Configuration public class AmqpAsyncApplication { @Bean public IntegrationFlow asyncAmqpOutbound(AsyncRabbitTemplate asyncRabbitTemplate) { return f -> f .handle(Amqp.asyncOutboundGateway(asyncRabbitTemplate) .routingKey("queue1")); // default exchange - route to queue 'queue1' } @MessagingGateway(defaultRequestChannel = "asyncAmqpOutbound.input") public interface MyGateway { String sendToRabbit(String data); } } ``` -------------------------------- ### Example Linear Commit History Output Source: https://github.com/spring-projects/spring-integration/blob/main/CONTRIBUTING.adoc This output shows a clean, linear commit history, which is preferred for pull requests. ```git * c129a02e6c752b49bacd4a445092a44f66c2a1e9 GH-2721 Increase Timers on JDBC Delayer Tests * 14e556ce23d49229c420632cef608630b1d82e7d GH-2620 Fix Debug Log * 6140aa7b2cfb6ae309c55a157e94b44e5d0bea4f GH-3037 Fix JDBC MS Discard After Completion * 077f2b24ea871a3937c513e08241d1c6cb9c9179 Update Spring Social Twitter to 1.0.5 * 6d4f2b46d859c903881a561c35aa28df68f8faf3 GH-3053 Allow task-executor on * 56f9581b85a8a40bbcf2461ffc0753212669a68d Update Spring Social Twitter version to 1.0.4 ``` -------------------------------- ### Unzip Splitter Flow Configuration (Java DSL) Source: https://github.com/spring-projects/spring-integration/blob/main/src/reference/antora/modules/ROOT/pages/zip.adoc Demonstrates a flow for unzipping and then splitting zip entries using Java DSL. Requires an Executor for the output channel. ```java @Bean public IntegrationFlow unzipSplitFlow(Executor executor) { return IntegrationFlow .from("unzipChannel") .transform(new UnZipTransformer()) .split(new UnZipResultSplitter()) .channel(c -> c.executor("entriesChannel", executor)) .get(); } ``` -------------------------------- ### SmartLifecycleRoleController Status Methods Source: https://github.com/spring-projects/spring-integration/blob/main/src/reference/antora/modules/ROOT/pages/endpoint-roles.adoc Query the status of roles and endpoints managed by the `SmartLifecycleRoleController`. These methods are available starting from version 4.3.8. ```java public Collection getRoles() <1> public boolean allEndpointsRunning(String role) <2> public boolean noEndpointsRunning(String role) <3> public Map getEndpointsRunningStatus(String role) <4> ```