# AmqpConnectionManagerSocketOptions

**Kind:** Interface

**Source:** [`packages/microservices/external/rmq-url.interface.ts`](https://github.com/nestjs/nest/blob/master/packages/microservices/external/rmq-url.interface.ts#L47)

**Part of:** [Microservices](subsystem-packages-microservices)

`AmqpConnectionManagerSocketOptions` configures how an AMQP connection manager discovers RabbitMQ servers and maintains its socket connection. It defines reconnect and heartbeat timing, AMQP connection settings, and client metadata used when establishing connections.

## Properties

| Property | Type |
|---|---|
| `reconnectTimeInSeconds` | `number` |
| `heartbeatIntervalInSeconds` | `number` |
| `findServers` | `() => string | string[]` |
| `connectionOptions` | `AmqpConnectionOptions` |
| `clientProperties` | `ClientProperties` |

## Diagram

```mermaid
graph LR
  App[Application / Microservice] --> Options[AmqpConnectionManagerSocketOptions]
  Options --> Discovery[findServers()]
  Discovery --> Servers[AMQP Server URL(s)]
  Options --> Reconnect[reconnectTimeInSeconds]
  Options --> Heartbeat[heartbeatIntervalInSeconds]
  Options --> Connection[connectionOptions]
  Options --> Properties[clientProperties]
  Servers --> Manager[AMQP Connection Manager]
  Reconnect --> Manager
  Heartbeat --> Manager
  Connection --> Manager
  Properties --> Manager
  Manager --> RabbitMQ[RabbitMQ Cluster]
```

## Usage

```ts
import type {
  AmqpConnectionManagerSocketOptions,
} from './rmq-url.interface';

const socketOptions: AmqpConnectionManagerSocketOptions = {
  reconnectTimeInSeconds: 5,
  heartbeatIntervalInSeconds: 30,

  findServers: () => [
    'amqp://rabbitmq-1:5672',
    'amqp://rabbitmq-2:5672',
  ],

  connectionOptions: {
    username: process.env.RABBITMQ_USERNAME,
    password: process.env.RABBITMQ_PASSWORD,
    vhost: process.env.RABBITMQ_VHOST ?? '/',
  },

  clientProperties: {
    connection_name: 'orders-service',
  },
};

// Pass socketOptions to the AMQP/RabbitMQ connection setup.
```

## AI Coding Instructions

- Return one or more valid AMQP server URLs from `findServers`; use multiple URLs for clustered RabbitMQ deployments.
- Keep `reconnectTimeInSeconds` and `heartbeatIntervalInSeconds` positive and appropriate for the service reliability requirements.
- Store credentials in environment variables or a secrets manager rather than hardcoding them in `connectionOptions`.
- Set a meaningful `clientProperties.connection_name` value to make RabbitMQ management and connection debugging easier.
- Ensure `connectionOptions` matches the AMQP client library's supported connection option format.
