**@amqp-contract/core**

***

# @amqp-contract/core

## Classes

### AmqpClient

Defined in: [packages/core/src/amqp-client.ts:149](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/amqp-client.ts#L149)

AMQP client that manages connections and channels with automatic topology setup.

This class handles:
- Connection management with automatic reconnection via amqp-connection-manager
- Connection pooling and sharing across instances with the same URLs
- Automatic AMQP topology setup (exchanges, queues, bindings) from contract
- Channel creation with JSON serialization enabled by default

All operations return `AsyncResult<T, TechnicalError>` for consistent error handling.

#### Example

```typescript
const client = new AmqpClient(contract, {
  urls: ['amqp://localhost'],
  connectionOptions: { heartbeatIntervalInSeconds: 30 }
});

// Wait for connection (AsyncResult is thenable)
await client.waitForConnect();

// Publish a message
const result = await client.publish('exchange', 'routingKey', { data: 'value' });

// Close when done
await client.close();
```

#### Constructors

##### Constructor

```ts
new AmqpClient(contract, options): AmqpClient;
```

Defined in: [packages/core/src/amqp-client.ts:177](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/amqp-client.ts#L177)

Create a new AMQP client instance.

The client will automatically:
- Get or create a shared connection using the singleton pattern
- Set up AMQP topology (exchanges, queues, bindings) from the contract
- Create a channel with JSON serialization enabled

###### Parameters

| Parameter | Type | Description |
| ------ | ------ | ------ |
| `contract` | `ContractDefinition` | The contract definition specifying the AMQP topology |
| `options` | [`AmqpClientOptions`](#amqpclientoptions) | Client configuration options |

###### Returns

[`AmqpClient`](#amqpclient)

#### Methods

##### ack()

```ts
ack(msg, allUpTo?): void;
```

Defined in: [packages/core/src/amqp-client.ts:443](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/amqp-client.ts#L443)

Acknowledge a message.

###### Parameters

| Parameter | Type | Default value | Description |
| ------ | ------ | ------ | ------ |
| `msg` | `ConsumeMessage` | `undefined` | The message to acknowledge |
| `allUpTo` | `boolean` | `false` | If true, acknowledge all messages up to and including this one |

###### Returns

`void`

##### addSetup()

```ts
addSetup(setup): void;
```

Defined in: [packages/core/src/amqp-client.ts:465](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/amqp-client.ts#L465)

Add a setup function to be called when the channel is created or reconnected.

This is useful for setting up channel-level configuration like prefetch.

###### Parameters

| Parameter | Type | Description |
| ------ | ------ | ------ |
| `setup` | (`channel`) => `void` \| `Promise`&lt;`void`&gt; | The setup function to add |

###### Returns

`void`

##### cancel()

```ts
cancel(consumerTag): AsyncResult<void, TechnicalError>;
```

Defined in: [packages/core/src/amqp-client.ts:412](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/amqp-client.ts#L412)

Cancel a consumer by its consumer tag.

###### Parameters

| Parameter | Type |
| ------ | ------ |
| `consumerTag` | `string` |

###### Returns

`AsyncResult`&lt;`void`, [`TechnicalError`](#technicalerror)&gt;

##### close()

```ts
close(): AsyncResult<void, TechnicalError>;
```

Defined in: [packages/core/src/amqp-client.ts:495](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/amqp-client.ts#L495)

Close the channel and release the connection reference.

This will:
- Close the channel wrapper
- Decrease the reference count on the shared connection
- Close the connection if this was the last client using it

Both steps run regardless of each other's outcome; if both fail, the
errors are wrapped in an AggregateError.

###### Returns

`AsyncResult`&lt;`void`, [`TechnicalError`](#technicalerror)&gt;

##### consume()

```ts
consume(
   queue, 
   callback, 
   options?): AsyncResult<string, TechnicalError>;
```

Defined in: [packages/core/src/amqp-client.ts:338](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/amqp-client.ts#L338)

Start consuming messages from a queue.

If `options.prefetch` is set, a per-consumer prefetch count is applied via
`channel.prefetch(count, false)` registered as a setup function on the
channel wrapper *before* the underlying `consume` call. Registering it via
`addSetup` ensures the prefetch is reapplied automatically on channel
reconnect; using `global=false` scopes it to subsequent consumers on the
channel (RabbitMQ semantics — opposite of intuition: `false` is per-
consumer, `true` is channel-wide).

`prefetch` is stripped from the options handed to `channelWrapper.consume`
because it is not a valid `amqplib` `Options.Consume` field — leaving it
in would just travel as a no-op key-value pair on the consume frame.

###### Parameters

| Parameter | Type |
| ------ | ------ |
| `queue` | `string` |
| `callback` | [`ConsumeCallback`](#consumecallback) |
| `options?` | [`ConsumerOptions`](#consumeroptions) |

###### Returns

`AsyncResult`&lt;`string`, [`TechnicalError`](#technicalerror)&gt;

AsyncResult resolving to the consumer tag.

##### getConnection()

```ts
getConnection(): IAmqpConnectionManager;
```

Defined in: [packages/core/src/amqp-client.ts:232](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/amqp-client.ts#L232)

Get the underlying connection manager

This method exposes the AmqpConnectionManager instance that this client uses.
The connection is automatically shared across all AmqpClient instances that
use the same URLs and connection options.

###### Returns

`IAmqpConnectionManager`

The AmqpConnectionManager instance used by this client

##### nack()

```ts
nack(
   msg, 
   allUpTo?, 
   requeue?): void;
```

Defined in: [packages/core/src/amqp-client.ts:454](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/amqp-client.ts#L454)

Negative acknowledge a message.

###### Parameters

| Parameter | Type | Default value | Description |
| ------ | ------ | ------ | ------ |
| `msg` | `ConsumeMessage` | `undefined` | The message to nack |
| `allUpTo` | `boolean` | `false` | If true, nack all messages up to and including this one |
| `requeue` | `boolean` | `true` | If true, requeue the message(s) |

###### Returns

`void`

##### on()

```ts
on(event, listener): void;
```

Defined in: [packages/core/src/amqp-client.ts:480](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/amqp-client.ts#L480)

Register an event listener on the channel wrapper.

Available events:
- 'connect': Emitted when the channel is (re)connected
- 'close': Emitted when the channel is closed
- 'error': Emitted when an error occurs

###### Parameters

| Parameter | Type | Description |
| ------ | ------ | ------ |
| `event` | `string` | The event name |
| `listener` | (...`args`) => `void` | The event listener |

###### Returns

`void`

##### publish()

```ts
publish(
   exchange, 
   routingKey, 
   content, 
   options?): AsyncResult<boolean, TechnicalError>;
```

Defined in: [packages/core/src/amqp-client.ts:288](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/amqp-client.ts#L288)

Publish a message to an exchange.

###### Parameters

| Parameter | Type |
| ------ | ------ |
| `exchange` | `string` |
| `routingKey` | `string` |
| `content` | `unknown` |
| `options?` | `Publish` |

###### Returns

`AsyncResult`&lt;`boolean`, [`TechnicalError`](#technicalerror)&gt;

AsyncResult resolving to `true` if the message was sent, `false` if the channel buffer is full.

##### sendToQueue()

```ts
sendToQueue(
   queue, 
   content, 
   options?): AsyncResult<boolean, TechnicalError>;
```

Defined in: [packages/core/src/amqp-client.ts:309](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/amqp-client.ts#L309)

Publish a message directly to a queue.

###### Parameters

| Parameter | Type |
| ------ | ------ |
| `queue` | `string` |
| `content` | `unknown` |
| `options?` | `Publish` |

###### Returns

`AsyncResult`&lt;`boolean`, [`TechnicalError`](#technicalerror)&gt;

AsyncResult resolving to `true` if the message was sent, `false` if the channel buffer is full.

##### waitForConnect()

```ts
waitForConnect(): AsyncResult<void, TechnicalError>;
```

Defined in: [packages/core/src/amqp-client.ts:250](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/amqp-client.ts#L250)

Wait for the channel to be connected and ready.

If `connectTimeoutMs` was provided in the constructor options, the returned
AsyncResult resolves to `Err(TechnicalError)` once the timeout elapses.
Without a timeout, this waits forever — amqp-connection-manager retries
connections indefinitely and never errors on its own.

NOTE: When using `AmqpClient` directly (not via `TypedAmqpClient` /
`TypedAmqpWorker`), the constructor has already incremented the pooled
connection's reference count. Callers must invoke `close()` on the error
path to release the connection — `waitForConnect` does not do this
automatically. The typed factories handle this cleanup for you.

###### Returns

`AsyncResult`&lt;`void`, [`TechnicalError`](#technicalerror)&gt;

***

### MessageValidationError

Defined in: [packages/core/src/errors.ts:39](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/errors.ts#L39)

Error thrown when message validation fails (payload or headers).

Used by both the client (publish-time payload validation) and the worker
(consume-time payload and headers validation). Carries a `_tag` of
`"@amqp-contract/MessageValidationError"` (namespaced to avoid collisions);
the `Error.name` is kept bare (`"MessageValidationError"`).

#### Param

**source**

The name of the publisher or consumer that triggered the validation

#### Param

**issues**

The validation issues from the Standard Schema validation

#### Extends

- `TaggedErrorInstance`&lt;`"@amqp-contract/MessageValidationError"`, \{
  `issues`: `unknown`;
  `source`: `string`;
\}&gt;

#### Constructors

##### Constructor

```ts
new MessageValidationError(source, issues): MessageValidationError;
```

Defined in: [packages/core/src/errors.ts:45](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/errors.ts#L45)

###### Parameters

| Parameter | Type |
| ------ | ------ |
| `source` | `string` |
| `issues` | `unknown` |

###### Returns

[`MessageValidationError`](#messagevalidationerror)

###### Overrides

```ts
TaggedError("@amqp-contract/MessageValidationError", {
  name: "MessageValidationError",
})<{
  source: string;
  issues: unknown;
}>.constructor
```

#### Properties

| Property | Modifier | Type | Inherited from | Defined in |
| ------ | ------ | ------ | ------ | ------ |
| <a id="_tag"></a> `_tag` | `readonly` | `"@amqp-contract/MessageValidationError"` | `TaggedError("@amqp-contract/MessageValidationError", { name: "MessageValidationError", })._tag` | node\_modules/.pnpm/unthrown@4.1.0/node\_modules/unthrown/dist/index.d.mts:1456 |
| <a id="cause"></a> `cause?` | `public` | `unknown` | `TaggedError("@amqp-contract/MessageValidationError", { name: "MessageValidationError", }).cause` | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es2022.error.d.ts:24 |
| <a id="issues"></a> `issues` | `readonly` | `unknown` | `TaggedError("@amqp-contract/MessageValidationError", { name: "MessageValidationError", }).issues` | [packages/core/src/errors.ts:43](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/errors.ts#L43) |
| <a id="message"></a> `message` | `public` | `string` | `TaggedError("@amqp-contract/MessageValidationError", { name: "MessageValidationError", }).message` | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es5.d.ts:1075 |
| <a id="name"></a> `name` | `public` | `string` | `TaggedError("@amqp-contract/MessageValidationError", { name: "MessageValidationError", }).name` | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es5.d.ts:1074 |
| <a id="source"></a> `source` | `readonly` | `string` | `TaggedError("@amqp-contract/MessageValidationError", { name: "MessageValidationError", }).source` | [packages/core/src/errors.ts:42](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/errors.ts#L42) |
| <a id="stack"></a> `stack?` | `public` | `string` | `TaggedError("@amqp-contract/MessageValidationError", { name: "MessageValidationError", }).stack` | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es5.d.ts:1076 |

***

### RpcError

Defined in: [packages/core/src/errors.ts:92](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/errors.ts#L92)

A typed, contract-declared RPC error — the business-failure channel of an
RPC, as opposed to the transport failures modeled by [TechnicalError](#technicalerror).

Declared per-RPC via `defineRpc(queue, { request, response, errors })`,
where each error code maps to a message definition validating the error's
`data` payload. A worker handler surfaces one by returning
`Err(rpcError(code, data))`; the worker validates `data` against the
declared schema, publishes an error reply, and acks the request (business
errors are not retried). The caller's `client.call(...)` resolves to
`Err(RpcError<code, data>)` with `data` re-validated on arrival.

Carries a `_tag` of `"@amqp-contract/RpcError"` for exhaustive dispatch via
`matchTags`; the `Error.name` is kept bare (`"RpcError"`). Discriminate
between codes on the `code` property.

#### Extends

- `TaggedErrorInstance`&lt;`"@amqp-contract/RpcError"`, \{
  `code`: `string`;
  `data`: `unknown`;
\}&gt;

#### Type Parameters

| Type Parameter | Default type |
| ------ | ------ |
| `TCode` *extends* `string` | `string` |
| `TData` | `unknown` |

#### Constructors

##### Constructor

```ts
new RpcError<TCode, TData>(
   code, 
   data, 
   message?): RpcError<TCode, TData>;
```

Defined in: [packages/core/src/errors.ts:102](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/errors.ts#L102)

###### Parameters

| Parameter | Type |
| ------ | ------ |
| `code` | `TCode` |
| `data` | `TData` |
| `message?` | `string` |

###### Returns

[`RpcError`](#rpcerror)&lt;`TCode`, `TData`&gt;

###### Overrides

```ts
TaggedError(
  "@amqp-contract/RpcError",
  { name: "RpcError" },
)<{
  code: string;
  data: unknown;
}>.constructor
```

#### Properties

| Property | Modifier | Type | Overrides | Inherited from | Defined in |
| ------ | ------ | ------ | ------ | ------ | ------ |
| <a id="_tag-1"></a> `_tag` | `readonly` | `"@amqp-contract/RpcError"` | - | `TaggedError( "@amqp-contract/RpcError", { name: "RpcError" }, )._tag` | node\_modules/.pnpm/unthrown@4.1.0/node\_modules/unthrown/dist/index.d.mts:1456 |
| <a id="cause-1"></a> `cause?` | `public` | `unknown` | - | `TaggedError( "@amqp-contract/RpcError", { name: "RpcError" }, ).cause` | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es2022.error.d.ts:24 |
| <a id="code"></a> `code` | `readonly` | `TCode` | `TaggedError( "@amqp-contract/RpcError", { name: "RpcError" }, ).code` | - | [packages/core/src/errors.ts:99](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/errors.ts#L99) |
| <a id="data"></a> `data` | `readonly` | `TData` | `TaggedError( "@amqp-contract/RpcError", { name: "RpcError" }, ).data` | - | [packages/core/src/errors.ts:100](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/errors.ts#L100) |
| <a id="message-1"></a> `message` | `public` | `string` | - | `TaggedError( "@amqp-contract/RpcError", { name: "RpcError" }, ).message` | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es5.d.ts:1075 |
| <a id="name-1"></a> `name` | `public` | `string` | - | `TaggedError( "@amqp-contract/RpcError", { name: "RpcError" }, ).name` | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es5.d.ts:1074 |
| <a id="stack-1"></a> `stack?` | `public` | `string` | - | `TaggedError( "@amqp-contract/RpcError", { name: "RpcError" }, ).stack` | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es5.d.ts:1076 |

***

### TechnicalError

Defined in: [packages/core/src/errors.ts:17](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/errors.ts#L17)

Error for technical/runtime failures that cannot be prevented by TypeScript.

This includes AMQP connection failures, channel issues, validation failures,
and other runtime errors. This error is shared across core, worker, and client packages.

Built on unthrown's [TaggedError](https://github.com/btravstack/unthrown), so it carries a `_tag` of
`"@amqp-contract/TechnicalError"` for exhaustive dispatch via `matchTags`. The
tag is namespaced to avoid colliding with other libraries' tags in a shared
`matchTags`; the human-facing `Error.name` is kept bare (`"TechnicalError"`).
Remains a real `Error` (and a *modeled* error — it lives in the `E` channel of
a `Result`, never the `Defect` channel).

#### Extends

- `TaggedErrorInstance`&lt;`"@amqp-contract/TechnicalError"`, \{
  `cause?`: `unknown`;
\}&gt;

#### Constructors

##### Constructor

```ts
new TechnicalError(message, cause?): TechnicalError;
```

Defined in: [packages/core/src/errors.ts:22](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/errors.ts#L22)

###### Parameters

| Parameter | Type |
| ------ | ------ |
| `message` | `string` |
| `cause?` | `unknown` |

###### Returns

[`TechnicalError`](#technicalerror)

###### Overrides

```ts
TaggedError("@amqp-contract/TechnicalError", {
  name: "TechnicalError",
})<{
  cause?: unknown;
}>.constructor
```

#### Properties

| Property | Modifier | Type | Inherited from | Defined in |
| ------ | ------ | ------ | ------ | ------ |
| <a id="_tag-2"></a> `_tag` | `readonly` | `"@amqp-contract/TechnicalError"` | `TaggedError("@amqp-contract/TechnicalError", { name: "TechnicalError", })._tag` | node\_modules/.pnpm/unthrown@4.1.0/node\_modules/unthrown/dist/index.d.mts:1456 |
| <a id="cause-2"></a> `cause?` | `public` | `unknown` | [`MessageValidationError`](#messagevalidationerror).[`cause`](#cause) | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es2022.error.d.ts:24 |
| <a id="message-2"></a> `message` | `public` | `string` | `TaggedError("@amqp-contract/TechnicalError", { name: "TechnicalError", }).message` | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es5.d.ts:1075 |
| <a id="name-2"></a> `name` | `public` | `string` | `TaggedError("@amqp-contract/TechnicalError", { name: "TechnicalError", }).name` | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es5.d.ts:1074 |
| <a id="stack-2"></a> `stack?` | `public` | `string` | `TaggedError("@amqp-contract/TechnicalError", { name: "TechnicalError", }).stack` | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es5.d.ts:1076 |

## Type Aliases

### AmqpClientOptions

```ts
type AmqpClientOptions = object;
```

Defined in: [packages/core/src/amqp-client.ts:81](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/amqp-client.ts#L81)

Options for creating an AMQP client.

#### Properties

| Property | Type | Description | Defined in |
| ------ | ------ | ------ | ------ |
| <a id="channeloptions"></a> `channelOptions?` | `Partial`&lt;`CreateChannelOpts`&gt; | Optional channel configuration options. | [packages/core/src/amqp-client.ts:84](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/amqp-client.ts#L84) |
| <a id="connectionoptions"></a> `connectionOptions?` | `AmqpConnectionManagerOptions` | Optional connection configuration (heartbeat, reconnect settings, etc.). | [packages/core/src/amqp-client.ts:83](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/amqp-client.ts#L83) |
| <a id="connecttimeoutms"></a> `connectTimeoutMs?` | `number` \| `null` | Maximum time in ms to wait for the channel to become ready in `waitForConnect`. Defaults to [DEFAULT\_CONNECT\_TIMEOUT\_MS](#default_connect_timeout_ms). Pass `null` to disable the timeout entirely (amqp-connection-manager will retry indefinitely). | [packages/core/src/amqp-client.ts:85](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/amqp-client.ts#L85) |
| <a id="urls"></a> `urls` | `ConnectionUrl`[] | AMQP broker URL(s). Multiple URLs provide failover support. | [packages/core/src/amqp-client.ts:82](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/amqp-client.ts#L82) |

***

### ConsumeCallback

```ts
type ConsumeCallback = (msg) => void | Promise<void>;
```

Defined in: [packages/core/src/amqp-client.ts:91](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/amqp-client.ts#L91)

Callback type for consuming messages.

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `msg` | `ConsumeMessage` \| `null` |

#### Returns

`void` \| `Promise`&lt;`void`&gt;

***

### ConsumerOptions

```ts
type ConsumerOptions = Options.Consume & object;
```

Defined in: [packages/core/src/amqp-client.ts:116](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/amqp-client.ts#L116)

Consume options that extend amqplib's `Options.Consume` with an optional
per-consumer prefetch count.

`prefetch` is intercepted by [AmqpClient.consume](#consume): it is stripped from
the options handed to the underlying `channelWrapper.consume(...)` call
(since amqplib's `Options.Consume` does not include it) and applied via
`channel.prefetch(count, false)` registered through `addSetup` *before* the
consume so the value is in effect when the consumer starts and is reapplied
automatically on channel reconnect.

#### Type Declaration

| Name | Type | Description | Defined in |
| ------ | ------ | ------ | ------ |
| `prefetch?` | `number` | Per-consumer prefetch count. Applied before `channel.consume(...)`. | [packages/core/src/amqp-client.ts:118](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/amqp-client.ts#L118) |

***

### Logger

```ts
type Logger = object;
```

Defined in: [packages/core/src/logger.ts:30](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/logger.ts#L30)

Logger interface for amqp-contract packages.

Provides a simple logging abstraction that can be implemented by users
to integrate with their preferred logging framework.

#### Example

```typescript
// Simple console logger implementation
const logger: Logger = {
  debug: (message, context) => console.debug(message, context),
  info: (message, context) => console.info(message, context),
  warn: (message, context) => console.warn(message, context),
  error: (message, context) => console.error(message, context),
};
```

#### Methods

##### debug()

```ts
debug(message, context?): void;
```

Defined in: [packages/core/src/logger.ts:36](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/logger.ts#L36)

Log debug level messages

###### Parameters

| Parameter | Type | Description |
| ------ | ------ | ------ |
| `message` | `string` | The log message |
| `context?` | [`LoggerContext`](#loggercontext) | Optional context to include with the log |

###### Returns

`void`

##### error()

```ts
error(message, context?): void;
```

Defined in: [packages/core/src/logger.ts:57](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/logger.ts#L57)

Log error level messages

###### Parameters

| Parameter | Type | Description |
| ------ | ------ | ------ |
| `message` | `string` | The log message |
| `context?` | [`LoggerContext`](#loggercontext) | Optional context to include with the log |

###### Returns

`void`

##### info()

```ts
info(message, context?): void;
```

Defined in: [packages/core/src/logger.ts:43](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/logger.ts#L43)

Log info level messages

###### Parameters

| Parameter | Type | Description |
| ------ | ------ | ------ |
| `message` | `string` | The log message |
| `context?` | [`LoggerContext`](#loggercontext) | Optional context to include with the log |

###### Returns

`void`

##### warn()

```ts
warn(message, context?): void;
```

Defined in: [packages/core/src/logger.ts:50](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/logger.ts#L50)

Log warning level messages

###### Parameters

| Parameter | Type | Description |
| ------ | ------ | ------ |
| `message` | `string` | The log message |
| `context?` | [`LoggerContext`](#loggercontext) | Optional context to include with the log |

###### Returns

`void`

***

### LoggerContext

```ts
type LoggerContext = Record<string, unknown> & object;
```

Defined in: [packages/core/src/logger.ts:9](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/logger.ts#L9)

Context object for logger methods.

This type includes reserved keys that provide consistent naming
for common logging context properties.

#### Type Declaration

| Name | Type | Defined in |
| ------ | ------ | ------ |
| `error?` | `unknown` | [packages/core/src/logger.ts:10](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/logger.ts#L10) |

***

### PublishOptions

```ts
type PublishOptions = Options.Publish;
```

Defined in: [packages/core/src/amqp-client.ts:103](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/amqp-client.ts#L103)

Publish options for `AmqpClient.publish` / `AmqpClient.sendToQueue`.

Currently a re-export of amqplib's `Options.Publish`. A previous version of
this type also exposed a `timeout` field, but that field never had a
meaningful AMQP-level effect in this codebase and has been removed to avoid
suggesting behaviour we do not provide. (`amqp-connection-manager`'s own
`publishTimeout` channel option is unrelated and is configured at channel
creation, not per-publish.)

***

### TelemetryProvider

```ts
type TelemetryProvider = object;
```

Defined in: [packages/core/src/telemetry.ts:54](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/telemetry.ts#L54)

Telemetry provider for AMQP operations.
Uses lazy loading to gracefully handle cases where OpenTelemetry is not installed.

#### Properties

| Property | Type | Description | Defined in |
| ------ | ------ | ------ | ------ |
| <a id="getconsumecounter"></a> `getConsumeCounter` | () => `Counter` \| `undefined` | Get a counter for messages consumed. Returns undefined if OpenTelemetry is not available. | [packages/core/src/telemetry.ts:71](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/telemetry.ts#L71) |
| <a id="getconsumelatencyhistogram"></a> `getConsumeLatencyHistogram` | () => `Histogram` \| `undefined` | Get a histogram for consume/process latency. Returns undefined if OpenTelemetry is not available. | [packages/core/src/telemetry.ts:83](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/telemetry.ts#L83) |
| <a id="getlaterpcreplycounter"></a> `getLateRpcReplyCounter` | () => `Counter` \| `undefined` | Get a counter for RPC replies that arrive after the caller has gone away (timeout, cancellation, or unknown correlationId). Returns undefined if OpenTelemetry is not available. | [packages/core/src/telemetry.ts:90](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/telemetry.ts#L90) |
| <a id="getpublishcounter"></a> `getPublishCounter` | () => `Counter` \| `undefined` | Get a counter for messages published. Returns undefined if OpenTelemetry is not available. | [packages/core/src/telemetry.ts:65](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/telemetry.ts#L65) |
| <a id="getpublishlatencyhistogram"></a> `getPublishLatencyHistogram` | () => `Histogram` \| `undefined` | Get a histogram for publish latency. Returns undefined if OpenTelemetry is not available. | [packages/core/src/telemetry.ts:77](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/telemetry.ts#L77) |
| <a id="gettracer"></a> `getTracer` | () => `Tracer` \| `undefined` | Get a tracer instance for creating spans. Returns undefined if OpenTelemetry is not available. | [packages/core/src/telemetry.ts:59](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/telemetry.ts#L59) |

## Variables

### DEFAULT\_CONNECT\_TIMEOUT\_MS

```ts
const DEFAULT_CONNECT_TIMEOUT_MS: 30000 = 30_000;
```

Defined in: [packages/core/src/amqp-client.ts:55](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/amqp-client.ts#L55)

Default time `waitForConnect` will wait for the broker before erroring out.
Defaulting to a finite value (rather than waiting forever) means a fail-fast
developer experience: a misconfigured URL, a down broker, or wrong
credentials surface as an `err` within 30 seconds. Pass `null`
explicitly to disable the timeout — `Infinity` and other non-finite values
are also coerced to "no timeout" because Node's `setTimeout` clamps large
delays to ~24.8 days and silently fires near-immediately on `Infinity`.

***

### defaultTelemetryProvider

```ts
const defaultTelemetryProvider: TelemetryProvider;
```

Defined in: [packages/core/src/telemetry.ts:229](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/telemetry.ts#L229)

Default telemetry provider that uses OpenTelemetry API if available.

***

### MessagingSemanticConventions

```ts
const MessagingSemanticConventions: object;
```

Defined in: [packages/core/src/telemetry.ts:26](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/telemetry.ts#L26)

Semantic conventions for AMQP messaging following OpenTelemetry standards.

#### Type Declaration

| Name | Type | Default value | Defined in |
| ------ | ------ | ------ | ------ |
| <a id="property-amqp_consumer_name"></a> `AMQP_CONSUMER_NAME` | `"amqp.consumer.name"` | `"amqp.consumer.name"` | [packages/core/src/telemetry.ts:37](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/telemetry.ts#L37) |
| <a id="property-amqp_publisher_name"></a> `AMQP_PUBLISHER_NAME` | `"amqp.publisher.name"` | `"amqp.publisher.name"` | [packages/core/src/telemetry.ts:36](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/telemetry.ts#L36) |
| <a id="property-error_type"></a> `ERROR_TYPE` | `"error.type"` | `"error.type"` | [packages/core/src/telemetry.ts:40](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/telemetry.ts#L40) |
| <a id="property-messaging_destination"></a> `MESSAGING_DESTINATION` | `"messaging.destination.name"` | `"messaging.destination.name"` | [packages/core/src/telemetry.ts:29](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/telemetry.ts#L29) |
| <a id="property-messaging_destination_kind"></a> `MESSAGING_DESTINATION_KIND` | `"messaging.destination.kind"` | `"messaging.destination.kind"` | [packages/core/src/telemetry.ts:30](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/telemetry.ts#L30) |
| <a id="property-messaging_destination_kind_exchange"></a> `MESSAGING_DESTINATION_KIND_EXCHANGE` | `"exchange"` | `"exchange"` | [packages/core/src/telemetry.ts:44](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/telemetry.ts#L44) |
| <a id="property-messaging_destination_kind_queue"></a> `MESSAGING_DESTINATION_KIND_QUEUE` | `"queue"` | `"queue"` | [packages/core/src/telemetry.ts:45](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/telemetry.ts#L45) |
| <a id="property-messaging_operation"></a> `MESSAGING_OPERATION` | `"messaging.operation"` | `"messaging.operation"` | [packages/core/src/telemetry.ts:31](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/telemetry.ts#L31) |
| <a id="property-messaging_operation_process"></a> `MESSAGING_OPERATION_PROCESS` | `"process"` | `"process"` | [packages/core/src/telemetry.ts:47](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/telemetry.ts#L47) |
| <a id="property-messaging_operation_publish"></a> `MESSAGING_OPERATION_PUBLISH` | `"publish"` | `"publish"` | [packages/core/src/telemetry.ts:46](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/telemetry.ts#L46) |
| <a id="property-messaging_rabbitmq_message_delivery_tag"></a> `MESSAGING_RABBITMQ_MESSAGE_DELIVERY_TAG` | `"messaging.rabbitmq.message.delivery_tag"` | `"messaging.rabbitmq.message.delivery_tag"` | [packages/core/src/telemetry.ts:35](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/telemetry.ts#L35) |
| <a id="property-messaging_rabbitmq_routing_key"></a> `MESSAGING_RABBITMQ_ROUTING_KEY` | `"messaging.rabbitmq.destination.routing_key"` | `"messaging.rabbitmq.destination.routing_key"` | [packages/core/src/telemetry.ts:34](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/telemetry.ts#L34) |
| <a id="property-messaging_system"></a> `MESSAGING_SYSTEM` | `"messaging.system"` | `"messaging.system"` | [packages/core/src/telemetry.ts:28](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/telemetry.ts#L28) |
| <a id="property-messaging_system_rabbitmq"></a> `MESSAGING_SYSTEM_RABBITMQ` | `"rabbitmq"` | `"rabbitmq"` | [packages/core/src/telemetry.ts:43](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/telemetry.ts#L43) |

#### See

https://opentelemetry.io/docs/specs/semconv/messaging/messaging-spans/

***

### RPC\_ERROR\_CODE\_HEADER

```ts
const RPC_ERROR_CODE_HEADER: "x-amqp-contract-error-code" = "x-amqp-contract-error-code";
```

Defined in: [packages/core/src/errors.ts:74](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/errors.ts#L74)

AMQP message header carrying the error code of a typed RPC error reply.

A reply message with this header is an error reply: its body is
`{ message, data }` where `data` conforms to the error's declared schema in
the RPC's `errors` map. A reply without it is a regular success reply whose
body is the response payload — so success replies are wire-compatible with
contracts that declare no errors.

## Functions

### ~~\_getConnectionCountForTesting()~~

```ts
function _getConnectionCountForTesting(): number;
```

Defined in: [packages/core/src/connection-manager.ts:206](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/connection-manager.ts#L206)

#### Returns

`number`

#### Deprecated

Renamed to \_internal\_getConnectionCount per the org `_internal_` convention.

***

### ~~\_resetConnectionsForTesting()~~

```ts
function _resetConnectionsForTesting(): Promise<void>;
```

Defined in: [packages/core/src/connection-manager.ts:220](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/connection-manager.ts#L220)

#### Returns

`Promise`&lt;`void`&gt;

#### Deprecated

Renamed to \_internal\_resetConnections per the org `_internal_` convention.

***

### ~~\_resetTelemetryCacheForTesting()~~

```ts
function _resetTelemetryCacheForTesting(): void;
```

Defined in: [packages/core/src/telemetry.ts:429](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/telemetry.ts#L429)

#### Returns

`void`

#### Deprecated

Renamed to \_internal\_resetTelemetryCache per the org `_internal_` convention.

***

### endSpanError()

```ts
function endSpanError(span, error): void;
```

Defined in: [packages/core/src/telemetry.ts:324](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/telemetry.ts#L324)

End a span with error status.

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `span` | `Span` \| `undefined` |
| `error` | `Error` |

#### Returns

`void`

***

### endSpanSuccess()

```ts
function endSpanSuccess(span): void;
```

Defined in: [packages/core/src/telemetry.ts:309](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/telemetry.ts#L309)

End a span with success status.

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `span` | `Span` \| `undefined` |

#### Returns

`void`

***

### isRpcError()

```ts
function isRpcError(error): error is RpcError<string, unknown>;
```

Defined in: [packages/core/src/errors.ts:114](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/errors.ts#L114)

Type guard to check if an error is an [RpcError](#rpcerror).

Narrowing to a specific code (and thus a typed `data`) is done on the
`code` property after the guard, or via `matchTags` on the `_tag`.

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `error` | `unknown` |

#### Returns

`error is RpcError<string, unknown>`

***

### recordConsumeMetric()

```ts
function recordConsumeMetric(
   provider, 
   queueName, 
   consumerName, 
   success, 
   durationMs): void;
```

Defined in: [packages/core/src/telemetry.ts:368](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/telemetry.ts#L368)

Record a consume metric.

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `provider` | [`TelemetryProvider`](#telemetryprovider) |
| `queueName` | `string` |
| `consumerName` | `string` |
| `success` | `boolean` |
| `durationMs` | `number` |

#### Returns

`void`

***

### recordLateRpcReply()

```ts
function recordLateRpcReply(provider, reason): void;
```

Defined in: [packages/core/src/telemetry.ts:398](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/telemetry.ts#L398)

Record an RPC reply that arrived after the caller stopped waiting.

#### Parameters

| Parameter | Type | Description |
| ------ | ------ | ------ |
| `provider` | [`TelemetryProvider`](#telemetryprovider) | - |
| `reason` | `"unknown-correlation-id"` \| `"missing-correlation-id"` | Why the reply was orphaned. `"unknown-correlation-id"` is the typical "caller already timed out" case; `"missing-correlation-id"` means the broker delivered a reply with no correlationId at all (a protocol violation by the responder). |

#### Returns

`void`

***

### recordPublishMetric()

```ts
function recordPublishMetric(
   provider, 
   exchangeName, 
   routingKey, 
   success, 
   durationMs): void;
```

Defined in: [packages/core/src/telemetry.ts:341](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/telemetry.ts#L341)

Record a publish metric.

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `provider` | [`TelemetryProvider`](#telemetryprovider) |
| `exchangeName` | `string` |
| `routingKey` | `string` \| `undefined` |
| `success` | `boolean` |
| `durationMs` | `number` |

#### Returns

`void`

***

### rpcError()

```ts
function rpcError<TCode, TData>(
   code, 
   data, 
   message?): RpcError<TCode, TData>;
```

Defined in: [packages/core/src/errors.ts:143](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/errors.ts#L143)

Create an [RpcError](#rpcerror) with less verbosity.

The code/data pair must match one of the entries declared in the RPC's
`errors` map — the handler's return type enforces this at compile time, and
the worker validates `data` against the declared schema at runtime before
replying.

#### Type Parameters

| Type Parameter |
| ------ |
| `TCode` *extends* `string` |
| `TData` |

#### Parameters

| Parameter | Type | Description |
| ------ | ------ | ------ |
| `code` | `TCode` | The error code, as declared in the RPC's `errors` map |
| `data` | `TData` | The error data, validated against the declared schema |
| `message?` | `string` | Optional human-readable message (defaults to a generic one) |

#### Returns

[`RpcError`](#rpcerror)&lt;`TCode`, `TData`&gt;

#### Example

```typescript
import { rpcError } from '@amqp-contract/worker';
import { ErrAsync } from 'unthrown';

const handler = ({ payload }) => {
  if (!orders.has(payload.orderId)) {
    return ErrAsync(rpcError('ORDER_NOT_FOUND', { orderId: payload.orderId }));
  }
  // ...
};
```

***

### safeJsonParse()

```ts
function safeJsonParse<E>(buffer, errorFn): Result<unknown, E>;
```

Defined in: [packages/core/src/parsing.ts:24](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/parsing.ts#L24)

Parse a `Buffer` as JSON, mapping any `JSON.parse` exception to the
caller-supplied error type.

Use this in consume / reply paths where a parse failure is a typed value,
not a thrown exception — the caller decides how to translate the raw error
into a domain-level error (e.g. [TechnicalError](#technicalerror)).

#### Type Parameters

| Type Parameter | Description |
| ------ | ------ |
| `E` | The error type produced by `errorFn`. |

#### Parameters

| Parameter | Type | Description |
| ------ | ------ | ------ |
| `buffer` | `Buffer` | The raw message body to parse. |
| `errorFn` | (`raw`) => `E` | Callback invoked with the underlying `JSON.parse` error. |

#### Returns

`Result`&lt;`unknown`, `E`&gt;

A `Result` containing the parsed `unknown` value or the mapped error.

#### Example

```typescript
const parsed = safeJsonParse(
  msg.content,
  (error) => new TechnicalError("Failed to parse JSON", error),
);
```

***

### setupAmqpTopology()

```ts
function setupAmqpTopology(channel, contract): Promise<void>;
```

Defined in: [packages/core/src/setup.ts:26](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/setup.ts#L26)

Setup AMQP topology (exchanges, queues, and bindings) from a contract definition.

This function sets up the complete AMQP topology in the correct order:
1. Assert all exchanges defined in the contract
2. Validate dead letter exchanges are declared before referencing them
3. Assert all queues with their configurations (including dead letter settings)
4. Create all bindings (queue-to-exchange and exchange-to-exchange)

#### Parameters

| Parameter | Type | Description |
| ------ | ------ | ------ |
| `channel` | `Channel` | The AMQP channel to use for topology setup |
| `contract` | `ContractDefinition` | The contract definition containing the topology specification |

#### Returns

`Promise`&lt;`void`&gt;

#### Throws

If any exchanges, queues, or bindings fail to be created

#### Throws

If a queue references a dead letter exchange not declared in the contract

#### Example

```typescript
const channel = await connection.createChannel();
await setupAmqpTopology(channel, contract);
```

***

### startConsumeSpan()

```ts
function startConsumeSpan(
   provider, 
   queueName, 
   consumerName, 
   attributes?): Span | undefined;
```

Defined in: [packages/core/src/telemetry.ts:277](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/telemetry.ts#L277)

Create a span for a consume/process operation.
Returns undefined if OpenTelemetry is not available.

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `provider` | [`TelemetryProvider`](#telemetryprovider) |
| `queueName` | `string` |
| `consumerName` | `string` |
| `attributes?` | `Attributes` |

#### Returns

`Span` \| `undefined`

***

### startPublishSpan()

```ts
function startPublishSpan(
   provider, 
   exchangeName, 
   routingKey, 
   attributes?): Span | undefined;
```

Defined in: [packages/core/src/telemetry.ts:242](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/core/src/telemetry.ts#L242)

Create a span for a publish operation.
Returns undefined if OpenTelemetry is not available.

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `provider` | [`TelemetryProvider`](#telemetryprovider) |
| `exchangeName` | `string` |
| `routingKey` | `string` \| `undefined` |
| `attributes?` | `Attributes` |

#### Returns

`Span` \| `undefined`
