Service
A service that processes requests coming from other VMs connected to the data cloud.
Constructors
new Service()
new Service(serviceId, context): Service
Create a new instance of the service with the specified id. It uses the context to make the lifecycle of the service related to the context one.
Parameters
Parameter | Type | Description |
---|---|---|
serviceId | string | the service id |
context | Context | the context of that service. |
Returns
Service
Methods
get()
static get(
service,
payload,
config?): Promise<Object>
Send a request to a Service and wait for a reply with a payload..
Parameters
Parameter | Type | Description |
---|---|---|
service | string | the service id |
payload | Object | the message payload |
config ? | ServiceConfig | optional parameters for the message |
Returns
Promise
<Object
>
a Promise wrapping the resulting value
getPublisher()
static getPublisher(service): Publisher
Returns a Publisher to publish a list of messages to the same service handler, to ensure the messages published are processed by the same processor instead of being balanced between the potential multiple instances of the service.
Parameters
Parameter | Type | Description |
---|---|---|
service | string | the service id |
Returns
observe()
static observe(
service,
context,
payload?,
config?): object
Send a request to a Service and subscribe to notifications published from that service.
Parameters
Parameter | Type | Description |
---|---|---|
service | string | the service id |
context | Context | the context used to link its lifecycle to this subscription |
payload ? | Object | the message payload, optional |
config ? | SubscriptionServiceConfig | optional parameters for the message |
Returns
object
an Observable emitting notifications
observable
observable: Observable<Object>;
publisher
publisher: Publisher;
publish()
static publish(service, payload): Promise<void>
Publish a message on the specified service without waiting for any acknowledge
Parameters
Parameter | Type | Description |
---|---|---|
service | string | the service id |
payload | Object |
Returns
Promise
<void
>
send()
static send(
service,
payload?,
config?): Promise<void>
Send a request to a Service and wait for an ack.
Parameters
Parameter | Type | Description |
---|---|---|
service | string | the service id |
payload ? | Object | the message payload, optional |
config ? | ServiceConfig | optional parameters for the message |
Returns
Promise
<void
>
a Promise that completes when the call has been executed
listen()
listen(): Observable<ServiceRequest>
Start and listen to incoming requests.
Returns
Observable
<ServiceRequest
>
multicast()
multicast(payload): Promise<void>
Send the given payload to all available instances (e.g.: when running multiple replicas of the same backend) of the current service.
Parameters
Parameter | Type | Description |
---|---|---|
payload | Object | the message content |
Returns
Promise
<void
>
setUnsubscriptionHandler()
setUnsubscriptionHandler(handler): this
Set a function to be executed each time a subscription to that service is closed. The function receives the subscription id that has been closed. The subscription id is the one that has been set and returned by the ServiceRequest.notifyOn method.
Parameters
Parameter | Type | Description |
---|---|---|
handler | (subId ) => void | the handler function to be executed when a subscription is closed. |
Returns
this
this Service instance.
stop()
stop(): void
Stop the service.
Returns
void