Skip to content

Instantly share code, notes, and snippets.

@milovtim
Created November 29, 2017 10:55
Show Gist options
  • Save milovtim/e2b98d2dc71f761f74b3a247cd77a3b3 to your computer and use it in GitHub Desktop.
Save milovtim/e2b98d2dc71f761f74b3a247cd77a3b3 to your computer and use it in GitHub Desktop.
Simple context to check spring-integration components
import org.springframework.context.support.GenericXmlApplicationContext
import org.springframework.core.io.ByteArrayResource
import org.springframework.integration.support.MessageBuilder
import org.springframework.messaging.MessageChannel
def xml = '''<?xml version="1.0" encoding="UTF-8"?>
<bean:beans xmlns="http://www.springframework.org/schema/integration"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:bean="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd">
<channel id="inCh" />
<splitter input-channel="inCh" output-channel="outCh" expression="payload.?[#this % 2 == 0]"/>
<channel id="outCh" />
<outbound-channel-adapter id="printer" channel="outCh" expression="T(java.lang.System).out.println(payload + ': ' + headers['id'])"/>
</bean:beans>
'''
def context = new GenericXmlApplicationContext(new ByteArrayResource(xml.bytes))
def inChannel = context.getBean('inCh', MessageChannel)
def outChannel = context.getBean('outCh', MessageChannel)
inChannel.send(MessageBuilder.withPayload((1..10) as List).build())
//outChannel.send(MessageBuilder.withPayload((1..10) as List).build())
Thread.sleep(3000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment