INT-2214, INT-343, INT-2250 MessageHandler Advice

Add general capability to advise just the handleRequestMessage
part of an AbstractReplyProducingMessageHandler.

This is to advise just the immediate operation, and not the
entire downstream flow.

Uses include:

* outbound gateway post processing
* adding retry behavior using spring-retry
* adding circuit breaker functionality

Initial commit for review.

Also need to advise simple message handlers (such as file
etc) to allow them to post-process file operations
with payload.delete(), payload.renameTo(...) etc.

INT-2250 Add Circuit Breaker Advice

INT-343 Add Retry Advice

Stateless and Stateful retry using spring-retry. Stateless
means the RetryTemplate performs the retries internally.
Stateful means the exception is thrown (e.g. to JMS container)
and the retry state is maintained by spring-retry.

INT-2215, INT-343, INT-2250 Refactoring

Factor out common abstract Advice class.

INT-2214 Catch Evaluation Expression Exceptions

If an onSuccess expression evaluation fails, add an
option so the user can decide whether such an exception is
caught, or propagated to the caller.

INT-2214 etc PR Review Polishing

INT-2214 etc Namespace Core, File, FTP

Add <request-handler-advice-chain/> to outbound endpoints.

INT-2214 etc. More Namespace Support

amqp, event, gemfire, groovy, http, ip, jdbc, jms, jmx, jpa, mail, rmi, sftp, twitter, ws, xmpp

INT-2214 etc Polishing

PR Review

INT-2214 etc Polishing

Don't catch Throwable.

Move Advice classes to handler.advice package.
This commit is contained in:
Gary Russell
2012-07-14 13:00:38 -04:00
committed by Oleg Zhurakousky
parent 56e3c22970
commit 08cbab08c2
114 changed files with 2661 additions and 296 deletions

View File

@@ -132,7 +132,7 @@
writes Message to a Gemfire cache
</xsd:documentation>
</xsd:annotation>
<xsd:sequence>
<xsd:choice minOccurs="0" maxOccurs="2">
<xsd:element name="cache-entries" type="beans:mapType"
minOccurs="0" maxOccurs="1">
<xsd:annotation>
@@ -142,7 +142,8 @@
</xsd:documentation>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
<xsd:element name="request-handler-advice-chain" type="integration:adviceChainType" minOccurs="0" maxOccurs="1" />
</xsd:choice>
<xsd:attribute name="id" type="xsd:string" use="optional" />

View File

@@ -0,0 +1,21 @@
<?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-gfe="http://www.springframework.org/schema/integration/gemfire"
xmlns:int="http://www.springframework.org/schema/integration"
xsi:schemaLocation="http://www.springframework.org/schema/integration/gemfire http://www.springframework.org/schema/integration/gemfire/spring-integration-gemfire-2.2.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">
<int:channel id="input" />
<int-gfe:outbound-channel-adapter region="region" channel="input">
<int-gfe:request-handler-advice-chain>
<bean class="org.springframework.integration.gemfire.config.xml.GemfireOutboundChannelAdapterParserTests$FooAdvice" />
</int-gfe:request-handler-advice-chain>
</int-gfe:outbound-channel-adapter>
<bean id="region" class="org.mockito.Mockito" factory-method="mock">
<constructor-arg value="com.gemstone.gemfire.cache.Region" />
</bean>
</beans>

View File

@@ -13,24 +13,51 @@
package org.springframework.integration.gemfire.config.xml;
import org.junit.Test;
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException;
import org.w3c.dom.Element;
import static org.junit.Assert.assertEquals;
import static org.springframework.integration.gemfire.config.xml.ParserTestUtil.createFakeParserContext;
import static org.springframework.integration.gemfire.config.xml.ParserTestUtil.loadXMLFrom;
import org.junit.Test;
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.Message;
import org.springframework.integration.MessageChannel;
import org.springframework.integration.handler.advice.AbstractRequestHandlerAdvice;
import org.springframework.integration.message.GenericMessage;
import org.w3c.dom.Element;
/**
* @author Dan Oxlade
*/
public class GemfireOutboundChannelAdapterParserTests {
private GemfireOutboundChannelAdapterParser underTest = new GemfireOutboundChannelAdapterParser();
private GemfireOutboundChannelAdapterParser underTest = new GemfireOutboundChannelAdapterParser();
@Test(expected = BeanDefinitionParsingException.class)
public void regionIsARequiredAttribute() throws Exception {
String xml = "<outbound-channel-adapter />";
Element element = loadXMLFrom(xml).getDocumentElement();
underTest.parseConsumer(element, createFakeParserContext());
}
private volatile static int adviceCalled;
@Test(expected = BeanDefinitionParsingException.class)
public void regionIsARequiredAttribute() throws Exception {
String xml = "<outbound-channel-adapter />";
Element element = loadXMLFrom(xml).getDocumentElement();
underTest.parseConsumer(element, createFakeParserContext());
}
@Test
public void withAdvice() {
ApplicationContext ctx = new ClassPathXmlApplicationContext(this.getClass().getSimpleName() + "-context.xml", this.getClass());
MessageChannel channel = ctx.getBean("input", MessageChannel.class);
channel.send(new GenericMessage<String>("foo"));
assertEquals(1, adviceCalled);
}
public static class FooAdvice extends AbstractRequestHandlerAdvice {
@Override
protected Object doInvoke(ExecutionCallback callback, Object target, Message<?> message) throws Exception {
adviceCalled++;
return null;
}
}
}