# Class: ServiceDiscovery

## vertx-service-discovery-js/service_discovery~ ServiceDiscovery

#### new ServiceDiscovery()

Service Discovery main entry point.

The service discovery is an infrastructure that let you publish and find `services`. A `service` is a discoverable functionality. It can be qualified by its type, metadata, and location. So a `service` can be a database, a service proxy, a HTTP endpoint. It does not have to be a vert.x entity, but can be anything. Each service is

Source:
  - vertx-service-discovery-js/service_discovery.js, line 38

### Methods

#### bindings() → {Array.<ServiceReference>}

Source:
  - vertx-service-discovery-js/service_discovery.js, line 314

##### Returns:

the set of service references retrieved by this service discovery.

Type
  Array.<ServiceReference>

#### close()

Closes the service discovery

Source:
  - vertx-service-discovery-js/service_discovery.js, line 142

#### getRecord(filter, includeOutOfService, resultHandler)

Lookups for a single record.

The filter is a taking a Record as argument and returning a boolean. You should see it as an `accept` method of a filter. This method return a record passing the filter.

Unlike ServiceDiscovery#getRecord, this method may accept records with a `OUT OF SERVICE` status, if the `includeOutOfService` parameter is set to `true`.

##### Parameters:

Name | Type | Description
--- | --- | ---
`filter` | todo | the filter, must not be `null`. To return all records, use a function accepting all records
`includeOutOfService` | boolean | whether or not the filter accepts `OUT OF SERVICE` records
`resultHandler` | function | the result handler called when the lookup has been completed. When there are no matching record, the operation succeed, but the async result has no result.

Source:
  - vertx-service-discovery-js/service_discovery.js, line 203

#### getRecords(filter, includeOutOfService, resultHandler)

Lookups for a set of records. Unlike ServiceDiscovery#getRecord, this method returns all matching records.

The filter is a taking a Record as argument and returning a boolean. You should see it as an `accept` method of a filter. This method return a record passing the filter.

Unlike ServiceDiscovery#getRecords, this method may accept records with a `OUT OF SERVICE` status, if the `includeOutOfService` parameter is set to `true`.

##### Parameters:

Name | Type | Description
--- | --- | ---
`filter` | todo | the filter, must not be `null`. To return all records, use a function accepting all records
`includeOutOfService` | boolean | whether or not the filter accepts `OUT OF SERVICE` records
`resultHandler` | function | handler called when the lookup has been completed. When there are no matching record, the operation succeed, but the async result has an empty list as result.

Source:
  - vertx-service-discovery-js/service_discovery.js, line 253

#### getReference(record) → {ServiceReference}

Gets a service reference from the given record.

##### Parameters:

Name | Type | Description
--- | --- | ---
`record` | Object | the chosen record

Source:
  - vertx-service-discovery-js/service_discovery.js, line 50

##### Returns:

the service reference, that allows retrieving the service object. Once called the service reference is cached, and need to be released.

Type
  ServiceReference

#### getReferenceWithConfiguration(record, configuration) → {ServiceReference}

Gets a service reference from the given record, the reference is configured with the given json object.

##### Parameters:

Name | Type | Description
--- | --- | ---
`record` | Object | the chosen record
`configuration` | Object | the configuration

Source:
  - vertx-service-discovery-js/service_discovery.js, line 65

##### Returns:

the service reference, that allows retrieving the service object. Once called the service reference is cached, and need to be released.

Type
  ServiceReference

#### options() → {Object}

Source:
  - vertx-service-discovery-js/service_discovery.js, line 327

##### Returns:

the discovery options. Modifying the returned object would not update the discovery service configuration. This object should be considered as read-only.

Type
  Object

#### publish(record, resultHandler)

Publishes a record.

##### Parameters:

Name | Type | Description
--- | --- | ---
`record` | Object | the record
`resultHandler` | function | handler called when the operation has completed (successfully or not). In case of success, the passed record has a registration id required to modify and un-register the service.

Source:
  - vertx-service-discovery-js/service_discovery.js, line 156

#### registerServiceExporter(exporter, configuration, completionHandler) → {ServiceDiscovery}

Registers a discovery bridge. Exporters let you integrate other discovery technologies in this service discovery.

##### Parameters:

Name | Type | Description
--- | --- | ---
`exporter` | ServiceExporter | the service exporter
`configuration` | Object | the optional configuration
`completionHandler` | function | handler notified when the exporter has been correctly initialized.

Source:
  - vertx-service-discovery-js/service_discovery.js, line 121

##### Returns:

the current ServiceDiscovery

Type
  ServiceDiscovery

#### registerServiceImporter(importer, configuration, completionHandler) → {ServiceDiscovery}

Registers a discovery service importer. Importers let you integrate other discovery technologies in this service discovery.

##### Parameters:

Name | Type | Description
--- | --- | ---
`importer` | ServiceImporter | the service importer
`configuration` | Object | the optional configuration
`completionHandler` | function | handler call when the importer has finished its initialization and initial imports

Source:
  - vertx-service-discovery-js/service_discovery.js, line 96

##### Returns:

the current ServiceDiscovery

Type
  ServiceDiscovery

#### release(reference) → {boolean}

Releases the service reference.

##### Parameters:

Name | Type | Description
--- | --- | ---
`reference` | ServiceReference | the reference to release, must not be `null`

Source:
  - vertx-service-discovery-js/service_discovery.js, line 79

##### Returns:

whether or not the reference has been released.

Type
  boolean

#### unpublish(id, resultHandler)

Un-publishes a record.

##### Parameters:

Name | Type | Description
--- | --- | ---
`id` | string | the registration id
`resultHandler` | function | handler called when the operation has completed (successfully or not).

Source:
  - vertx-service-discovery-js/service_discovery.js, line 176

#### update(record, resultHandler)

Updates the given record. The record must has been published, and has it's registration id set.

##### Parameters:

Name | Type | Description
--- | --- | ---
`record` | Object | the updated record
`resultHandler` | function | handler called when the lookup has been completed.

Source:
  - vertx-service-discovery-js/service_discovery.js, line 295