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:
committed by
Oleg Zhurakousky
parent
56e3c22970
commit
08cbab08c2
@@ -29,6 +29,20 @@
|
||||
|
||||
<twitter:outbound-channel-adapter twitter-template="twitter" channel="inputChannel" />
|
||||
|
||||
<twitter:dm-outbound-channel-adapter id="dmAdvised" order="23"
|
||||
twitter-template="twitter"
|
||||
channel="inputChannel">
|
||||
<twitter:request-handler-advice-chain>
|
||||
<beans:bean class="org.springframework.integration.twitter.config.TestSendingMessageHandlerParserTests$FooAdvice" />
|
||||
</twitter:request-handler-advice-chain>
|
||||
</twitter:dm-outbound-channel-adapter>
|
||||
|
||||
<twitter:outbound-channel-adapter id="advised" twitter-template="twitter" channel="inputChannel">
|
||||
<twitter:request-handler-advice-chain>
|
||||
<beans:bean class="org.springframework.integration.twitter.config.TestSendingMessageHandlerParserTests$FooAdvice" />
|
||||
</twitter:request-handler-advice-chain>
|
||||
</twitter:outbound-channel-adapter>
|
||||
|
||||
</beans:beans>
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2012 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.
|
||||
@@ -17,12 +17,16 @@
|
||||
package org.springframework.integration.twitter.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.core.MessageHandler;
|
||||
import org.springframework.integration.endpoint.EventDrivenConsumer;
|
||||
import org.springframework.integration.handler.advice.AbstractRequestHandlerAdvice;
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
import org.springframework.integration.test.util.TestUtils;
|
||||
import org.springframework.integration.twitter.outbound.DirectMessageSendingMessageHandler;
|
||||
|
||||
@@ -33,13 +37,32 @@ import org.springframework.integration.twitter.outbound.DirectMessageSendingMess
|
||||
*/
|
||||
public class TestSendingMessageHandlerParserTests {
|
||||
|
||||
private static volatile int adviceCalled;
|
||||
|
||||
@Test
|
||||
public void testSendingMessageHandlerSuccessfulBootstrap(){
|
||||
ApplicationContext ac = new ClassPathXmlApplicationContext("TestSendingMessageHandlerParser-context.xml", this.getClass());
|
||||
EventDrivenConsumer dmAdapter = ac.getBean("dmAdapter", EventDrivenConsumer.class);
|
||||
Object handler = TestUtils.getPropertyValue(dmAdapter, "handler");
|
||||
MessageHandler handler = TestUtils.getPropertyValue(dmAdapter, "handler", MessageHandler.class);
|
||||
assertEquals(DirectMessageSendingMessageHandler.class, handler.getClass());
|
||||
assertEquals(23, TestUtils.getPropertyValue(handler, "order"));
|
||||
dmAdapter = ac.getBean("dmAdvised", EventDrivenConsumer.class);
|
||||
handler = TestUtils.getPropertyValue(dmAdapter, "handler", MessageHandler.class);
|
||||
handler.handleMessage(new GenericMessage<String>("foo"));
|
||||
assertEquals(1, adviceCalled);
|
||||
MessageHandler handler2 = TestUtils.getPropertyValue(ac.getBean("advised"), "handler", MessageHandler.class);
|
||||
assertNotSame(handler, handler2);
|
||||
handler2.handleMessage(new GenericMessage<String>("foo"));
|
||||
assertEquals(2, adviceCalled);
|
||||
}
|
||||
|
||||
public static class FooAdvice extends AbstractRequestHandlerAdvice {
|
||||
|
||||
@Override
|
||||
protected Object doInvoke(ExecutionCallback callback, Object target, Message<?> message) throws Exception {
|
||||
adviceCalled++;
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user