-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Subscription Startup Resiliency
There are two ways to set up Subscription Matching using the HAPI-FHIR JPA Server:
- Embedded Subscription Matching within a FHIR Server Endpoint using the SubscriptionMatchingInterceptor:
// FHIR Server Config
myDaoConfig.addSupportedSubscriptionType(Subscription.SubscriptionChannelType.RESTHOOK);
myDaoConfig.setSubscriptionMatchingEnabled(true);
mySubscriptionInterceptorLoader.registerInterceptors();
- Standalone Subscription Matching outside of the FHIR Server Endpoint using a StandaloneSubscriptionMessageHandler:
// FHIR Server Config
myDaoConfig.addSupportedSubscriptionType(Subscription.SubscriptionChannelType.RESTHOOK);
myDaoConfig.setSubscriptionMatchingEnabled(false);
mySubscriptionInterceptorLoader.registerInterceptors();
In this topology, you will need to register your own FHIR Server interceptor that sends all Resources to a SubscribableChannel. Then subscribe the StandaloneSubscriptionMessageHandler to that SubcribableChannel within your Message Consumer Server:
// Message Consumer Server Config:
mySubscribableChannel.subscribe(myStandaloneSubscriptionMessageHandler);
In both topologies, two in-memory registries need to be initialized and kept in-sync with the FHIR Data Repository:
- ActiveSubscriptionRegistry: The list of active Subscriptions that are used to match incoming resources.
- SearchParamRegistry: The list of active Search Parameters used by the FHIR Server (including custom search params and excluding disabled search params)
The way these are initialized and synchronized works differently in the two topologies:
In both topologies, mySubscriptionInterceptorLoader.registerInterceptors() in the FHIR Server loads subscriptions from the database into the ActiveSubscriptionRegistry before registering the SubscriptionActivatingInterceptor. This should happen before the FHIR Server has started processing resources to ensure that no subscriptions are missed.
Also in both topologies, as new Subscription resources arrive, the SubscriptionActivatingInterceptor will activate them (if that type of subscription was enabled via myDaoConfig.addSupportedSubscriptionType) and load them into the ActiveSubscriptionRegistry of the FHIR Server.
In the Standalone topology, the Message Consumer Server also needs to maintain its own ActiveSubscriptionRegistry. It does initializes it by making a HTTP call to a FHIR Server (via a configured FhirClientSubscriptionProvider).
In both topologies, all ActiveSubscriptionRegistries are updated as new Subscription resources arrive. Also, as a failsafe, all ActiveSubscriptionRegistries synchronize their contents with the source repository (either via a database call or an HTTP call) one per minute. (SubscriptionLoader.initSubscriptions()).
The SearchParamRegistry works differently. It is not initialized at startup. Rather, it synchronizes its contents on a schedule of once per hour (either via a database call or an HTTP call).