Skip to content

Instantly share code, notes, and snippets.

View garyrussell's full-sized avatar

Gary Russell garyrussell

View GitHub Profile
@garyrussell
garyrussell / AdvisePolledFlow-context.xml
Last active December 16, 2015 03:59
BeanPostProcessor To Apply a Handler Advice
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
@garyrussell
garyrussell / HeaderExpectationsTests-context.xml
Last active December 16, 2015 04:09
Intercepting Channels in Tests
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int="http://www.springframework.org/schema/integration"
xsi:schemaLocation="http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<int:channel id="input" />
<int:header-enricher input-channel="input" output-channel="next">
/*
* Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@garyrussell
garyrussell / AddCompletionAdvice.java
Last active December 16, 2015 18:59
How to add a completion advice for testing flows that contain an async handoff and the final element produces no reply http://stackoverflow.com/questions/16277487/spring-integration-unit-test-outbound-channel-adapter
/*
* Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@garyrussell
garyrussell / GatewayMultiThreadedAggregationWithErrorHandling.md
Last active December 16, 2015 22:59
MultiThreaded Aggregation With ErrorHandler Per Thread

This example shows how to insert intermediate gateways into a flow, in order to provide a "try/catch"-like block around parts of the flow.

This is necessary when using multi-threaded aggregation with a gateway, so the result (including errors) is returned properly to the original inbound gateway.

It is important to understand that the actual services (and the error transformer) do not send their output to the aggregator directly; by omitting the output-channel, the result (or error) is returned to the intermediate gateway and thence to the aggregator.

EDIT: Added specific tests for one or both messages failing; added a resequencer so the tests are deteministic.

@garyrussell
garyrussell / Foo-context.xml
Created May 23, 2013 21:42
Test Outbound RMI Error Handling
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int-rmi="http://www.springframework.org/schema/integration/rmi"
xmlns:int="http://www.springframework.org/schema/integration"
xsi:schemaLocation="http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/rmi http://www.springframework.org/schema/integration/rmi/spring-integration-rmi.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<int:gateway id="noErrorChannel"
@garyrussell
garyrussell / AsymmetricMessageConverter.java
Last active December 18, 2015 11:09
Asymmetric Spring-AMQP MessageConverter
/*
* Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
/*
* Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@garyrussell
garyrussell / context.xml
Last active December 22, 2015 00:59
Poor Man's Retry (with SI >= 2.2 use a RequestHandlerRetryAdvice)
<int:channel id="requestChannel">
<int:dispatcher load-balancer="none"/> <!-- always first subscriber first -->
</int:channel>
<int:bridge order="1" input-channel="requestChannel" output-channel="toHttp" />
<int-http:outbound-gateway request-channel="toHttp"
url="http://localhost:18080/http/receiveGateway"
http-method="POST"
expected-response-type="java.lang.String"/>
@garyrussell
garyrussell / Main.java
Last active June 25, 2018 06:00
Quick Start
public class Main {
public static void main(String... args) throws Exception {
ApplicationContext ctx = new ClassPathXmlApplicationContext("context.xml");
// simple service
TempConverter converter = ctx.getBean("gw1", TempConverter.class);
System.out.println(converter.fahrenheitToCelcius(68.0f));
// web service
converter = ctx.getBean("gw2", TempConverter.class);
System.out.println(converter.fahrenheitToCelcius(68.0f));