Address review comments

This commit is contained in:
James Agnew 2019-02-08 17:26:34 -05:00
parent 88eb2c424e
commit 4699c51997
3 changed files with 25 additions and 23 deletions

View File

@ -63,7 +63,7 @@ public class SubscriptionDebugLogInterceptor {
public void step10_resourceModified(ResourceModifiedMessage theMessage) { public void step10_resourceModified(ResourceModifiedMessage theMessage) {
String value = Long.toString(System.currentTimeMillis()); String value = Long.toString(System.currentTimeMillis());
theMessage.setAttribute(SUBSCRIPTION_DEBUG_LOG_INTERCEPTOR_PRECHECK, value); theMessage.setAttribute(SUBSCRIPTION_DEBUG_LOG_INTERCEPTOR_PRECHECK, value);
log(EventCodeEnum.SUBS10, "Resource {} was submitted to the processing pipeline (op={})", theMessage.getPayloadId(), theMessage.getOperationType()); log(EventCodeEnum.SUBS1, "Resource {} was submitted to the processing pipeline (op={})", theMessage.getPayloadId(), theMessage.getOperationType());
} }
/* /*
@ -78,27 +78,27 @@ public class SubscriptionDebugLogInterceptor {
@Hook(Pointcut.SUBSCRIPTION_BEFORE_PERSISTED_RESOURCE_CHECKED) @Hook(Pointcut.SUBSCRIPTION_BEFORE_PERSISTED_RESOURCE_CHECKED)
public void step20_beforeChecked(ResourceModifiedMessage theMessage) { public void step20_beforeChecked(ResourceModifiedMessage theMessage) {
log(EventCodeEnum.SUBS20, "Checking resource {} (op={}) for matching subscriptions", theMessage.getPayloadId(), theMessage.getOperationType()); log(EventCodeEnum.SUBS2, "Checking resource {} (op={}) for matching subscriptions", theMessage.getPayloadId(), theMessage.getOperationType());
} }
@Hook(Pointcut.SUBSCRIPTION_RESOURCE_MATCHED) @Hook(Pointcut.SUBSCRIPTION_RESOURCE_MATCHED)
public void step30_subscriptionMatched(ResourceDeliveryMessage theMessage, SubscriptionMatchResult theResult) { public void step30_subscriptionMatched(ResourceDeliveryMessage theMessage, SubscriptionMatchResult theResult) {
log(EventCodeEnum.SUBS30, "Resource {} matched by subscription {} (memory match={})", theMessage.getPayloadId(), theMessage.getSubscription().getIdElementString(), theResult.isInMemory()); log(EventCodeEnum.SUBS3, "Resource {} matched by subscription {} (memory match={})", theMessage.getPayloadId(), theMessage.getSubscription().getIdElementString(), theResult.isInMemory());
} }
@Hook(Pointcut.SUBSCRIPTION_RESOURCE_DID_NOT_MATCH_ANY_SUBSCRIPTIONS) @Hook(Pointcut.SUBSCRIPTION_RESOURCE_DID_NOT_MATCH_ANY_SUBSCRIPTIONS)
public void step35_subscriptionNotMatched(ResourceModifiedMessage theMessage) { public void step35_subscriptionNotMatched(ResourceModifiedMessage theMessage) {
log(EventCodeEnum.SUBS35, "Resource {} did not match any subscriptions", theMessage.getPayloadId()); log(EventCodeEnum.SUBS4, "Resource {} did not match any subscriptions", theMessage.getPayloadId());
} }
@Hook(Pointcut.SUBSCRIPTION_BEFORE_DELIVERY) @Hook(Pointcut.SUBSCRIPTION_BEFORE_DELIVERY)
public void step40_beforeDelivery(ResourceDeliveryMessage theMessage) { public void step40_beforeDelivery(ResourceDeliveryMessage theMessage) {
log(EventCodeEnum.SUBS40, "Delivering resource {} for subscription {} to channel of type {} to endpoint {}", theMessage.getPayloadId(), theMessage.getSubscription().getIdElementString(), theMessage.getSubscription().getChannelType(), theMessage.getSubscription().getEndpointUrl()); log(EventCodeEnum.SUBS5, "Delivering resource {} for subscription {} to channel of type {} to endpoint {}", theMessage.getPayloadId(), theMessage.getSubscription().getIdElementString(), theMessage.getSubscription().getChannelType(), theMessage.getSubscription().getEndpointUrl());
} }
@Hook(Pointcut.SUBSCRIPTION_AFTER_DELIVERY_FAILED) @Hook(Pointcut.SUBSCRIPTION_AFTER_DELIVERY_FAILED)
public void step45_deliveryFailed(ResourceDeliveryMessage theMessage, Exception theFailure) { public void step45_deliveryFailed(ResourceDeliveryMessage theMessage, Exception theFailure) {
log(EventCodeEnum.SUBS45, "Delivery of resource {} for subscription {} to channel of type {} - Failure: {}", theMessage.getPayloadId(), theMessage.getSubscription().getIdElementString(), theMessage.getSubscription().getChannelType(), theFailure.toString()); log(EventCodeEnum.SUBS6, "Delivery of resource {} for subscription {} to channel of type {} - Failure: {}", theMessage.getPayloadId(), theMessage.getSubscription().getIdElementString(), theMessage.getSubscription().getChannelType(), theFailure.toString());
} }
@Hook(Pointcut.SUBSCRIPTION_AFTER_DELIVERY) @Hook(Pointcut.SUBSCRIPTION_AFTER_DELIVERY)
@ -110,7 +110,7 @@ public class SubscriptionDebugLogInterceptor {
.map(start -> new StopWatch(start).toString()) .map(start -> new StopWatch(start).toString())
.orElse("(unknown)"); .orElse("(unknown)");
log(EventCodeEnum.SUBS50, "Finished delivery of resource {} for subscription {} to channel of type {} - Total processing time: {}", theMessage.getPayloadId(), theMessage.getSubscription().getIdElementString(), theMessage.getSubscription().getChannelType(), processingTime); log(EventCodeEnum.SUBS7, "Finished delivery of resource {} for subscription {} to channel of type {} - Total processing time: {}", theMessage.getPayloadId(), theMessage.getSubscription().getIdElementString(), theMessage.getSubscription().getChannelType(), processingTime);
} }
protected void log(EventCodeEnum theEventCode, String theMessage, Object... theArguments) { protected void log(EventCodeEnum theEventCode, String theMessage, Object... theArguments) {
@ -141,34 +141,34 @@ public class SubscriptionDebugLogInterceptor {
* A new/updated resource has been submitted to the processing pipeline and is about * A new/updated resource has been submitted to the processing pipeline and is about
* to be placed on the matchign queue. * to be placed on the matchign queue.
*/ */
SUBS10, SUBS1,
/** /**
* A resources has been dequeued from the matching queue and is about to be checked * A resources has been dequeued from the matching queue and is about to be checked
* for any matching subscriptions. * for any matching subscriptions.
*/ */
SUBS20, SUBS2,
/** /**
* The resource has matched a subscription (logged once for each matching subscription) * The resource has matched a subscription (logged once for each matching subscription)
* and is about to be queued for delivery. * and is about to be queued for delivery.
*/ */
SUBS30, SUBS3,
/** /**
* The resource did not match any subscriptions and processing is complete. * The resource did not match any subscriptions and processing is complete.
*/ */
SUBS35, SUBS4,
/** /**
* The resource has been dequeued from the delivery queue and is about to be * The resource has been dequeued from the delivery queue and is about to be
* delivered. * delivered.
*/ */
SUBS40, SUBS5,
/** /**
* Delivery failed * Delivery failed
*/ */
SUBS45, SUBS6,
/** /**
* Delivery is now complete and processing is finished. * Delivery is now complete and processing is finished.
*/ */
SUBS50 SUBS7
} }

View File

@ -50,7 +50,7 @@ public abstract class BaseSubscriptionDeliverySubscriber implements MessageHandl
} }
ResourceDeliveryMessage msg = (ResourceDeliveryMessage) theMessage.getPayload(); ResourceDeliveryMessage msg = (ResourceDeliveryMessage) theMessage.getPayload();
String subscriptionId = msg.getSubscription().getIdElement(myFhirContext).getValue(); String subscriptionId = msg.getSubscriptionId(myFhirContext);
ActiveSubscription updatedSubscription = mySubscriptionRegistry.get(msg.getSubscription().getIdElement(myFhirContext).getIdPart()); ActiveSubscription updatedSubscription = mySubscriptionRegistry.get(msg.getSubscription().getIdElement(myFhirContext).getIdPart());
if (updatedSubscription != null) { if (updatedSubscription != null) {
@ -71,13 +71,14 @@ public abstract class BaseSubscriptionDeliverySubscriber implements MessageHandl
} catch (Exception e) { } catch (Exception e) {
String errorMsg = "Failure handling subscription payload for subscription: " + subscriptionId;
ourLog.error(errorMsg, e);
// Interceptor call: SUBSCRIPTION_AFTER_DELIVERY // Interceptor call: SUBSCRIPTION_AFTER_DELIVERY
if (!myInterceptorBroadcaster.callHooks(Pointcut.SUBSCRIPTION_AFTER_DELIVERY_FAILED, msg, msg.getSubscription(), e)) { if (!myInterceptorBroadcaster.callHooks(Pointcut.SUBSCRIPTION_AFTER_DELIVERY_FAILED, msg, msg.getSubscription(), e)) {
return; return;
} }
String errorMsg = "Failure handling subscription payload for subscription: " + subscriptionId;
ourLog.error(errorMsg, e);
throw new MessagingException(theMessage, errorMsg, e); throw new MessagingException(theMessage, errorMsg, e);
} }
} }

View File

@ -28,16 +28,10 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.gson.Gson; import com.google.gson.Gson;
import org.apache.commons.lang3.Validate;
import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringBuilder;
import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.instance.model.api.IIdType;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import static org.apache.commons.lang3.StringUtils.isNotBlank; import static org.apache.commons.lang3.StringUtils.isNotBlank;
@SuppressWarnings("WeakerAccess") @SuppressWarnings("WeakerAccess")
@ -133,4 +127,11 @@ public class ResourceDeliveryMessage extends BaseResourceMessage implements IRes
.append("myOperationType", myOperationType) .append("myOperationType", myOperationType)
.toString(); .toString();
} }
/**
* Helper method to fetch the subscription ID
*/
public String getSubscriptionId(FhirContext theFhirContext) {
return getSubscription().getIdElement(theFhirContext).getValue();
}
} }