**@amqp-contract/contract**

***

# @amqp-contract/contract

## Type Aliases

### AnySchema

```ts
type AnySchema = StandardSchemaV1;
```

Defined in: [types.ts:12](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L12)

Any schema that conforms to Standard Schema v1.

This library supports any validation library that implements the Standard Schema v1 specification,
including Zod, Valibot, and ArkType. This allows you to use your preferred validation library
while maintaining type safety.

#### See

https://github.com/standard-schema/standard-schema

***

### BaseExchangeDefinition

```ts
type BaseExchangeDefinition<TName> = object;
```

Defined in: [types.ts:394](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L394)

Base definition of an AMQP exchange.

An exchange receives messages from publishers and routes them to queues based on the exchange
type and routing rules. This type contains properties common to all exchange types.

#### Type Parameters

| Type Parameter | Default type |
| ------ | ------ |
| `TName` *extends* `string` | `string` |

#### Properties

| Property | Type | Description | Defined in |
| ------ | ------ | ------ | ------ |
| <a id="arguments"></a> `arguments?` | `Record`&lt;`string`, `unknown`&gt; | Additional AMQP arguments for advanced configuration. Common arguments include alternate-exchange for handling unroutable messages. | [types.ts:421](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L421) |
| <a id="autodelete"></a> `autoDelete?` | `boolean` | If true, the exchange is deleted when all queues have finished using it. | [types.ts:409](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L409) |
| <a id="durable"></a> `durable?` | `boolean` | If true, the exchange survives broker restarts. Durable exchanges are persisted to disk. **Default** `true` | [types.ts:404](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L404) |
| <a id="internal"></a> `internal?` | `boolean` | If true, the exchange cannot be directly published to by clients. It can only receive messages from other exchanges via exchange-to-exchange bindings. | [types.ts:415](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L415) |
| <a id="name"></a> `name` | `TName` | The name of the exchange. Must be unique within the RabbitMQ virtual host. | [types.ts:398](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L398) |

***

### BindingDefinition

```ts
type BindingDefinition = 
  | QueueBindingDefinition
  | ExchangeBindingDefinition;
```

Defined in: [types.ts:891](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L891)

Union type of all binding definitions.

A binding can be either:
- Queue-to-exchange binding: Routes messages from an exchange to a queue
- Exchange-to-exchange binding: Forwards messages from one exchange to another

***

### BindingPattern

```ts
type BindingPattern<S> = S extends "" ? never : S;
```

Defined in: [builder/routing-types.ts:52](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/builder/routing-types.ts#L52)

Type-safe binding pattern that validates basic format and wildcards.

Validates that a binding pattern follows basic AMQP binding pattern rules:
- Can contain wildcards (* for one word, # for zero or more words)
- Must not be empty
- Should contain alphanumeric characters, dots, hyphens, underscores, and wildcards

Note: Full character-by-character validation is not performed to avoid TypeScript
recursion depth limits. Runtime validation is still recommended.

#### Type Parameters

| Type Parameter | Description |
| ------ | ------ |
| `S` *extends* `string` | The binding pattern string to validate |

#### Example

```typescript
type ValidPattern = BindingPattern<"order.*">; // "order.*"
type ValidHash = BindingPattern<"order.#">; // "order.#"
type ValidConcrete = BindingPattern<"order.created">; // "order.created"
type Invalid = BindingPattern<"">; // never (empty string)
```

***

### BridgedPublisherConfig

```ts
type BridgedPublisherConfig<TMessage, TBridgeExchange, TTargetExchange> = object;
```

Defined in: [builder/command.ts:61](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/builder/command.ts#L61)

Configuration for a bridged command publisher.

A bridged publisher publishes to a bridge exchange (local domain), which forwards
messages to the target exchange (remote domain) via an exchange-to-exchange binding.

#### Type Parameters

| Type Parameter | Description |
| ------ | ------ |
| `TMessage` *extends* [`MessageDefinition`](#messagedefinition) | The message definition |
| `TBridgeExchange` *extends* [`ExchangeDefinition`](#exchangedefinition) | The bridge (local domain) exchange definition |
| `TTargetExchange` *extends* [`ExchangeDefinition`](#exchangedefinition) | The target (remote domain) exchange definition |

#### Properties

| Property | Type | Description | Defined in |
| ------ | ------ | ------ | ------ |
| <a id="__brand"></a> `__brand` | `"BridgedPublisherConfig"` | Discriminator to identify this as a bridged publisher config | [builder/command.ts:67](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/builder/command.ts#L67) |
| <a id="bridgeexchange"></a> `bridgeExchange` | `TBridgeExchange` | The bridge (local domain) exchange | [builder/command.ts:73](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/builder/command.ts#L73) |
| <a id="exchangebinding"></a> `exchangeBinding` | [`ExchangeBindingDefinition`](#exchangebindingdefinition) | The exchange-to-exchange binding (bridge → target) | [builder/command.ts:71](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/builder/command.ts#L71) |
| <a id="publisher"></a> `publisher` | [`PublisherDefinition`](#publisherdefinition)&lt;`TMessage`&gt; | The publisher definition (publishes to bridge exchange) | [builder/command.ts:69](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/builder/command.ts#L69) |
| <a id="targetexchange"></a> `targetExchange` | `TTargetExchange` | The target (remote domain) exchange | [builder/command.ts:75](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/builder/command.ts#L75) |

***

### BridgedPublisherConfigBase

```ts
type BridgedPublisherConfigBase = object;
```

Defined in: [types.ts:1024](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L1024)

Base type for bridged publisher configuration.

A bridged publisher publishes to a bridge exchange, which forwards messages
to the target exchange via an exchange-to-exchange binding.

#### See

defineCommandPublisher with bridgeExchange option

#### Properties

| Property | Type | Defined in |
| ------ | ------ | ------ |
| <a id="__brand-1"></a> `__brand` | `"BridgedPublisherConfig"` | [types.ts:1025](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L1025) |
| <a id="bridgeexchange-1"></a> `bridgeExchange` | [`ExchangeDefinition`](#exchangedefinition) | [types.ts:1028](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L1028) |
| <a id="exchangebinding-1"></a> `exchangeBinding` | [`ExchangeBindingDefinition`](#exchangebindingdefinition) | [types.ts:1027](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L1027) |
| <a id="publisher-1"></a> `publisher` | [`PublisherDefinition`](#publisherdefinition) | [types.ts:1026](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L1026) |
| <a id="targetexchange-1"></a> `targetExchange` | [`ExchangeDefinition`](#exchangedefinition) | [types.ts:1029](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L1029) |

***

### ClassicQueueDefinition

```ts
type ClassicQueueDefinition<TName> = BaseQueueDefinition<TName> & object;
```

Defined in: [types.ts:608](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L608)

Definition of a classic queue.

Classic queues are the traditional RabbitMQ queue type. Use them when you need
specific features not supported by quorum queues (e.g., exclusive queues, auto-deleting queues, priority queues).

#### Type Declaration

| Name | Type | Description | Defined in |
| ------ | ------ | ------ | ------ |
| `autoDelete?` | `boolean` | If true, the queue is deleted when the last consumer unsubscribes. | [types.ts:628](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L628) |
| `durable` | `boolean` | If true, the queue survives broker restarts. Durable queues are persisted to disk. | [types.ts:617](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L617) |
| `exclusive?` | `boolean` | If true, the queue can only be used by the declaring connection and is deleted when that connection closes. Exclusive queues are private to the connection. | [types.ts:623](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L623) |
| `maxPriority?` | `number` | Maximum priority level for priority queue (1-255, recommended: 1-10). Sets x-max-priority argument. | [types.ts:634](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L634) |
| `type` | `"classic"` | Queue type discriminator: classic queue. | [types.ts:612](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L612) |

#### Type Parameters

| Type Parameter | Default type |
| ------ | ------ |
| `TName` *extends* `string` | `string` |

***

### ClassicQueueOptions

```ts
type ClassicQueueOptions = BaseQueueOptions & object;
```

Defined in: [types.ts:342](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L342)

Options for creating a classic queue.

Classic queues support all traditional RabbitMQ features including:
- `exclusive` - For connection-scoped queues
- `autoDelete` - For auto-deleting queues when consumers disconnect
- `maxPriority` - For priority queues
- `durable: false` - For non-durable queues

#### Type Declaration

| Name | Type | Description | Defined in |
| ------ | ------ | ------ | ------ |
| `autoDelete?` | `boolean` | If true, the queue is deleted when the last consumer unsubscribes. | [types.ts:363](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L363) |
| `durable?` | `boolean` | If true, the queue survives broker restarts. Durable queues are persisted to disk. **Default** `true` | [types.ts:352](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L352) |
| `exclusive?` | `boolean` | If true, the queue can only be used by the declaring connection and is deleted when that connection closes. Exclusive queues are private to the connection. | [types.ts:358](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L358) |
| `maxPriority?` | `number` | Maximum priority level for priority queue (1-255, recommended: 1-10). Sets x-max-priority argument. | [types.ts:369](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L369) |
| `type` | `"classic"` | Queue type: classic (for special cases) | [types.ts:346](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L346) |

#### Example

```typescript
const priorityQueue = defineQueue('tasks', {
  type: 'classic',
  maxPriority: 10,
});
```

***

### CommandConsumerConfig

```ts
type CommandConsumerConfig<TMessage, TExchange, TRoutingKey, TQueue> = object;
```

Defined in: [builder/command.ts:29](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/builder/command.ts#L29)

Configuration for a command consumer.

Commands are sent by one or more publishers to a single consumer (task queue pattern).
The consumer "owns" the queue, and publishers send commands to it.

#### Type Parameters

| Type Parameter | Default type | Description |
| ------ | ------ | ------ |
| `TMessage` *extends* [`MessageDefinition`](#messagedefinition) | - | The message definition |
| `TExchange` *extends* [`ExchangeDefinition`](#exchangedefinition) | - | The exchange definition |
| `TRoutingKey` *extends* `string` \| `undefined` | `undefined` | The routing key type (undefined for fanout and headers exchanges) |
| `TQueue` *extends* [`QueueEntry`](#queueentry) | [`QueueEntry`](#queueentry) | - |

#### Properties

| Property | Type | Description | Defined in |
| ------ | ------ | ------ | ------ |
| <a id="__brand-2"></a> `__brand` | `"CommandConsumerConfig"` | Discriminator to identify this as a command consumer config | [builder/command.ts:36](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/builder/command.ts#L36) |
| <a id="binding"></a> `binding` | [`QueueBindingDefinition`](#queuebindingdefinition) | The binding connecting the queue to the exchange | [builder/command.ts:40](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/builder/command.ts#L40) |
| <a id="consumer"></a> `consumer` | [`ConsumerDefinition`](#consumerdefinition)&lt;`TMessage`&gt; | The consumer definition for processing commands | [builder/command.ts:38](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/builder/command.ts#L38) |
| <a id="exchange"></a> `exchange` | `TExchange` | The exchange that receives commands | [builder/command.ts:42](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/builder/command.ts#L42) |
| <a id="message"></a> `message` | `TMessage` | The message definition | [builder/command.ts:46](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/builder/command.ts#L46) |
| <a id="queue"></a> `queue` | `TQueue` | The queue this consumer reads from | [builder/command.ts:44](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/builder/command.ts#L44) |
| <a id="routingkey"></a> `routingKey` | `TRoutingKey` | The routing key pattern for the binding | [builder/command.ts:48](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/builder/command.ts#L48) |

***

### CommandConsumerConfigBase

```ts
type CommandConsumerConfigBase = object;
```

Defined in: [types.ts:988](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L988)

Base type for command consumer configuration.

This is a simplified type used in ContractDefinition. The full generic type
is defined in the builder module.

#### See

defineCommandConsumer for creating command consumers

#### Properties

| Property | Type | Defined in |
| ------ | ------ | ------ |
| <a id="__brand-3"></a> `__brand` | `"CommandConsumerConfig"` | [types.ts:989](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L989) |
| <a id="binding-1"></a> `binding` | [`QueueBindingDefinition`](#queuebindingdefinition) | [types.ts:991](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L991) |
| <a id="consumer-1"></a> `consumer` | [`ConsumerDefinition`](#consumerdefinition) | [types.ts:990](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L990) |
| <a id="exchange-1"></a> `exchange` | [`ExchangeDefinition`](#exchangedefinition) | [types.ts:992](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L992) |
| <a id="message-1"></a> `message` | [`MessageDefinition`](#messagedefinition) | [types.ts:994](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L994) |
| <a id="queue-1"></a> `queue` | [`QueueEntry`](#queueentry) | [types.ts:993](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L993) |
| <a id="routingkey-1"></a> `routingKey` | `string` \| `undefined` | [types.ts:995](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L995) |

***

### CompressionAlgorithm

```ts
type CompressionAlgorithm = "gzip" | "deflate";
```

Defined in: [types.ts:199](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L199)

Supported compression algorithms for message payloads.

- `gzip`: GZIP compression (standard, widely supported, good compression ratio)
- `deflate`: DEFLATE compression (faster than gzip, slightly less compression)

Compression is configured at runtime via PublishOptions when calling
AmqpClient.publish, not at publisher definition time.

When compression is enabled, the message payload is compressed before publishing
and automatically decompressed when consuming. The `content-encoding` AMQP
message property is set to indicate the compression algorithm used.

To disable compression, simply omit the `compression` option (it's optional).

#### Example

```typescript
// Define a publisher without compression configuration
const orderCreatedPublisher = definePublisher(exchange, message, {
  routingKey: "order.created",
});

// Later, choose whether to compress at publish time
await client.publish("orderCreated", payload, {
  compression: "gzip",
});
```

***

### ConsumerDefinition

```ts
type ConsumerDefinition<TMessage> = object;
```

Defined in: [types.ts:952](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L952)

Definition of a message consumer.

A consumer receives and processes messages from a queue with automatic schema validation.
The message payload is validated against the schema before being passed to your handler.
If the message is compressed (indicated by the content-encoding header), it will be
automatically decompressed before validation.

#### Example

```typescript
const consumer: ConsumerDefinition = {
  queue: orderProcessingQueue,
  message: orderMessage
};
```

#### Type Parameters

| Type Parameter | Default type | Description |
| ------ | ------ | ------ |
| `TMessage` *extends* [`MessageDefinition`](#messagedefinition) | [`MessageDefinition`](#messagedefinition) | The message definition with payload schema |

#### Properties

| Property | Type | Description | Defined in |
| ------ | ------ | ------ | ------ |
| <a id="message-2"></a> `message` | `TMessage` | The message definition including the payload schema | [types.ts:957](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L957) |
| <a id="queue-2"></a> `queue` | [`QueueEntry`](#queueentry) | The queue to consume messages from | [types.ts:954](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L954) |

***

### ConsumerEntry

```ts
type ConsumerEntry = 
  | ConsumerDefinition
  | EventConsumerResultBase
  | CommandConsumerConfigBase;
```

Defined in: [types.ts:1184](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L1184)

Consumer entry that can be passed to defineContract's consumers section.

Can be either:
- A plain ConsumerDefinition from defineConsumer
- An EventConsumerResult from defineEventConsumer (binding auto-extracted)
- A CommandConsumerConfig from defineCommandConsumer (binding auto-extracted)

***

### ContractDefinition

```ts
type ContractDefinition = object;
```

Defined in: [types.ts:1115](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L1115)

Complete AMQP contract definition (output type).

A contract brings together all AMQP resources into a single, type-safe definition.
It defines the complete messaging topology including exchanges, queues, bindings,
publishers, and consumers.

The contract is used by:
- Clients (TypedAmqpClient) for type-safe message publishing
- Workers (TypedAmqpWorker) for type-safe message consumption
- AsyncAPI generator for documentation

#### Example

```typescript
const contract: ContractDefinition = {
  exchanges: {
    orders: ordersExchange,
  },
  queues: {
    orderProcessing: orderProcessingQueue,
  },
  bindings: {
    orderBinding: orderQueueBinding,
  },
  publishers: {
    orderCreated: orderCreatedPublisher,
  },
  consumers: {
    processOrder: processOrderConsumer,
  },
};
```

#### Properties

| Property | Type | Description | Defined in |
| ------ | ------ | ------ | ------ |
| <a id="bindings"></a> `bindings?` | `Record`&lt;`string`, [`BindingDefinition`](#bindingdefinition)&gt; | Named binding definitions. Bindings can be queue-to-exchange or exchange-to-exchange. | [types.ts:1135](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L1135) |
| <a id="consumers"></a> `consumers?` | `Record`&lt;`string`, [`ConsumerDefinition`](#consumerdefinition)&gt; | Named consumer definitions. Each key requires a corresponding handler in the TypedAmqpWorker. The handler will be fully typed based on the message schema. | [types.ts:1149](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L1149) |
| <a id="exchanges"></a> `exchanges?` | `Record`&lt;`string`, [`ExchangeDefinition`](#exchangedefinition)&gt; | Named exchange definitions. Each key becomes available as a named resource in the contract. | [types.ts:1120](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L1120) |
| <a id="publishers"></a> `publishers?` | `Record`&lt;`string`, [`PublisherDefinition`](#publisherdefinition)&gt; | Named publisher definitions. Each key becomes a method on the TypedAmqpClient for publishing messages. The method will be fully typed based on the message schema. | [types.ts:1142](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L1142) |
| <a id="queues"></a> `queues?` | `Record`&lt;`string`, [`QueueEntry`](#queueentry)&gt; | Named queue definitions. Each key becomes available as a named resource in the contract. When a queue has TTL-backoff retry configured, pass the `QueueWithTtlBackoffInfrastructure` object returned by `defineQueue`. The wait queue, exchanges, and bindings will be automatically added. | [types.ts:1129](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L1129) |
| <a id="rpcs"></a> `rpcs?` | `Record`&lt;`string`, [`RpcDefinition`](#rpcdefinition)&gt; | Named RPC definitions. Each key gets: - A handler in the TypedAmqpWorker that returns the typed response. - A `client.call(name, request, options)` method on the TypedAmqpClient. RPC entries do not appear in `publishers` or `consumers` because each end of an RPC plays both roles (publisher of one direction, consumer of the other). | [types.ts:1160](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L1160) |

***

### ContractDefinitionInput

```ts
type ContractDefinitionInput = object;
```

Defined in: [types.ts:1213](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L1213)

Contract definition input type with automatic extraction of event/command patterns.

Users only define publishers and consumers. Exchanges, queues, and bindings are
automatically extracted from these definitions.

#### Example

```typescript
const contract = defineContract({
  publishers: {
    // EventPublisherConfig → auto-extracted to publisher
    orderCreated: defineEventPublisher(ordersExchange, orderMessage, { routingKey: "order.created" }),
  },
  consumers: {
    // CommandConsumerConfig → auto-extracted to consumer + binding
    processOrder: defineCommandConsumer(orderQueue, ordersExchange, orderMessage, { routingKey: "order.process" }),
    // EventConsumerResult → auto-extracted to consumer + binding
    notify: defineEventConsumer(orderCreatedEvent, notificationQueue),
  },
});
```

#### See

defineContract - Processes this input and returns a ContractDefinition

#### Properties

| Property | Type | Description | Defined in |
| ------ | ------ | ------ | ------ |
| <a id="consumers-1"></a> `consumers?` | `Record`&lt;`string`, [`ConsumerEntry`](#consumerentry)&gt; | Named consumer definitions. Can accept: - ConsumerDefinition from defineConsumer - EventConsumerResult from defineEventConsumer (binding auto-extracted) - CommandConsumerConfig from defineCommandConsumer (binding auto-extracted) | [types.ts:1231](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L1231) |
| <a id="publishers-1"></a> `publishers?` | `Record`&lt;`string`, [`PublisherEntry`](#publisherentry)&gt; | Named publisher definitions. Can accept: - PublisherDefinition from definePublisher - EventPublisherConfig from defineEventPublisher (auto-extracted to publisher) | [types.ts:1221](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L1221) |
| <a id="rpcs-1"></a> `rpcs?` | `Record`&lt;`string`, [`RpcDefinition`](#rpcdefinition)&gt; | Named RPC definitions from `defineRpc`. Each entry contributes its queue (and DLX if any) to the contract topology and exposes a typed `client.call(name, ...)` / worker handler pair. | [types.ts:1238](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L1238) |

***

### ContractOutput

```ts
type ContractOutput<TContract> = object;
```

Defined in: [types.ts:1555](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L1555)

Contract output type with all resources extracted and properly typed.

This type represents the fully expanded contract with:
- exchanges: Extracted from publishers and consumer bindings
- queues: Extracted from consumers
- bindings: Extracted from event/command consumers
- publishers: Normalized publisher definitions
- consumers: Normalized consumer definitions

#### Type Parameters

| Type Parameter |
| ------ |
| `TContract` *extends* [`ContractDefinitionInput`](#contractdefinitioninput) |

#### Properties

| Property | Type | Defined in |
| ------ | ------ | ------ |
| <a id="bindings-1"></a> `bindings` | `TContract`\[`"consumers"`\] *extends* `Record`&lt;`string`, [`ConsumerEntry`](#consumerentry)&gt; ? `ExtractBindingsFromConsumers`&lt;`TContract`\[`"consumers"`\]&gt; : `object` & `TContract`\[`"consumers"`\] *extends* `Record`&lt;`string`, [`ConsumerEntry`](#consumerentry)&gt; ? `ExtractExchangeBindingsFromConsumers`&lt;`TContract`\[`"consumers"`\]&gt; : `object` & `TContract`\[`"publishers"`\] *extends* `Record`&lt;`string`, [`PublisherEntry`](#publisherentry)&gt; ? `ExtractExchangeBindingsFromPublishers`&lt;`TContract`\[`"publishers"`\]&gt; : `object` | [types.ts:1580](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L1580) |
| <a id="consumers-2"></a> `consumers` | `TContract`\[`"consumers"`\] *extends* `Record`&lt;`string`, [`ConsumerEntry`](#consumerentry)&gt; ? `ExtractConsumerDefinitions`&lt;`TContract`\[`"consumers"`\]&gt; : `object` | [types.ts:1592](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L1592) |
| <a id="exchanges-1"></a> `exchanges` | `TContract`\[`"publishers"`\] *extends* `Record`&lt;`string`, [`PublisherEntry`](#publisherentry)&gt; ? `ExtractExchangesFromPublishers`&lt;`TContract`\[`"publishers"`\]&gt; : `object` & `TContract`\[`"consumers"`\] *extends* `Record`&lt;`string`, [`ConsumerEntry`](#consumerentry)&gt; ? `ExtractExchangesFromConsumers`&lt;`TContract`\[`"consumers"`\]&gt; : `object` & `TContract`\[`"consumers"`\] *extends* `Record`&lt;`string`, [`ConsumerEntry`](#consumerentry)&gt; ? `ExtractDeadLetterExchangesFromConsumers`&lt;`TContract`\[`"consumers"`\]&gt; : `object` & `TContract`\[`"consumers"`\] *extends* `Record`&lt;`string`, [`ConsumerEntry`](#consumerentry)&gt; ? `ExtractBridgeExchangesFromConsumers`&lt;`TContract`\[`"consumers"`\]&gt; : `object` & `TContract`\[`"publishers"`\] *extends* `Record`&lt;`string`, [`PublisherEntry`](#publisherentry)&gt; ? `ExtractTargetExchangesFromPublishers`&lt;`TContract`\[`"publishers"`\]&gt; : `object` & `TContract`\[`"rpcs"`\] *extends* `Record`&lt;`string`, [`RpcDefinition`](#rpcdefinition)&gt; ? `ExtractDeadLetterExchangesFromRpcs`&lt;`TContract`\[`"rpcs"`\]&gt; : `object` | [types.ts:1556](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L1556) |
| <a id="publishers-2"></a> `publishers` | `TContract`\[`"publishers"`\] *extends* `Record`&lt;`string`, [`PublisherEntry`](#publisherentry)&gt; ? `ExtractPublisherDefinitions`&lt;`TContract`\[`"publishers"`\]&gt; : `object` | [types.ts:1589](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L1589) |
| <a id="queues-1"></a> `queues` | `TContract`\[`"consumers"`\] *extends* `Record`&lt;`string`, [`ConsumerEntry`](#consumerentry)&gt; ? `ExtractQueuesFromConsumers`&lt;`TContract`\[`"consumers"`\]&gt; : `object` & `TContract`\[`"rpcs"`\] *extends* `Record`&lt;`string`, [`RpcDefinition`](#rpcdefinition)&gt; ? `ExtractQueuesFromRpcs`&lt;`TContract`\[`"rpcs"`\]&gt; : `object` | [types.ts:1574](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L1574) |
| <a id="rpcs-2"></a> `rpcs` | `TContract`\[`"rpcs"`\] *extends* `Record`&lt;`string`, [`RpcDefinition`](#rpcdefinition)&gt; ? `TContract`\[`"rpcs"`\] : `object` | [types.ts:1595](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L1595) |

***

### DeadLetterConfig

```ts
type DeadLetterConfig = object;
```

Defined in: [types.ts:518](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L518)

Configuration for dead letter exchange (DLX) on a queue.

When a message in a queue is rejected, expires, or exceeds the queue length limit,
it can be automatically forwarded to a dead letter exchange for further processing
or storage.

#### Properties

| Property | Type | Description | Defined in |
| ------ | ------ | ------ | ------ |
| <a id="exchange-2"></a> `exchange` | [`ExchangeDefinition`](#exchangedefinition) | The exchange to send dead-lettered messages to. This exchange must be declared in the contract. | [types.ts:523](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L523) |
| <a id="routingkey-2"></a> `routingKey?` | `string` | Optional routing key to use when forwarding messages to the dead letter exchange. If not specified, the original message routing key is used. | [types.ts:529](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L529) |

***

### DefineQueueOptions

```ts
type DefineQueueOptions = 
  | QuorumQueueOptions
  | ClassicQueueOptions;
```

Defined in: [types.ts:379](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L379)

Options for defining a queue. Uses a discriminated union based on the `type` property
to enforce quorum queue constraints at compile time.

- Quorum queues (default): Do not support `exclusive`, `autoDelete`, or `maxPriority`
- Classic queues: Support all options including `exclusive`, `autoDelete`, and `maxPriority`

***

### DirectExchangeDefinition

```ts
type DirectExchangeDefinition<TName> = BaseExchangeDefinition<TName> & object;
```

Defined in: [types.ts:459](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L459)

A direct exchange definition.

Direct exchanges route messages to queues based on exact routing key matches.
This is ideal for point-to-point messaging where each message should go to specific queues.

#### Type Declaration

| Name | Type | Defined in |
| ------ | ------ | ------ |
| `type` | `"direct"` | [types.ts:461](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L461) |

#### Type Parameters

| Type Parameter | Default type |
| ------ | ------ |
| `TName` *extends* `string` | `string` |

#### Example

```typescript
const tasksExchange: DirectExchangeDefinition = defineExchange('tasks', {
  type: 'direct',
});
```

***

### EventConsumerResult

```ts
type EventConsumerResult<TMessage, TExchange, TQueue, TExchangeBinding, TBridgeExchange> = object;
```

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

Result from defineEventConsumer.

Contains the consumer definition and binding needed to subscribe to an event.
Can be used directly in defineContract's consumers section - the binding
will be automatically extracted.

#### Type Parameters

| Type Parameter | Default type | Description |
| ------ | ------ | ------ |
| `TMessage` *extends* [`MessageDefinition`](#messagedefinition) | - | The message definition |
| `TExchange` *extends* [`ExchangeDefinition`](#exchangedefinition) | [`ExchangeDefinition`](#exchangedefinition) | - |
| `TQueue` *extends* [`QueueEntry`](#queueentry) | [`QueueEntry`](#queueentry) | - |
| `TExchangeBinding` *extends* [`ExchangeBindingDefinition`](#exchangebindingdefinition) \| `undefined` | [`ExchangeBindingDefinition`](#exchangebindingdefinition) \| `undefined` | - |
| `TBridgeExchange` *extends* [`ExchangeDefinition`](#exchangedefinition) \| `undefined` | [`ExchangeDefinition`](#exchangedefinition) \| `undefined` | - |

#### Properties

| Property | Type | Description | Defined in |
| ------ | ------ | ------ | ------ |
| <a id="__brand-4"></a> `__brand` | `"EventConsumerResult"` | Discriminator to identify this as an event consumer result | [builder/event.ts:64](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/builder/event.ts#L64) |
| <a id="binding-2"></a> `binding` | [`QueueBindingDefinition`](#queuebindingdefinition) | The binding connecting the queue to the exchange | [builder/event.ts:68](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/builder/event.ts#L68) |
| <a id="bridgeexchange-2"></a> `bridgeExchange` | `TBridgeExchange` | The bridge (local domain) exchange when bridging, if configured | [builder/event.ts:76](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/builder/event.ts#L76) |
| <a id="consumer-2"></a> `consumer` | [`ConsumerDefinition`](#consumerdefinition)&lt;`TMessage`&gt; | The consumer definition for processing messages | [builder/event.ts:66](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/builder/event.ts#L66) |
| <a id="exchange-3"></a> `exchange` | `TExchange` | The source exchange this consumer subscribes to | [builder/event.ts:70](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/builder/event.ts#L70) |
| <a id="exchangebinding-2"></a> `exchangeBinding` | `TExchangeBinding` | The exchange-to-exchange binding when bridging, if configured | [builder/event.ts:74](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/builder/event.ts#L74) |
| <a id="queue-3"></a> `queue` | `TQueue` | The queue this consumer reads from | [builder/event.ts:72](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/builder/event.ts#L72) |

***

### EventConsumerResultBase

```ts
type EventConsumerResultBase = object;
```

Defined in: [types.ts:1006](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L1006)

Base type for event consumer result.

This is a simplified type used in ContractDefinitionInput. The full generic type
is defined in the builder module.

#### See

defineEventConsumer for creating event consumers

#### Properties

| Property | Type | Defined in |
| ------ | ------ | ------ |
| <a id="__brand-5"></a> `__brand` | `"EventConsumerResult"` | [types.ts:1007](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L1007) |
| <a id="binding-3"></a> `binding` | [`QueueBindingDefinition`](#queuebindingdefinition) | [types.ts:1009](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L1009) |
| <a id="bridgeexchange-3"></a> `bridgeExchange` | [`ExchangeDefinition`](#exchangedefinition) \| `undefined` | [types.ts:1013](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L1013) |
| <a id="consumer-3"></a> `consumer` | [`ConsumerDefinition`](#consumerdefinition) | [types.ts:1008](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L1008) |
| <a id="exchange-4"></a> `exchange` | [`ExchangeDefinition`](#exchangedefinition) | [types.ts:1010](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L1010) |
| <a id="exchangebinding-3"></a> `exchangeBinding` | [`ExchangeBindingDefinition`](#exchangebindingdefinition) \| `undefined` | [types.ts:1012](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L1012) |
| <a id="queue-4"></a> `queue` | [`QueueEntry`](#queueentry) | [types.ts:1011](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L1011) |

***

### EventPublisherConfig

```ts
type EventPublisherConfig<TMessage, TExchange, TRoutingKey> = object;
```

Defined in: [builder/event.ts:28](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/builder/event.ts#L28)

Configuration for an event publisher.

Events are published without knowing who consumes them. Multiple consumers
can subscribe to the same event. This follows the pub/sub pattern where
publishers broadcast events and consumers subscribe to receive them.

#### Type Parameters

| Type Parameter | Default type | Description |
| ------ | ------ | ------ |
| `TMessage` *extends* [`MessageDefinition`](#messagedefinition) | - | The message definition |
| `TExchange` *extends* [`ExchangeDefinition`](#exchangedefinition) | - | The exchange definition |
| `TRoutingKey` *extends* `string` \| `undefined` | `undefined` | The routing key type (undefined for fanout and headers exchanges) |

#### Properties

| Property | Type | Description | Defined in |
| ------ | ------ | ------ | ------ |
| <a id="__brand-6"></a> `__brand` | `"EventPublisherConfig"` | Discriminator to identify this as an event publisher config | [builder/event.ts:34](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/builder/event.ts#L34) |
| <a id="arguments-1"></a> `arguments?` | `Record`&lt;`string`, `unknown`&gt; | Additional AMQP arguments | [builder/event.ts:42](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/builder/event.ts#L42) |
| <a id="exchange-5"></a> `exchange` | `TExchange` | The exchange to publish to | [builder/event.ts:36](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/builder/event.ts#L36) |
| <a id="message-3"></a> `message` | `TMessage` | The message definition | [builder/event.ts:38](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/builder/event.ts#L38) |
| <a id="routingkey-3"></a> `routingKey` | `TRoutingKey` | The routing key for direct/topic exchanges | [builder/event.ts:40](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/builder/event.ts#L40) |

***

### EventPublisherConfigBase

```ts
type EventPublisherConfigBase = object;
```

Defined in: [types.ts:972](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L972)

Base type for event publisher configuration.

This is a simplified type used in ContractDefinition. The full generic type
is defined in the builder module.

#### See

defineEventPublisher for creating event publishers

#### Properties

| Property | Type | Defined in |
| ------ | ------ | ------ |
| <a id="__brand-7"></a> `__brand` | `"EventPublisherConfig"` | [types.ts:973](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L973) |
| <a id="arguments-2"></a> `arguments?` | `Record`&lt;`string`, `unknown`&gt; | [types.ts:977](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L977) |
| <a id="exchange-6"></a> `exchange` | [`ExchangeDefinition`](#exchangedefinition) | [types.ts:974](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L974) |
| <a id="message-4"></a> `message` | [`MessageDefinition`](#messagedefinition) | [types.ts:975](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L975) |
| <a id="routingkey-4"></a> `routingKey` | `string` \| `undefined` | [types.ts:976](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L976) |

***

### ExchangeBindingDefinition

```ts
type ExchangeBindingDefinition = object & 
  | {
  routingKey: string;
  source:   | DirectExchangeDefinition
     | TopicExchangeDefinition;
}
  | {
  routingKey?: never;
  source:   | FanoutExchangeDefinition
     | HeadersExchangeDefinition;
};
```

Defined in: [types.ts:855](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L855)

Binding between two exchanges (exchange-to-exchange routing).

Defines how messages should be forwarded from a source exchange to a destination exchange.
This allows for more complex routing topologies.

#### Type Declaration

| Name | Type | Description | Defined in |
| ------ | ------ | ------ | ------ |
| `arguments?` | `Record`&lt;`string`, `unknown`&gt; | Additional AMQP arguments for the binding. | [types.ts:865](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L865) |
| `destination` | [`ExchangeDefinition`](#exchangedefinition) | The destination exchange that will receive forwarded messages | [types.ts:860](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L860) |
| `type` | `"exchange"` | Discriminator indicating this is an exchange-to-exchange binding | [types.ts:857](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L857) |

#### Example

```typescript
// Forward high-priority orders to a special processing exchange
const binding: ExchangeBindingDefinition = {
  type: 'exchange',
  source: ordersExchange,
  destination: highPriorityExchange,
  routingKey: 'order.high-priority.*'
};
```

***

### ExchangeDefinition

```ts
type ExchangeDefinition<TName> = 
  | TopicExchangeDefinition<TName>
  | DirectExchangeDefinition<TName>
  | FanoutExchangeDefinition<TName>
  | HeadersExchangeDefinition<TName>;
```

Defined in: [types.ts:505](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L505)

Union type of all exchange definitions.

Represents any type of AMQP exchange: topic, direct, fanout, headers.

#### Type Parameters

| Type Parameter | Default type |
| ------ | ------ |
| `TName` *extends* `string` | `string` |

***

### FanoutExchangeDefinition

```ts
type FanoutExchangeDefinition<TName> = BaseExchangeDefinition<TName> & object;
```

Defined in: [types.ts:477](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L477)

A fanout exchange definition.

Fanout exchanges broadcast all messages to all bound queues, ignoring routing keys.
This is the simplest exchange type for pub/sub messaging patterns.

#### Type Declaration

| Name | Type | Defined in |
| ------ | ------ | ------ |
| `type` | `"fanout"` | [types.ts:479](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L479) |

#### Type Parameters

| Type Parameter | Default type |
| ------ | ------ |
| `TName` *extends* `string` | `string` |

#### Example

```typescript
const logsExchange: FanoutExchangeDefinition = defineExchange('logs', {
  type: 'fanout',
});
```

***

### HeadersExchangeDefinition

```ts
type HeadersExchangeDefinition<TName> = BaseExchangeDefinition<TName> & object;
```

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

A headers exchange definition.

Headers exchanges route messages based on header values rather than routing keys.
This is useful for more complex routing scenarios where metadata is important.

#### Type Declaration

| Name | Type | Defined in |
| ------ | ------ | ------ |
| `type` | `"headers"` | [types.ts:497](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L497) |

#### Type Parameters

| Type Parameter | Default type |
| ------ | ------ |
| `TName` *extends* `string` | `string` |

#### Example

```typescript
const routesExchange: HeadersExchangeDefinition = defineExchange('routes', {
  type: 'headers',
});
```

***

### ImmediateRequeueRetryOptions

```ts
type ImmediateRequeueRetryOptions = object;
```

Defined in: [types.ts:88](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L88)

Immediate-Requeue retry options.

Failed messages are requeued immediately.
For quorum queues, messages are requeued with `nack(requeue=true)`, and the worker tracks delivery count via the native RabbitMQ `x-delivery-count` header.
For classic queues, messages are re-published on the same queue, and the worker tracks delivery count via a custom `x-retry-count` header.
When the count exceeds `maxRetries`, the message is automatically dead-lettered (if DLX is configured) or dropped.

**Benefits:** Simpler architecture, no wait queues needed, no head-of-queue blocking.
**Limitation:** Immediate retries only (no exponential backoff).

#### See

https://www.rabbitmq.com/docs/quorum-queues#poison-message-handling

#### Properties

| Property | Type | Description | Defined in |
| ------ | ------ | ------ | ------ |
| <a id="maxretries"></a> `maxRetries?` | `number` | Maximum retry attempts before sending to DLQ. **Minimum** 1 - Must be a positive integer (1 or greater) **Default** `3` | [types.ts:98](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L98) |
| <a id="mode"></a> `mode` | `"immediate-requeue"` | Immediate-Requeue mode. | [types.ts:92](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L92) |

***

### InferConsumerNames

```ts
type InferConsumerNames<TContract> = TContract["consumers"] extends Record<string, unknown> ? keyof TContract["consumers"] : never;
```

Defined in: [types.ts:1631](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L1631)

Extract consumer names from a contract.

This utility type extracts the keys of all consumers defined in a contract.
It's used internally for type inference in the TypedAmqpWorker.

#### Type Parameters

| Type Parameter | Description |
| ------ | ------ |
| `TContract` *extends* [`ContractDefinition`](#contractdefinition) | The contract definition |

#### Returns

Union of consumer names, or never if no consumers defined

#### Example

```typescript
type ConsumerNames = InferConsumerNames<typeof myContract>;
// Result: 'processOrder' | 'sendNotification' | 'updateInventory'
```

***

### InferPublisherNames

```ts
type InferPublisherNames<TContract> = TContract["publishers"] extends Record<string, unknown> ? keyof TContract["publishers"] : never;
```

Defined in: [types.ts:1613](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L1613)

Extract publisher names from a contract.

This utility type extracts the keys of all publishers defined in a contract.
It's used internally for type inference in the TypedAmqpClient.

#### Type Parameters

| Type Parameter | Description |
| ------ | ------ |
| `TContract` *extends* [`ContractDefinition`](#contractdefinition) | The contract definition |

#### Returns

Union of publisher names, or never if no publishers defined

#### Example

```typescript
type PublisherNames = InferPublisherNames<typeof myContract>;
// Result: 'orderCreated' | 'orderUpdated' | 'orderCancelled'
```

***

### InferRpcNames

```ts
type InferRpcNames<TContract> = TContract["rpcs"] extends Record<string, RpcDefinition> ? keyof TContract["rpcs"] : never;
```

Defined in: [types.ts:1643](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L1643)

Extract RPC names from a contract.

Each name in this union has a typed worker handler and a `client.call(name, ...)`
method. RPC names are disjoint from `InferConsumerNames` and `InferPublisherNames`.

#### Type Parameters

| Type Parameter | Description |
| ------ | ------ |
| `TContract` *extends* [`ContractDefinition`](#contractdefinition) | The contract definition |

#### Returns

Union of RPC names, or never if no RPCs defined

***

### MatchingRoutingKey

```ts
type MatchingRoutingKey<Pattern, Key> = RoutingKey<Key> extends never ? never : BindingPattern<Pattern> extends never ? never : MatchesPattern<Key, Pattern> extends true ? Key : never;
```

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

Validate that a routing key matches a binding pattern.

This is a utility type provided for users who want compile-time validation
that a routing key matches a specific pattern. It's not enforced internally
in the API to avoid TypeScript recursion depth issues with complex routing keys.

Returns the routing key if it's valid and matches the pattern, `never` otherwise.

#### Type Parameters

| Type Parameter | Description |
| ------ | ------ |
| `Pattern` *extends* `string` | The binding pattern (can contain * and # wildcards) |
| `Key` *extends* `string` | The routing key to validate |

#### Example

```typescript
type ValidKey = MatchingRoutingKey<"order.*", "order.created">; // "order.created"
type InvalidKey = MatchingRoutingKey<"order.*", "user.created">; // never
```

***

### MessageDefinition

```ts
type MessageDefinition<TPayload, THeaders> = object;
```

Defined in: [types.ts:769](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L769)

Definition of a message with typed payload and optional headers.

#### Type Parameters

| Type Parameter | Default type | Description |
| ------ | ------ | ------ |
| `TPayload` *extends* [`AnySchema`](#anyschema) | [`AnySchema`](#anyschema) | The Standard Schema v1 compatible schema for the message payload |
| `THeaders` *extends* \| `StandardSchemaV1`&lt;`Record`&lt;`string`, `unknown`&gt;&gt; \| `undefined` | \| `StandardSchemaV1`&lt;`Record`&lt;`string`, `unknown`&gt;&gt; \| `undefined` | The Standard Schema v1 compatible schema for the message headers (optional) |

#### Properties

| Property | Type | Description | Defined in |
| ------ | ------ | ------ | ------ |
| <a id="description"></a> `description?` | `string` | Detailed description of the message for documentation purposes. Used in AsyncAPI specification generation. | [types.ts:797](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L797) |
| <a id="headers"></a> `headers?` | `THeaders` | Optional headers schema for validating message metadata. Must be a Standard Schema v1 compatible schema. | [types.ts:785](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L785) |
| <a id="payload"></a> `payload` | `TPayload` | The payload schema for validating message content. Must be a Standard Schema v1 compatible schema (Zod, Valibot, ArkType, etc.). | [types.ts:779](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L779) |
| <a id="summary"></a> `summary?` | `string` | Brief description of the message for documentation purposes. Used in AsyncAPI specification generation. | [types.ts:791](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L791) |

***

### PublisherDefinition

```ts
type PublisherDefinition<TMessage> = object & 
  | {
  exchange:   | DirectExchangeDefinition
     | TopicExchangeDefinition;
  routingKey: string;
}
  | {
  exchange:   | FanoutExchangeDefinition
     | HeadersExchangeDefinition;
  routingKey?: never;
};
```

Defined in: [types.ts:913](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L913)

Definition of a message publisher.

A publisher sends messages to an exchange with automatic schema validation.
The message payload is validated against the schema before being sent to RabbitMQ.

Compression can be optionally applied at publish time by specifying a compression
algorithm when calling the publish method.

#### Type Declaration

| Name | Type | Description | Defined in |
| ------ | ------ | ------ | ------ |
| `message` | `TMessage` | The message definition including the payload schema | [types.ts:915](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L915) |

#### Type Parameters

| Type Parameter | Default type | Description |
| ------ | ------ | ------ |
| `TMessage` *extends* [`MessageDefinition`](#messagedefinition) | [`MessageDefinition`](#messagedefinition) | The message definition with payload schema |

#### Example

```typescript
const publisher: PublisherDefinition = {
  exchange: ordersExchange,
  message: orderMessage,
  routingKey: 'order.created'
};
```

***

### PublisherEntry

```ts
type PublisherEntry = 
  | PublisherDefinition
  | EventPublisherConfigBase
  | BridgedPublisherConfigBase;
```

Defined in: [types.ts:1171](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L1171)

Publisher entry that can be passed to defineContract's publishers section.

Can be either:
- A plain PublisherDefinition from definePublisher
- An EventPublisherConfig from defineEventPublisher (auto-extracted to publisher)
- An BridgedPublisherConfig from defineCommandPublisher (auto-extracted to publisher)

***

### QueueBindingDefinition

```ts
type QueueBindingDefinition = object & 
  | {
  exchange:   | DirectExchangeDefinition
     | TopicExchangeDefinition;
  routingKey: string;
}
  | {
  exchange:   | FanoutExchangeDefinition
     | HeadersExchangeDefinition;
  routingKey?: never;
};
```

Defined in: [types.ts:807](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L807)

Binding between a queue and an exchange.

Defines how messages from an exchange should be routed to a queue.
For direct and topic exchanges, a routing key is required.
For fanout and headers exchanges, no routing key is needed.

#### Type Declaration

| Name | Type | Description | Defined in |
| ------ | ------ | ------ | ------ |
| `arguments?` | `Record`&lt;`string`, `unknown`&gt; | Additional AMQP arguments for the binding. Can be used for advanced routing scenarios with the headers exchange type. | [types.ts:818](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L818) |
| `queue` | [`QueueDefinition`](#queuedefinition) | The queue that will receive messages | [types.ts:812](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L812) |
| `type` | `"queue"` | Discriminator indicating this is a queue-to-exchange binding | [types.ts:809](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L809) |

***

### QueueDefinition

```ts
type QueueDefinition<TName> = 
  | QuorumQueueDefinition<TName>
  | ClassicQueueDefinition<TName>;
```

Defined in: [types.ts:646](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L646)

Definition of an AMQP queue.

A discriminated union based on queue type:
- `QuorumQueueDefinition`: For quorum queues (type: "quorum")
- `ClassicQueueDefinition`: For classic queues (type: "classic")

Use `queue.type` as the discriminator to narrow the type.

#### Type Parameters

| Type Parameter | Default type |
| ------ | ------ |
| `TName` *extends* `string` | `string` |

***

### QueueEntry

```ts
type QueueEntry<TName> = 
  | QueueDefinition<TName>
  | QueueWithTtlBackoffInfrastructure<TName>;
```

Defined in: [types.ts:749](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L749)

A queue entry that can be passed to `defineContract`.

Can be either a plain queue definition or a queue with TTL-backoff infrastructure.

#### Type Parameters

| Type Parameter | Default type |
| ------ | ------ |
| `TName` *extends* `string` | `string` |

***

### QueueType

```ts
type QueueType = "quorum" | "classic";
```

Defined in: [types.ts:227](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L227)

Supported queue types in RabbitMQ.

- `quorum`: Quorum queues (default, recommended) - Provide better durability and high-availability
  using the Raft consensus algorithm. Best for most production use cases.
- `classic`: Classic queues - The traditional RabbitMQ queue type. Use only when you need
  specific features not supported by quorum queues (e.g., non-durable queues, priority queues).

Note: Quorum queues only support durable queues, and do not support exclusive, auto-deleting, or priority queues.

#### See

https://www.rabbitmq.com/docs/quorum-queues

#### Example

```typescript
// Create a quorum queue (default, recommended)
const orderQueue = defineQueue('order-processing', {
  type: 'quorum', // This is the default
});

// Create a classic queue (for special cases)
const tempQueue = defineQueue('temp-queue', {
  type: 'classic',
  durable: false, // Only supported with classic queues
});
```

***

### QueueWithTtlBackoffInfrastructure

```ts
type QueueWithTtlBackoffInfrastructure<TName> = object;
```

Defined in: [types.ts:706](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L706)

A queue with automatically generated TTL-backoff retry infrastructure.

This type is returned by `defineQueue` when TTL-backoff retry is configured.
When passed to `defineContract`, the wait queue, exchanges, and bindings are
automatically added to the contract.

#### Example

```typescript
const exchange = defineExchange('orders');
const queue = defineQueue('order-processing', {
  retry: { mode: 'ttl-backoff', maxRetries: 5 },
});
// queue is QueueWithTtlBackoffInfrastructure
const message = defineMessage(z.object({ orderId: z.string() }));
const orderCreated = defineEventPublisher(exchange, message, { routingKey: 'order.created' });

// Wait queue, exchanges, and bindings are automatically extracted
const contract = defineContract({
  publishers: { orderCreated },
  consumers: { processOrder: defineEventConsumer(orderCreated, queue) },
});
```

#### Type Parameters

| Type Parameter | Default type |
| ------ | ------ |
| `TName` *extends* `string` | `string` |

#### Properties

| Property | Type | Description | Defined in |
| ------ | ------ | ------ | ------ |
| <a id="queue-5"></a> `queue` | [`QueueDefinition`](#queuedefinition)&lt;`TName`&gt; | The main queue definition. | [types.ts:716](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L716) |
| <a id="retryexchange"></a> `retryExchange` | [`HeadersExchangeDefinition`](#headersexchangedefinition) | Retry exchange used to route messages to retry back to the main queue. | [types.ts:731](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L731) |
| <a id="retryqueuebinding"></a> `retryQueueBinding` | [`QueueBindingDefinition`](#queuebindingdefinition) | Binding that routes messages to retry back to the main queue. | [types.ts:741](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L741) |
| <a id="waitexchange"></a> `waitExchange` | [`HeadersExchangeDefinition`](#headersexchangedefinition) | Wait exchange used to route failed messages to the wait queue. | [types.ts:726](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L726) |
| <a id="waitqueue"></a> `waitQueue` | [`QueueDefinition`](#queuedefinition) | The wait queue for holding messages during backoff delay. | [types.ts:721](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L721) |
| <a id="waitqueuebinding"></a> `waitQueueBinding` | [`QueueBindingDefinition`](#queuebindingdefinition) | Binding that routes failed messages to the wait queue. | [types.ts:736](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L736) |

***

### QuorumQueueDefinition

```ts
type QuorumQueueDefinition<TName> = BaseQueueDefinition<TName> & object;
```

Defined in: [types.ts:572](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L572)

Definition of a quorum queue.

Quorum queues provide better durability and high-availability using the Raft consensus algorithm.

#### Type Declaration

| Name | Type | Description | Defined in |
| ------ | ------ | ------ | ------ |
| `autoDelete?` | `never` | Quorum queues do not support auto-delete mode. Use type: 'classic' if you need auto-deleting queues. | [types.ts:593](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L593) |
| `durable` | `true` | Quorum queues only support durable queues. | [types.ts:581](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L581) |
| `exclusive?` | `never` | Quorum queues do not support exclusive mode. Use type: 'classic' if you need exclusive queues. | [types.ts:587](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L587) |
| `maxPriority?` | `never` | Quorum queues do not support priority queues. Use type: 'classic' if you need priority queues. | [types.ts:599](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L599) |
| `type` | `"quorum"` | Queue type discriminator: quorum queue. | [types.ts:576](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L576) |

#### Type Parameters

| Type Parameter | Default type |
| ------ | ------ |
| `TName` *extends* `string` | `string` |

***

### QuorumQueueOptions

```ts
type QuorumQueueOptions = BaseQueueOptions & object;
```

Defined in: [types.ts:295](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L295)

Options for creating a quorum queue.

Quorum queues do not support:
- `exclusive` - Use classic queues for connection-scoped queues
- `autoDelete` - Use classic queues for auto-deleting queues when consumers disconnect
- `maxPriority` - Use classic queues for priority queues
- `durable: false` - Use classic queues for non-durable queues

Quorum queues provide native retry support for immediate-requeue retry mode:
- RabbitMQ tracks delivery count automatically via `x-delivery-count` header
- When the limit is exceeded, messages are dead-lettered (if DLX is configured) or dropped
- This is simpler than TTL-based retry and avoids head-of-queue blocking issues

#### Type Declaration

| Name | Type | Description | Defined in |
| ------ | ------ | ------ | ------ |
| `autoDelete?` | `never` | Quorum queues do not support auto-delete mode. Use type: 'classic' if you need auto-deleting queues. | [types.ts:316](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L316) |
| `durable?` | `true` | Quorum queues only support durable queues. | [types.ts:304](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L304) |
| `exclusive?` | `never` | Quorum queues do not support exclusive mode. Use type: 'classic' if you need exclusive queues. | [types.ts:310](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L310) |
| `maxPriority?` | `never` | Quorum queues do not support priority queues. Use type: 'classic' if you need priority queues. | [types.ts:322](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L322) |
| `type?` | `"quorum"` | Queue type: quorum (default, recommended) | [types.ts:299](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L299) |

#### Example

```typescript
const orderQueue = defineQueue('orders', {
  type: 'quorum',
  deadLetter: { exchange: dlx },
  retry: { mode: 'immediate-requeue', maxRetries: 3 } // Message dead-lettered after 3 retry attempts
});
```

***

### ResolvedRetryOptions

```ts
type ResolvedRetryOptions = 
  | NoneRetryOptions
  | ResolvedImmediateRequeueRetryOptions
  | ResolvedTtlBackoffRetryOptions;
```

Defined in: [types.ts:166](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L166)

Resolved retry configuration stored in queue definitions.

This is a discriminated union based on the `mode` field:
- `none`: No retry attempts are made; failed messages are handled by DLQ/reject
- `immediate-requeue`: Has all immediate-requeue retry options with default applied
- `ttl-backoff`: Has all TTL-backoff retry options with defaults applied

When using `ttl-backoff` mode, the core package will automatically create
a wait queue and the necessary exchanges and bindings.

***

### RoutingKey

```ts
type RoutingKey<S> = S extends "" ? never : S extends `${string}*${string}` | `${string}#${string}` ? never : S;
```

Defined in: [builder/routing-types.ts:25](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/builder/routing-types.ts#L25)

Type-safe routing key that validates basic format.

Validates that a routing key follows basic AMQP routing key rules:
- Must not contain wildcards (* or #)
- Must not be empty
- Should contain alphanumeric characters, dots, hyphens, and underscores

Note: Full character-by-character validation is not performed to avoid TypeScript
recursion depth limits. Runtime validation is still recommended.

#### Type Parameters

| Type Parameter | Description |
| ------ | ------ |
| `S` *extends* `string` | The routing key string to validate |

#### Example

```typescript
type Valid = RoutingKey<"order.created">; // "order.created"
type Invalid = RoutingKey<"order.*">; // never (contains wildcard)
type Invalid2 = RoutingKey<"">; // never (empty string)
```

***

### RpcDefinition

```ts
type RpcDefinition<TRequestMessage, TResponseMessage, TQueue, TErrors> = object;
```

Defined in: [types.ts:1061](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L1061)

Definition of an RPC operation: a request/response pair flowing over a
request queue with replies routed back via direct reply-to.

An RPC is bidirectional on both ends — the server consumes requests and
publishes responses; the client publishes requests and consumes responses —
so it has its own slot in the contract (`rpcs`) rather than being shoehorned
into `consumers` or `publishers`.

#### See

defineRpc for creating RPC definitions

#### Type Parameters

| Type Parameter | Default type | Description |
| ------ | ------ | ------ |
| `TRequestMessage` *extends* [`MessageDefinition`](#messagedefinition) | [`MessageDefinition`](#messagedefinition) | The request message definition |
| `TResponseMessage` *extends* [`MessageDefinition`](#messagedefinition) | [`MessageDefinition`](#messagedefinition) | The response message definition |
| `TQueue` *extends* [`QueueEntry`](#queueentry) | [`QueueEntry`](#queueentry) | The request queue entry |
| `TErrors` *extends* [`RpcErrorMap`](#rpcerrormap) \| `undefined` | [`RpcErrorMap`](#rpcerrormap) \| `undefined` | The typed error map (undefined when the RPC declares none) |

#### Properties

| Property | Type | Description | Defined in |
| ------ | ------ | ------ | ------ |
| <a id="errors"></a> `errors?` | `TErrors` | Typed business errors the handler may return via `Err(rpcError(code, data))`. Error data is validated against the declared schema on the worker before the error reply is published, and re-validated on the client when it arrives. Business errors are replied and acked — never retried. | [types.ts:1079](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L1079) |
| <a id="queue-6"></a> `queue` | `TQueue` | The queue that receives RPC requests. Replies are routed back via direct reply-to. | [types.ts:1068](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L1068) |
| <a id="request"></a> `request` | `TRequestMessage` | Schema for the request payload (validated on both publish and consume). | [types.ts:1070](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L1070) |
| <a id="response"></a> `response` | `TResponseMessage` | Schema for the response payload (validated on both worker reply and client receive). | [types.ts:1072](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L1072) |

***

### RpcErrorMap

```ts
type RpcErrorMap = Record<string, MessageDefinition>;
```

Defined in: [types.ts:1043](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L1043)

Typed error map for an RPC: error code → message definition validating the
error's `data` payload.

Reuses [MessageDefinition](#messagedefinition) so error data gets the same Standard Schema
validation and AsyncAPI metadata (`summary` / `description`) as request and
response payloads. The `headers` slot of an error's message definition is
ignored — error replies carry the code in a fixed AMQP header instead.

#### See

defineRpc for declaring errors on an RPC

***

### TopicExchangeDefinition

```ts
type TopicExchangeDefinition<TName> = BaseExchangeDefinition<TName> & object;
```

Defined in: [types.ts:441](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L441)

A topic exchange definition.

Topic exchanges route messages to queues based on routing key patterns with wildcards:
- `*` (star) matches exactly one word
- `#` (hash) matches zero or more words

Words are separated by dots (e.g., `order.created.high-value`).

#### Type Declaration

| Name | Type | Defined in |
| ------ | ------ | ------ |
| `type` | `"topic"` | [types.ts:443](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L443) |

#### Type Parameters

| Type Parameter | Default type |
| ------ | ------ |
| `TName` *extends* `string` | `string` |

#### Example

```typescript
const ordersExchange: TopicExchangeDefinition = defineExchange('orders', {
  type: 'topic', // This is the default type, so it can be omitted
});
// Can be bound with patterns like 'order.*' or 'order.#'
```

***

### TtlBackoffRetryOptions

```ts
type TtlBackoffRetryOptions = object;
```

Defined in: [types.ts:27](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L27)

TTL-Backoff retry options for exponential backoff with configurable delays.

Uses TTL + wait queue pattern. Messages are published to a wait queue with
per-message TTL, then dead-lettered back to the main queue after the TTL expires.

**Benefits:** Configurable delays with exponential backoff and jitter.
**Limitation:** More complex, potential head-of-queue blocking with mixed TTLs.

#### Properties

| Property | Type | Description | Defined in |
| ------ | ------ | ------ | ------ |
| <a id="backoffmultiplier"></a> `backoffMultiplier?` | `number` | Exponential backoff multiplier. **Default** `2` | [types.ts:52](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L52) |
| <a id="initialdelayms"></a> `initialDelayMs?` | `number` | Initial delay in ms before first retry. **Default** `1000` | [types.ts:42](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L42) |
| <a id="jitter"></a> `jitter?` | `boolean` | Add jitter to prevent thundering herd. **Default** `true` | [types.ts:57](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L57) |
| <a id="maxdelayms"></a> `maxDelayMs?` | `number` | Maximum delay in ms between retries. **Default** `30000` | [types.ts:47](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L47) |
| <a id="maxretries-1"></a> `maxRetries?` | `number` | Maximum retry attempts before sending to DLQ. **Minimum** 1 - Must be a positive integer (1 or greater) **Default** `3` | [types.ts:37](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L37) |
| <a id="mode-1"></a> `mode` | `"ttl-backoff"` | TTL-Backoff mode uses wait queues with per-message TTL for exponential backoff. | [types.ts:31](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L31) |
| <a id="retryexchangename"></a> `retryExchangeName?` | `string` | Name of the retry exchange. **Default** `'retry-exchange'` | [types.ts:72](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L72) |
| <a id="waitexchangename"></a> `waitExchangeName?` | `string` | Name of the wait exchange. **Default** `'wait-exchange'` | [types.ts:67](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L67) |
| <a id="waitqueuename"></a> `waitQueueName?` | `string` | Name of the wait queue. **Default** `'{queueName}-wait'` | [types.ts:62](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/types.ts#L62) |

## Functions

### defineConsumer()

```ts
function defineConsumer<TMessage>(
   queue, 
   message, 
   options?): ConsumerDefinition<TMessage>;
```

Defined in: [builder/consumer.ts:120](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/builder/consumer.ts#L120)

Define a message consumer.

A consumer receives and processes messages from a queue. The message schema is validated
automatically when messages are consumed, ensuring type safety for your handlers.

Consumers are associated with a specific queue and message type. When you create a worker
with this consumer, it will process messages from the queue according to the schema.

**Which pattern to use:**

| Pattern | Best for | Description |
|---------|----------|-------------|
| `definePublisher` + `defineConsumer` | Independent definition | Define publishers and consumers separately with manual schema consistency |
| `defineEventPublisher` + `defineEventConsumer` | Event broadcasting | Define event publisher first, create consumers that subscribe to it |
| `defineCommandConsumer` + `defineCommandPublisher` | Task queues | Define command consumer first, create publishers that send commands to it |

Use `defineCommandConsumer` when:
- One consumer receives from multiple publishers
- You want automatic schema consistency between consumer and publishers
- You're building task queue or command patterns

#### Type Parameters

| Type Parameter |
| ------ |
| `TMessage` *extends* [`MessageDefinition`](#messagedefinition) |

#### Parameters

| Parameter | Type | Description |
| ------ | ------ | ------ |
| `queue` | [`QueueEntry`](#queueentry) | The queue definition to consume from |
| `message` | `TMessage` | The message definition with payload schema |
| `options?` | `Omit`&lt;[`ConsumerDefinition`](#consumerdefinition)&lt;`TMessage`&gt;, `"queue"` \| `"message"`&gt; | Optional consumer configuration |

#### Returns

[`ConsumerDefinition`](#consumerdefinition)&lt;`TMessage`&gt;

A consumer definition with inferred message types

#### Example

```typescript
import { z } from 'zod';

const orderQueue = defineQueue('order-processing');
const orderMessage = defineMessage(
  z.object({
    orderId: z.string().uuid(),
    customerId: z.string().uuid(),
    amount: z.number().positive(),
  })
);

const processOrderConsumer = defineConsumer(orderQueue, orderMessage);

// Later, when creating a worker, you'll provide a handler for this consumer:
// const worker = await TypedAmqpWorker.create({
//   contract,
//   handlers: {
//     processOrder: async (message) => {
//       // message is automatically typed based on the schema
//       console.log(message.orderId); // string
//     }
//   },
//   connection
// });
```

#### See

 - defineCommandConsumer - For task queue patterns with automatic schema consistency
 - defineEventPublisher - For event-driven patterns with automatic schema consistency

***

### defineContract()

```ts
function defineContract<TContract>(definition): ContractOutput<TContract>;
```

Defined in: [builder/contract.ts:136](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/builder/contract.ts#L136)

Define an AMQP contract.

A contract is the central definition of your AMQP messaging topology. It brings together
publishers and consumers in a single, type-safe definition. Exchanges, queues, and bindings
are automatically extracted from publishers and consumers.

The contract is used by both clients (for publishing) and workers (for consuming) to ensure
type safety throughout your messaging infrastructure. TypeScript will infer all message types
and publisher/consumer names from the contract.

#### Type Parameters

| Type Parameter |
| ------ |
| `TContract` *extends* [`ContractDefinitionInput`](#contractdefinitioninput) |

#### Parameters

| Parameter | Type | Description |
| ------ | ------ | ------ |
| `definition` | `TContract` | The contract definition containing publishers and consumers |

#### Returns

[`ContractOutput`](#contractoutput)&lt;`TContract`&gt;

The contract definition with fully inferred exchanges, queues, bindings, publishers, and consumers

#### Example

```typescript
import {
  defineContract,
  defineExchange,
  defineQueue,
  defineEventPublisher,
  defineEventConsumer,
  defineMessage,
} from '@amqp-contract/contract';
import { z } from 'zod';

// Define resources
const ordersExchange = defineExchange('orders');
const dlx = defineExchange('orders-dlx', { type: 'direct' });
const orderQueue = defineQueue('order-processing', {
  deadLetter: { exchange: dlx },
  retry: { mode: 'immediate-requeue', maxRetries: 3 },
});
const orderMessage = defineMessage(
  z.object({
    orderId: z.string(),
    amount: z.number(),
  })
);

// Define event publisher
const orderCreatedEvent = defineEventPublisher(ordersExchange, orderMessage, {
  routingKey: 'order.created',
});

// Compose contract - exchanges, queues, bindings are auto-extracted
export const contract = defineContract({
  publishers: {
    orderCreated: orderCreatedEvent,
  },
  consumers: {
    processOrder: defineEventConsumer(orderCreatedEvent, orderQueue),
  },
});

// TypeScript now knows:
// - contract.exchanges.orders, contract.exchanges['orders-dlx']
// - contract.queues['order-processing']
// - contract.bindings.processOrderBinding
// - client.publish('orderCreated', { orderId: string, amount: number })
// - handler: (message: { orderId: string, amount: number }) => Future<Result<void, HandlerError>>
```

***

### defineMessage()

```ts
function defineMessage<TPayload, THeaders>(payload, options?): MessageDefinition<TPayload, THeaders>;
```

Defined in: [builder/message.ts:40](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/builder/message.ts#L40)

Define a message definition with payload and optional headers/metadata.

A message definition specifies the schema for message payloads and headers using
Standard Schema v1 compatible libraries (Zod, Valibot, ArkType, etc.).
The schemas are used for automatic validation when publishing or consuming messages.

#### Type Parameters

| Type Parameter | Default type |
| ------ | ------ |
| `TPayload` *extends* [`AnySchema`](#anyschema) | - |
| `THeaders` *extends* \| `StandardSchemaV1`&lt;`Record`&lt;`string`, `unknown`&gt;, `Record`&lt;`string`, `unknown`&gt;&gt; \| `undefined` | `undefined` |

#### Parameters

| Parameter | Type | Description |
| ------ | ------ | ------ |
| `payload` | `TPayload` | The payload schema (must be Standard Schema v1 compatible) |
| `options?` | \{ `description?`: `string`; `headers?`: `THeaders`; `summary?`: `string`; \} | Optional message metadata |
| `options.description?` | `string` | Detailed description for documentation (used in AsyncAPI generation) |
| `options.headers?` | `THeaders` | Optional header schema for message headers |
| `options.summary?` | `string` | Brief description for documentation (used in AsyncAPI generation) |

#### Returns

[`MessageDefinition`](#messagedefinition)&lt;`TPayload`, `THeaders`&gt;

A message definition with inferred types

#### Example

```typescript
import { z } from 'zod';

const orderMessage = defineMessage(
  z.object({
    orderId: z.string().uuid(),
    customerId: z.string().uuid(),
    amount: z.number().positive(),
    items: z.array(z.object({
      productId: z.string(),
      quantity: z.number().int().positive(),
    })),
  }),
  {
    summary: 'Order created event',
    description: 'Emitted when a new order is created in the system'
  }
);
```

***

### defineQueue()

#### Call Signature

```ts
function defineQueue<TName, TDlx>(name, options): QueueEntryWithDeadLetterExchange<TName, TDlx>;
```

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

Define an AMQP queue.

A queue stores messages until they are consumed by workers. Queues can be bound to exchanges
to receive messages based on routing rules.

By default, queues are created as quorum queues which provide better durability and
high-availability. Use `type: 'classic'` for special cases like non-durable queues
or priority queues.

##### Type Parameters

| Type Parameter |
| ------ |
| `TName` *extends* `string` |
| `TDlx` *extends* [`ExchangeDefinition`](#exchangedefinition) |

##### Parameters

| Parameter | Type | Description |
| ------ | ------ | ------ |
| `name` | `TName` | The name of the queue |
| `options` | `DefineQueueOptionsWithDeadLetterExchange`&lt;`TDlx`&gt; | Optional queue configuration |

##### Returns

`QueueEntryWithDeadLetterExchange`&lt;`TName`, `TDlx`&gt;

A queue definition

##### Example

```typescript
// Quorum queue (default, recommended for production)
const orderQueue = defineQueue('order-processing');

// Explicit quorum queue with dead letter exchange
const dlx = defineExchange('orders-dlx');
const orderQueueWithDLX = defineQueue('order-processing', {
  type: 'quorum',
  deadLetter: {
    exchange: dlx,
    routingKey: 'order.failed'
  },
  arguments: {
    'x-message-ttl': 86400000, // 24 hours
  }
});

// Classic queue (for special cases)
const tempQueue = defineQueue('temp-queue', {
  type: 'classic',
  durable: false,
  autoDelete: true,
});

// Priority queue (requires classic type)
const taskQueue = defineQueue('urgent-tasks', {
  type: 'classic',
  maxPriority: 10,
});

// Queue with TTL-backoff retry (returns infrastructure automatically)
const dlx = defineExchange('orders-dlx', { type: 'direct' });
const orderQueue = defineQueue('order-processing', {
  deadLetter: { exchange: dlx },
  retry: { mode: 'ttl-backoff', maxRetries: 5 },
});
// orderQueue is QueueWithTtlBackoffInfrastructure, pass directly to defineContract
```

#### Call Signature

```ts
function defineQueue<TName>(name, options?): QueueEntry<TName>;
```

Defined in: [builder/queue.ts:119](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/builder/queue.ts#L119)

Define an AMQP queue.

A queue stores messages until they are consumed by workers. Queues can be bound to exchanges
to receive messages based on routing rules.

By default, queues are created as quorum queues which provide better durability and
high-availability. Use `type: 'classic'` for special cases like non-durable queues
or priority queues.

##### Type Parameters

| Type Parameter |
| ------ |
| `TName` *extends* `string` |

##### Parameters

| Parameter | Type | Description |
| ------ | ------ | ------ |
| `name` | `TName` | The name of the queue |
| `options?` | [`DefineQueueOptions`](#definequeueoptions) | Optional queue configuration |

##### Returns

[`QueueEntry`](#queueentry)&lt;`TName`&gt;

A queue definition

##### Example

```typescript
// Quorum queue (default, recommended for production)
const orderQueue = defineQueue('order-processing');

// Explicit quorum queue with dead letter exchange
const dlx = defineExchange('orders-dlx');
const orderQueueWithDLX = defineQueue('order-processing', {
  type: 'quorum',
  deadLetter: {
    exchange: dlx,
    routingKey: 'order.failed'
  },
  arguments: {
    'x-message-ttl': 86400000, // 24 hours
  }
});

// Classic queue (for special cases)
const tempQueue = defineQueue('temp-queue', {
  type: 'classic',
  durable: false,
  autoDelete: true,
});

// Priority queue (requires classic type)
const taskQueue = defineQueue('urgent-tasks', {
  type: 'classic',
  maxPriority: 10,
});

// Queue with TTL-backoff retry (returns infrastructure automatically)
const dlx = defineExchange('orders-dlx', { type: 'direct' });
const orderQueue = defineQueue('order-processing', {
  deadLetter: { exchange: dlx },
  retry: { mode: 'ttl-backoff', maxRetries: 5 },
});
// orderQueue is QueueWithTtlBackoffInfrastructure, pass directly to defineContract
```

***

### defineRpc()

```ts
function defineRpc<TRequestMessage, TResponseMessage, TQueue, TErrors>(queue, messages): RpcDefinition<TRequestMessage, TResponseMessage, TQueue, TErrors>;
```

Defined in: [builder/rpc.ts:56](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/builder/rpc.ts#L56)

Define an RPC operation: a request/response pair flowing over a request
queue with replies routed back via RabbitMQ direct reply-to.

RPC is bidirectional on both ends — the worker handler consumes the request
and produces the response; `client.call(name, request, options)` publishes
the request and awaits the typed response. Both sides share the same
definition, so request and response schemas cannot drift between them.

Plug the result into `defineContract({ rpcs: { name: ... } })`. RPCs do not
appear in `publishers` or `consumers`.

#### Type Parameters

| Type Parameter | Default type |
| ------ | ------ |
| `TRequestMessage` *extends* [`MessageDefinition`](#messagedefinition) | - |
| `TResponseMessage` *extends* [`MessageDefinition`](#messagedefinition) | - |
| `TQueue` *extends* [`QueueEntry`](#queueentry) | - |
| `TErrors` *extends* [`RpcErrorMap`](#rpcerrormap) \| `undefined` | `undefined` |

#### Parameters

| Parameter | Type | Description |
| ------ | ------ | ------ |
| `queue` | `TQueue` | The queue that receives RPC requests. The queue name is used as the routing key on the AMQP default direct exchange. |
| `messages` | \{ `errors?`: `TErrors`; `request`: `TRequestMessage`; `response`: `TResponseMessage`; \} | - |
| `messages.errors?` | `TErrors` | Optional typed error map: error code → message definition for the error's `data` payload. Declared errors widen the handler's `Err` channel (return `Err(rpcError(code, data))`) and the client's `call()` error union; error data is schema-validated on both sides. Business errors are replied and acked — never retried. |
| `messages.request` | `TRequestMessage` | Schema validated against incoming request payloads (server side) and outgoing requests (client side). |
| `messages.response` | `TResponseMessage` | Schema validated against handler return values (server side) and incoming replies (client side). |

#### Returns

[`RpcDefinition`](#rpcdefinition)&lt;`TRequestMessage`, `TResponseMessage`, `TQueue`, `TErrors`&gt;

#### Example

```typescript
import { defineQueue, defineMessage, defineRpc, defineContract } from '@amqp-contract/contract';
import { z } from 'zod';

const getOrder = defineRpc(defineQueue('rpc.get-order'), {
  request: defineMessage(z.object({ orderId: z.string() })),
  response: defineMessage(z.object({ orderId: z.string(), status: z.string() })),
  errors: {
    ORDER_NOT_FOUND: defineMessage(z.object({ orderId: z.string() })),
  },
});

const contract = defineContract({ rpcs: { getOrder } });

// Server (worker): return the response, or a declared typed error
//   handlers: {
//     getOrder: ({ payload }) =>
//       orders.has(payload.orderId)
//         ? OkAsync(orders.get(payload.orderId))
//         : ErrAsync(rpcError('ORDER_NOT_FOUND', { orderId: payload.orderId })),
//   }

// Client: typed call — the error union includes RpcError<'ORDER_NOT_FOUND', { orderId: string }>
//   const result = await client.call('getOrder', { orderId: '42' }, { timeoutMs: 5_000 });
//   if (result.isErr() && isRpcError(result.error)) console.log(result.error.code);
```

***

### extractConsumer()

```ts
function extractConsumer(entry): ConsumerDefinition;
```

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

Extract the ConsumerDefinition from any ConsumerEntry type.

Handles the following entry types:
- ConsumerDefinition: returned as-is
- EventConsumerResult: returns the nested `.consumer` property
- CommandConsumerConfig: returns the nested `.consumer` property

Use this function when you need to access the underlying ConsumerDefinition
from a consumer entry that may have been created with defineEventConsumer
or defineCommandConsumer.

#### Parameters

| Parameter | Type | Description |
| ------ | ------ | ------ |
| `entry` | [`ConsumerEntry`](#consumerentry) | The consumer entry to extract from |

#### Returns

[`ConsumerDefinition`](#consumerdefinition)

The underlying ConsumerDefinition

#### Example

```typescript
// Works with plain ConsumerDefinition
const consumer1 = defineConsumer(queue, message);
extractConsumer(consumer1).queue.name; // "my-queue"

// Works with EventConsumerResult
const consumer2 = defineEventConsumer(eventPublisher, queue);
extractConsumer(consumer2).queue.name; // "my-queue"

// Works with CommandConsumerConfig
const consumer3 = defineCommandConsumer(queue, exchange, message, { routingKey: "cmd" });
extractConsumer(consumer3).queue.name; // "my-queue"
```

***

### extractQueue()

```ts
function extractQueue<T>(entry): ExtractQueueFromEntry<T>;
```

Defined in: [builder/queue-utils.ts:60](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/builder/queue-utils.ts#L60)

Extract the plain QueueDefinition from a QueueEntry.

**Why this function exists:**
When you configure a queue with TTL-backoff retry,
`defineQueue` returns a wrapper object that includes
the main queue, wait queue, headers exchanges, and bindings. This function extracts the underlying
queue definition so you can access properties like `name`, `type`, etc.

**When to use:**
- When you need to access queue properties (name, type, etc.)
- When passing a queue to functions that expect a plain QueueDefinition
- Works safely on both plain queues and infrastructure wrappers

**How it works:**
- If the entry is a `QueueWithTtlBackoffInfrastructure`, returns `entry.queue`
- Otherwise, returns the entry as-is (it's already a plain QueueDefinition)

#### Type Parameters

| Type Parameter |
| ------ |
| `T` *extends* [`QueueEntry`](#queueentry) |

#### Parameters

| Parameter | Type | Description |
| ------ | ------ | ------ |
| `entry` | `T` | The queue entry (either plain QueueDefinition or QueueWithTtlBackoffInfrastructure) |

#### Returns

`ExtractQueueFromEntry`&lt;`T`&gt;

The plain QueueDefinition

#### Example

```typescript
import { defineQueue, extractQueue } from '@amqp-contract/contract';

// TTL-backoff queue returns a wrapper
const orderQueue = defineQueue('orders', {
  retry: { mode: 'ttl-backoff', maxRetries: 3 },
});

// Use extractQueue to access the queue name
const queueName = extractQueue(orderQueue).name; // 'orders'

// Also works safely on plain queues
const plainQueue = defineQueue('simple', { type: 'quorum', retry: { mode: 'immediate-requeue' } });
const plainName = extractQueue(plainQueue).name; // 'simple'

// Access other properties
const queueDef = extractQueue(orderQueue);
console.log(queueDef.name);       // 'orders'
console.log(queueDef.type);       // 'quorum'
```

#### See

isQueueWithTtlBackoffInfrastructure - Type guard to check if extraction is needed

***

### formatIssue()

```ts
function formatIssue(issue): string;
```

Defined in: [issues.ts:11](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/issues.ts#L11)

Render a single Standard Schema issue as `path.to.field: message` (or just
the message for root-level issues). Path segments may be raw property keys
or `{ key }` objects per the Standard Schema spec; both are handled.

Single source of truth for issue rendering across the client and worker —
mirrors temporal-contract's shared formatter (org DNA).

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `issue` | `Issue` |

#### Returns

`string`

***

### isBridgedPublisherConfig()

```ts
function isBridgedPublisherConfig(value): value is BridgedPublisherConfig<MessageDefinition, ExchangeDefinition, ExchangeDefinition>;
```

Defined in: [builder/command.ts:514](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/builder/command.ts#L514)

Type guard to check if a value is a BridgedPublisherConfig.

#### Parameters

| Parameter | Type | Description |
| ------ | ------ | ------ |
| `value` | `unknown` | The value to check |

#### Returns

`value is BridgedPublisherConfig<MessageDefinition, ExchangeDefinition, ExchangeDefinition>`

True if the value is a BridgedPublisherConfig

***

### isCommandConsumerConfig()

```ts
function isCommandConsumerConfig(value): value is CommandConsumerConfig<MessageDefinition, ExchangeDefinition, string | undefined, QueueEntry>;
```

Defined in: [builder/command.ts:497](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/builder/command.ts#L497)

Type guard to check if a value is a CommandConsumerConfig.

#### Parameters

| Parameter | Type | Description |
| ------ | ------ | ------ |
| `value` | `unknown` | The value to check |

#### Returns

value is CommandConsumerConfig\<MessageDefinition, ExchangeDefinition, string \| undefined, QueueEntry\>

True if the value is a CommandConsumerConfig

***

### isEventConsumerResult()

```ts
function isEventConsumerResult(value): value is EventConsumerResult<MessageDefinition, ExchangeDefinition, QueueEntry, ExchangeBindingDefinition | undefined, ExchangeDefinition | undefined>;
```

Defined in: [builder/event.ts:616](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/builder/event.ts#L616)

Type guard to check if a value is an EventConsumerResult.

#### Parameters

| Parameter | Type | Description |
| ------ | ------ | ------ |
| `value` | `unknown` | The value to check |

#### Returns

value is EventConsumerResult\<MessageDefinition, ExchangeDefinition, QueueEntry, ExchangeBindingDefinition \| undefined, ExchangeDefinition \| undefined\>

True if the value is an EventConsumerResult

***

### isEventPublisherConfig()

```ts
function isEventPublisherConfig(value): value is EventPublisherConfig<MessageDefinition, ExchangeDefinition, string | undefined>;
```

Defined in: [builder/event.ts:599](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/builder/event.ts#L599)

Type guard to check if a value is an EventPublisherConfig.

#### Parameters

| Parameter | Type | Description |
| ------ | ------ | ------ |
| `value` | `unknown` | The value to check |

#### Returns

value is EventPublisherConfig\<MessageDefinition, ExchangeDefinition, string \| undefined\>

True if the value is an EventPublisherConfig

***

### isQueueWithTtlBackoffInfrastructure()

```ts
function isQueueWithTtlBackoffInfrastructure(entry): entry is QueueWithTtlBackoffInfrastructure;
```

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

Type guard to check if a queue entry is a QueueWithTtlBackoffInfrastructure.

When you configure a queue with TTL-backoff retry,
`defineQueue` returns a `QueueWithTtlBackoffInfrastructure` instead of a plain
`QueueDefinition`. This type guard helps you distinguish between the two.

**When to use:**
- When you need to check the type of a queue entry at runtime
- When writing generic code that handles both plain queues and infrastructure wrappers

**Related functions:**
- `extractQueue()` - Use this to get the underlying queue definition from either type

#### Parameters

| Parameter | Type | Description |
| ------ | ------ | ------ |
| `entry` | [`QueueEntry`](#queueentry) | The queue entry to check |

#### Returns

`entry is QueueWithTtlBackoffInfrastructure`

True if the entry is a QueueWithTtlBackoffInfrastructure, false otherwise

#### Example

```typescript
const queue = defineQueue('orders', {
  retry: { mode: 'ttl-backoff' },
});

if (isQueueWithTtlBackoffInfrastructure(queue)) {
  // queue has .queue, .waitQueue, .waitQueueBinding, .retryQueueBinding, .waitExchange, .retryExchange
  console.log('Wait queue:', queue.waitQueue.name);
} else {
  // queue is a plain QueueDefinition
  console.log('Queue:', queue.name);
}
```

***

### summarizeIssues()

```ts
function summarizeIssues(issues, limit?): string;
```

Defined in: [issues.ts:28](https://github.com/btravstack/amqp-contract/blob/1948ac0d26ba5aafc2d473bf2820eb2e5408fd7a/packages/contract/src/issues.ts#L28)

Render a list of Standard Schema issues as a single human-readable line:
the first `limit` issues joined with `; `, plus a `(+N more)` suffix when
truncated. Empty input renders as `"no issues"` (defensive — validation
failures always carry at least one issue).

#### Parameters

| Parameter | Type | Default value |
| ------ | ------ | ------ |
| `issues` | readonly `Issue`[] | `undefined` |
| `limit` | `number` | `3` |

#### Returns

`string`
