ExternalService
Interface to an external service.
External services must be carefully managed in reactive Skip services to make sure that dependencies are properly tracked and data from external systems is kept up to date.
Context.useExternalResource
accepts the name of an external service, which must be associated to an instance of this ExternalService
interface by SkipService.externalServices
.
Custom implementations of the ExternalService
interface can be defined as needed, and the Skip framework provides several out of the box: SkipExternalService
and PolledExternalService
in the @skipruntime/helpers
package, and integrations with other systems such as PostgreSQL and Kafka in @skip-adapter/*
packages.
If it is a Skip service, then SkipExternalService
can be used, specifying an entrypoint.
The external Skip service will update its resources reactively and those changes will propagate through this service.
If it is not a Skip service, then PolledExternalService
can be used to specify the external source and desired polling frequency.
Methods
shutdown()
shutdown(): Promise<void>
Shutdown the external service.
Returns
Promise
<void
>
subscribe()
subscribe(
instance,
resource,
params,
callbacks): Promise<void>
Subscribe to a resource provided by the external service.
Parameters
Parameter | Type | Description |
---|---|---|
instance | string | Instance identifier of the external resource. |
resource | string | Name of the external resource. |
params | Json | Parameters of the external resource. |
callbacks | { error : (error ) => void ; update : (updates , isInit ) => Promise <void >; } | Callbacks to react on error/update. |
callbacks.error | (error ) => void | Error callback to log the error that prevent an idermetiate update. |
callbacks.update | (updates , isInit ) => Promise <void > | Update callback. |
Returns
Promise
<void
>
unsubscribe()
unsubscribe(instance): void
Unsubscribe from a resource provided by the external service.
Parameters
Parameter | Type | Description |
---|---|---|
instance | string | Instance identifier of the external resource. |
Returns
void