﻿# Connecting endpoints

<!-- Version variant: platformconnector_3; default: [/platform/connecting.md](/platform/connecting.md) -->


The ServicePlatform Connector plugin provides a unified API to connect an NServiceBus endpoint to the Particular Service Platform by configuring:

- an [error queue](/nservicebus/recoverability/configure-error-handling.md#configure-the-error-queue-address-using-code) address
- [message auditing](/nservicebus/operations/auditing.md)
- [saga auditing](/nservicebus/sagas/saga-audit.md)
- [performance metrics](/monitoring/metrics/index.md) collection
- [custom checks](/monitoring/custom-checks/install-plugin.md)
- [heartbeats](/monitoring/heartbeats/index.md)

## JSON

The connection details can be parsed from JSON with [a specific configuration schema](json-schema.md).

<!-- snippet: PlatformConnector-FromJson -->

```cs
var json = File.ReadAllText(pathToJson);
var platformConnection = ServicePlatformConnectionConfiguration.Parse(json);

endpointConfiguration.ConnectToServicePlatform(platformConnection);
```

<!-- endsnippet -->

The JSON file looks like this:

<!-- snippet: PlatformConnector-Json -->

```json
{
  "ErrorQueue": "myErrorQueue",
  "Heartbeats": {
    "Enabled": true,
    "HeartbeatsQueue": "heartbeatsQueue"
  },
  "CustomChecks": {
    "Enabled": true,
    "CustomChecksQueue": "customChecksQueue"
  },
  "MessageAudit": {
    "Enabled": true,
    "AuditQueue": "myAuditQueue"
  },
  "SagaAudit": {
    "Enabled": true,
    "SagaAuditQueue": "sagaAuditQueue"
  },
  "Metrics": {
    "Enabled": true,
    "MetricsQueue": "metricsQueue",
    "Interval": "00:00:10"
  }
}
```

<!-- endsnippet -->

A JSON file specific to a concrete deployment of the ServicePlatform is available via ServicePulse.

![Screenshot of ServicePulse showing the configuration endpoint connection JSON file tab](connecting.servicepulse.png)

## Code first

The connection details can be constructed in code.

<!-- snippet: PlatformConnector-CodeFirst -->

```cs
var platformConnection = new ServicePlatformConnectionConfiguration
{
    ErrorQueue = "myErrorQueue",
    Heartbeats = new ServicePlatformHeartbeatConfiguration
    {
        Enabled = true,
        HeartbeatsQueue = "heartbeatsQueue"
    },
    CustomChecks = new ServicePlatformCustomChecksConfiguration
    {
        Enabled = true,
        CustomChecksQueue = "customChecksQueue"
    },
    MessageAudit = new ServicePlatformMessageAuditConfiguration
    {
        Enabled = true,
        AuditQueue = "myAuditQueue"
    },
    SagaAudit = new ServicePlatformSagaAuditConfiguration
    {
        Enabled = true,
        SagaAuditQueue = "sagaAuditQueue"
    },
    Metrics = new ServicePlatformMetricsConfiguration
    {
        Enabled = true,
        MetricsQueue = "metricsQueue",
        Interval = TimeSpan.FromSeconds(60)
    }
};

endpointConfiguration.ConnectToServicePlatform(platformConnection);
```

<!-- endsnippet -->

## Combined

Configuration can be loaded from JSON and then overridden in code.

<!-- snippet: PlatformConnector-Combo -->

```cs
var json = File.ReadAllText(pathToJson);
var platformConnection = ServicePlatformConnectionConfiguration.Parse(json);

platformConnection.Heartbeats.Enabled = false;
platformConnection.Metrics.InstanceId = "MyCustomInstanceId";

endpointConfiguration.ConnectToServicePlatform(platformConnection);
```

<!-- endsnippet -->
