Pointcut parameters and Retrier log (#1236)

* Fixed a pointcut parameter list and log an exception that was being swallowed by Retrier

* Documentation clarification
This commit is contained in:
Ken Stevens 2019-03-11 17:31:03 -04:00 committed by GitHub
parent 71a07c0239
commit be4863133e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 5 deletions

View File

@ -136,9 +136,9 @@ public enum Pointcut {
* Hooks may accept the following parameters:
* </p>
* <ul>
* <li>java.lang.Exception - The exception that caused the failure</li>
* <li>ca.uhn.fhir.jpa.subscription.module.CanonicalSubscription</li>
* <li>ca.uhn.fhir.jpa.subscription.module.subscriber.ResourceDeliveryMessage</li>
* <li>java.lang.Exception - The exception that caused the failure. Note this could be an exception thrown by a SUBSCRIPTION_BEFORE_DELIVERY or SUBSCRIPTION_AFTER_DELIVERY interceptor</li>
* <li>ca.uhn.fhir.jpa.subscription.module.subscriber.ResourceDeliveryMessage - the message that triggered the exception</li>
* <li>java.lang.Exception</li>
* </ul>
* <p>
* Hooks may return <code>void</code> or may return a <code>boolean</code>. If the method returns
@ -149,7 +149,7 @@ public enum Pointcut {
* taken for the delivery.
* </p>
*/
SUBSCRIPTION_AFTER_DELIVERY_FAILED("ca.uhn.fhir.jpa.subscription.module.CanonicalSubscription", "ca.uhn.fhir.jpa.subscription.module.subscriber.ResourceDeliveryMessage"),
SUBSCRIPTION_AFTER_DELIVERY_FAILED("ca.uhn.fhir.jpa.subscription.module.subscriber.ResourceDeliveryMessage", "java.lang.Exception"),
/**
* Invoked immediately after the delivery of a REST HOOK subscription.

View File

@ -24,7 +24,11 @@ import org.apache.commons.lang3.Validate;
import org.apache.commons.lang3.time.DateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.retry.RetryCallback;
import org.springframework.retry.RetryContext;
import org.springframework.retry.RetryListener;
import org.springframework.retry.backoff.ExponentialBackOffPolicy;
import org.springframework.retry.listener.RetryListenerSupport;
import org.springframework.retry.policy.SimpleRetryPolicy;
import org.springframework.retry.support.RetryTemplate;
@ -52,6 +56,15 @@ public class Retrier<T> {
SimpleRetryPolicy retryPolicy = new SimpleRetryPolicy();
retryPolicy.setMaxAttempts(theMaxRetries);
myRetryTemplate.setRetryPolicy(retryPolicy);
RetryListener listener = new RetryListenerSupport() {
@Override
public <T, E extends Throwable> void onError(RetryContext context, RetryCallback<T, E> callback, Throwable throwable) {
super.onError(context, callback, throwable);
ourLog.error("Retry failure " + context.getRetryCount() + "/" + theMaxRetries, throwable);
}
};
myRetryTemplate.registerListener(listener);
}
public T runWithRetry() {

View File

@ -21,6 +21,7 @@ package ca.uhn.fhir.jpa.subscription.module.subscriber;
*/
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.jpa.model.interceptor.api.HookParams;
import ca.uhn.fhir.jpa.model.interceptor.api.IInterceptorBroadcaster;
import ca.uhn.fhir.jpa.model.interceptor.api.Pointcut;
import ca.uhn.fhir.jpa.subscription.module.cache.ActiveSubscription;
@ -79,7 +80,9 @@ public abstract class BaseSubscriptionDeliverySubscriber implements MessageHandl
ourLog.error(errorMsg, e);
// Interceptor call: SUBSCRIPTION_AFTER_DELIVERY
if (!myInterceptorBroadcaster.callHooks(Pointcut.SUBSCRIPTION_AFTER_DELIVERY_FAILED, msg, msg.getSubscription(), e)) {
HookParams hookParams = new HookParams()
.add(ResourceDeliveryMessage.class, msg).add(Exception.class, e);
if (!myInterceptorBroadcaster.callHooks(Pointcut.SUBSCRIPTION_AFTER_DELIVERY_FAILED, hookParams)) {
return;
}