# NATS C Client with JetStream and Streaming support: microService

Loading...
Searching...
No Matches
microService
EXPERIMENTAL - Microservices » Functions

## Functions

NATS_EXTERN microError * | micro_AddService (microService **new_microservice, natsConnection *nc, microServiceConfig *config)
| Creates and starts a new microservice.
NATS_EXTERN microError * | microService_AddEndpoint (microService *m, microEndpointConfig *config)
| Adds an endpoint to a microservice and starts listening for messages.
NATS_EXTERN microError * | microService_AddGroup (microGroup **new_group, microService *m, const char *prefix)
| Adds an group (prefix) to a microservice.
NATS_EXTERN microError * | microService_Destroy (microService *m)
| Destroys a microservice, stopping it first if needed.
NATS_EXTERN natsConnection * | microService_GetConnection (microService *m)
| Returns the connection associated with the service. If the service was successfully started, it is safe to assume it's not NULL, however it may already have been disconnected or closed.
NATS_EXTERN microError * | microService_GetInfo (microServiceInfo **new_info, microService *m)
| Returns a microServiceInfo for a microservice.
NATS_EXTERN void * | microService_GetState (microService *m)
| Returns the pointer to state data (closure). It is originally provided in microServiceConfig.State.
NATS_EXTERN microError * | microService_GetStats (microServiceStats **new_stats, microService *m)
| Returns run-time statistics for a microservice.
NATS_EXTERN bool | microService_IsStopped (microService *m)
| Checks if the service is stopped.
NATS_EXTERN microError * | microService_Run (microService *m)
| Waits for a microservice to stop.
NATS_EXTERN microError * | microService_Stop (microService *m)
| Stops a running microservice.

## Detailed Description

Functions that operate with microService.

## Function Documentation

## micro_AddService()

NATS_EXTERN microError * micro_AddService | ( | microService ** | new_microservice,
|  | natsConnection * | nc,
|  | microServiceConfig * | config
| ) |  |

Note
  The microservice should be destroyed to clean up using microService_Destroy.

Parameters

  new_microservice | the location where to store the pointer to the new microService object.
  nc | the natsConnection the service will use to receive and respond to requests.
  config | a microServiceConfig object with the configuration of the service. See micro_service_config_s for descriptions of the fields.

Returns
  a microError if an error occurred.

See also
  microService_Destroy, microService_AddEndpoint, microServiceConfig, microEndpointConfig

## microService_AddEndpoint()

NATS_EXTERN microError * microService_AddEndpoint | ( | microService * | m,
|  | microEndpointConfig * | config
| ) |  |

Endpoints are currently destroyed when the service is stopped, there is no present way to remove or stop individual endpoints.

Parameters

  m | the microService that the endpoint will be added to.
  config | a microEndpointConfig object with the configuration of the endpoint. See micro_endpoint_config_s for descriptions of the fields.

Returns
  a microError if an error occurred.

See also
  microService_Destroy, microEndpointConfig

## microService_AddGroup()

NATS_EXTERN microError * microService_AddGroup | ( | microGroup ** | new_group,
|  | microService * | m,
|  | const char * | prefix
| ) |  |

Groups are associated with a service, and are destroyed when the service is destroyed.

Parameters

  new_group | the location where to store the pointer to the new microGroup object.
  m | the microService that the group will be added to.
  prefix | a prefix to use on names and subjects of all endpoints in the group.

Returns
  a microError if an error occurred.

See also
  microGroup_AddGroup, microGroup_AddEndpoint

## microService_Destroy()

NATS_EXTERN microError * microService_Destroy | ( | microService * | m | ) |

Note
  This function may fail while stopping the service, do not assume unconditional success if clean up is important.

Parameters

  m | the microService to stop and destroy.

Returns
  a microError if an error occurred.

See also
  microService_Stop, microService_Run

## microService_GetConnection()

NATS_EXTERN natsConnection * microService_GetConnection | ( | microService * | m | ) |

Parameters

  m | the microService.

Returns
  a natsConnection associated with the service.

## microService_GetInfo()

NATS_EXTERN microError * microService_GetInfo | ( | microServiceInfo ** | new_info,
|  | microService * | m
| ) |  |

Note
  the microServiceInfo struct returned by this call should be freed with microServiceInfo_Destroy.

Parameters

  new_info | receives the pointer to the microServiceInfo.
  m | the microService to query.

Returns
  a microError if an error occurred.

See also
  microServiceInfo, micro_service_info_s

## microService_GetState()

NATS_EXTERN void * microService_GetState | ( | microService * | m | ) |

Parameters

  m | the microService.

Returns
  the state pointer.

See also
  microServiceConfig

## microService_GetStats()

NATS_EXTERN microError * microService_GetStats | ( | microServiceStats ** | new_stats,
|  | microService * | m
| ) |  |

Note
  the microServiceStats struct returned by this call should be freed with microServiceStats_Destroy.

Parameters

  new_stats | receives the pointer to the microServiceStats.
  m | the microService to query.

Returns
  a microError if an error occurred.

See also
  microServiceStats, micro_service_stats_s

## microService_IsStopped()

NATS_EXTERN bool microService_IsStopped | ( | microService * | m | ) |

Parameters

  m | the microService.

Returns
  `true` if stopped, otherwise `false`.

See also
  micro_AddService, microService_Stop, microService_Run

## microService_Run()

NATS_EXTERN microError * microService_Run | ( | microService * | m | ) |

micro_AddService starts the service with async subscriptions. microService_Run waits for the service to stop.

Parameters

  m | the microService.

Returns
  a microError for invalid arguments, otherwise always succeeds.

See also
  micro_AddService, microService_Stop

## microService_Stop()

NATS_EXTERN microError * microService_Stop | ( | microService * | m | ) |

Drains and closes the all subscriptions (endpoints and monitoring), resets the stats, and calls the `Done` callback for the service, so it can do its own clean up if needed.

It is possible that this call encounters an error while stopping the service, in which case it aborts and returns the error. The service then may be in a partially stopped state, and the `Done` callback will not have been called.

Parameters

  m | the microService.

Returns
  a microError if an error occurred.

See also
  micro_AddService, microService_Run