メソッドhelloWorld
にアドバイスを適用したいと思います。私は 'x' TPSを超える通話を抑制し、それらの通話を再試行したいと思います。コールレートは、コールが絞られた場合に再試行「はx」の Spring AOP - 複数のインターセプタが連携していません
- スロットルインターセプタ、 -
は、だから私は2つのインターセプタを持っています。
問題は、私は2つのインターセプタを組み合わせたときにスロットル インターセプターは、私は0としてレートを提供しても仕事をいないようだということで、それが実行されますのHelloWorld methosです。
私が を使用している場合は、Throttling Interceptorが正常に動作します。
私のSpring Configuration
はこのようなものです。
<bean id="retryPolicy" class="xyz.RetryPolicyFactoryBean">
<property name="backoffCoefficient"><value>2</value></property>
<property name="multiplierMillis"><value>100</value></property>
<property name="maxDelayMillis"><value>2000</value></property>
<property name="maxAttempts"><value>2</value></property>
<property name="expirationDurationMillis"><value>60000</value></property>
<bean id="retryInterceptor" class="xyz.RetryInterceptor">
<constructor-arg index="0"><ref bean="retryPolicy"/></constructor-arg>
</bean>
<bean id="throttlingInterceptor" class="xyz.ThrottlingInterceptor">
<constructor-arg index="0"><value>key</value></constructor-arg>
</bean>
<bean id="helloWorld" class="xyz.helloWorld" />
<bean id="helloWorldProxy" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="target" ref="helloWorld" />
<property name="interceptorNames">
<list>
<value>retryInterceptor</value>
<value>throttlingInterceptor</value>
</list>
</property>
</bean>
Throttling Interceptor
このようなものです:
@Override
public Object invoke(MethodInvocation methodInvocation) throws Throwable {
if (isDecorated(methodInvocation)) {
if (throttler.isThrottled(key)) {
throw new ThrottlingException("Call throttled.");
}
}
return methodInvocation.proceed();
}
私retry interceptor
は、このようなものです:私はここに
public class RetryInterceptor extends RetryAdvice {
public RetryInterceptor(RetryPolicy retryPolicy) {
super(retryPolicy);
}
@Override
public Object invoke(final MethodInvocation methodInvocation) throws Throwable {
return super.invoke(methodInvocation);
}
何をしないのですか?
「RetryAdvice」を拡張することは何ですか?そして、なぜあなたはAOPを適用する古い方法を使用していますか? 'RetryAdvice'とは何ですか? –
@ M.Deinum私はSpring AOPの初心者ですので、AOPを使用する標準的な方法を教えていただければ幸いです。再試行アドバイスは、再試行ポリシーを適用するクラスです。それは、それに提供されたRetryPolicyを単に適用し、methodInvocation.proceed()を呼び出すinvoke()メソッドを持っています。再試行を使用するより良い方法はありますか? – AgentX
しかし、なぜそれを拡張していますか?あなたの拡張機能は何も追加しません...オーバーライドとコンストラクタは意味をなさない...しかし、あなたはAOPを指定するために ' 'を使いたいと思うでしょう。あなたは手動で 'ProxyFactoryBean各AOP Beanに対して ''それはエラーが起こりやすく、例外が作られるでしょう。 –