---
url: https://node-ts.github.io/bus/api/bus-core/interfaces/Transport.md
---
[API reference](../../index.md) / [@node-ts/bus-core](../index.md) / Transport

# Interface: Transport\<TransportMessageType>

Defined in: [packages/bus-core/src/transport/transport.ts:26](https://github.com/node-ts/bus/blob/2e6cf65c27833b707ae31ee623cfb6343770f434/packages/bus-core/src/transport/transport.ts#L26)

A transport adapter interface that enables the service bus to use a messaging technology.

## Type Parameters

| Type Parameter | Default type |
| ------ | ------ |
| `TransportMessageType` | `object` |

## Methods

### connect()?

```ts
optional connect(options): Promise<void>;
```

Defined in: [packages/bus-core/src/transport/transport.ts:92](https://github.com/node-ts/bus/blob/2e6cf65c27833b707ae31ee623cfb6343770f434/packages/bus-core/src/transport/transport.ts#L92)

An optional function that will be called on startup. This gives a chance for the transport
to establish any connections to the underlying infrastructure.

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `options` | [`TransportConnectionOptions`](TransportConnectionOptions.md) |

#### Returns

`Promise`<`void`>

***

### deleteMessage()

```ts
deleteMessage(message): Promise<void>;
```

Defined in: [packages/bus-core/src/transport/transport.ts:71](https://github.com/node-ts/bus/blob/2e6cf65c27833b707ae31ee623cfb6343770f434/packages/bus-core/src/transport/transport.ts#L71)

Removes a message from the underlying transport. This will be called once a message has been
successfully handled by any of the message handling functions.

#### Parameters

| Parameter | Type | Description |
| ------ | ------ | ------ |
| `message` | [`TransportMessage`](TransportMessage.md)<`TransportMessageType`> | The message to be removed from the transport |

#### Returns

`Promise`<`void`>

***

### disconnect()?

```ts
optional disconnect(): Promise<void>;
```

Defined in: [packages/bus-core/src/transport/transport.ts:98](https://github.com/node-ts/bus/blob/2e6cf65c27833b707ae31ee623cfb6343770f434/packages/bus-core/src/transport/transport.ts#L98)

An optional function that will be called on shutdown. This gives a chance for the transport
to close any connections to the underlying infrastructure.

#### Returns

`Promise`<`void`>

***

### dispose()?

```ts
optional dispose(): Promise<void>;
```

Defined in: [packages/bus-core/src/transport/transport.ts:122](https://github.com/node-ts/bus/blob/2e6cf65c27833b707ae31ee623cfb6343770f434/packages/bus-core/src/transport/transport.ts#L122)

An optional function that will be called when the service bus is shutting down. This is an
opportunity for the transport to close out any open requests to fetch messages etc.

#### Returns

`Promise`<`void`>

***

### fail()

```ts
fail(transportMessage): Promise<void>;
```

Defined in: [packages/bus-core/src/transport/transport.ts:55](https://github.com/node-ts/bus/blob/2e6cf65c27833b707ae31ee623cfb6343770f434/packages/bus-core/src/transport/transport.ts#L55)

Forwards

#### Parameters

| Parameter | Type | Description |
| ------ | ------ | ------ |
| `transportMessage` | [`TransportMessage`](TransportMessage.md)<`unknown`> | to the dead letter queue. The message must have been read in from the queue and have a receipt handle. |

#### Returns

`Promise`<`void`>

***

### initialize()?

```ts
optional initialize(options): Promise<void>;
```

Defined in: [packages/bus-core/src/transport/transport.ts:116](https://github.com/node-ts/bus/blob/2e6cf65c27833b707ae31ee623cfb6343770f434/packages/bus-core/src/transport/transport.ts#L116)

An optional function that will be called when the service bus is starting. This is an
opportunity for the transport to see what messages need to be handled so that subscriptions
to the topics can be created.

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `options` | [`TransportInitializationOptions`](TransportInitializationOptions.md) |

#### Returns

`Promise`<`void`>

***

### prepare()

```ts
prepare(coreDependencies): void;
```

Defined in: [packages/bus-core/src/transport/transport.ts:86](https://github.com/node-ts/bus/blob/2e6cf65c27833b707ae31ee623cfb6343770f434/packages/bus-core/src/transport/transport.ts#L86)

An optional function that is called before startup that will provide core dependencies
to the transport. This can be used to fetch loggers, registries etc that are used
in initialization steps

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `coreDependencies` | [`CoreDependencies`](CoreDependencies.md) |

#### Returns

`void`

***

### publish()

```ts
publish<TEvent>(event, messageOptions?): Promise<void>;
```

Defined in: [packages/bus-core/src/transport/transport.ts:34](https://github.com/node-ts/bus/blob/2e6cf65c27833b707ae31ee623cfb6343770f434/packages/bus-core/src/transport/transport.ts#L34)

Publishes an event to the underlying transport. This is generally done to a topic or some other
mechanism that consumers can subscribe themselves to

#### Type Parameters

| Type Parameter |
| ------ |
| `TEvent` *extends* [`Event`](../../bus-messages/classes/Event.md) |

#### Parameters

| Parameter | Type | Description |
| ------ | ------ | ------ |
| `event` | `TEvent` | A domain event to be published |
| `messageOptions?` | [`MessageAttributes`](../../bus-messages/interfaces/MessageAttributes.md)<[`MessageAttributeMap`](../../bus-messages/interfaces/MessageAttributeMap.md), [`MessageAttributeMap`](../../bus-messages/interfaces/MessageAttributeMap.md)> | Options that control the behaviour around how the message is sent and additional information that travels with it. |

#### Returns

`Promise`<`void`>

***

### readNextMessage()

```ts
readNextMessage(): Promise<
  | TransportMessage<TransportMessageType>
| undefined>;
```

Defined in: [packages/bus-core/src/transport/transport.ts:64](https://github.com/node-ts/bus/blob/2e6cf65c27833b707ae31ee623cfb6343770f434/packages/bus-core/src/transport/transport.ts#L64)

Fetch the next message from the underlying queue. If there are no messages, then `undefined`
should be returned.

#### Returns

`Promise`<
| [`TransportMessage`](TransportMessage.md)<`TransportMessageType`>
| `undefined`>

The message construct from the underlying transport, that includes both the raw message envelope
plus the contents or body that contains the `@node-ts/bus-messages` message.

***

### returnMessage()

```ts
returnMessage(message): Promise<void>;
```

Defined in: [packages/bus-core/src/transport/transport.ts:78](https://github.com/node-ts/bus/blob/2e6cf65c27833b707ae31ee623cfb6343770f434/packages/bus-core/src/transport/transport.ts#L78)

Returns a message to the queue for retry. This will be called if an error was thrown when
trying to process a message.

#### Parameters

| Parameter | Type | Description |
| ------ | ------ | ------ |
| `message` | [`TransportMessage`](TransportMessage.md)<`unknown`> | The message to be returned to the queue for reprocessing |

#### Returns

`Promise`<`void`>

***

### send()

```ts
send<TCommand>(command, messageOptions?): Promise<void>;
```

Defined in: [packages/bus-core/src/transport/transport.ts:46](https://github.com/node-ts/bus/blob/2e6cf65c27833b707ae31ee623cfb6343770f434/packages/bus-core/src/transport/transport.ts#L46)

Sends a command to the underlying transport. This is generally done to a topic or some other
mechanism that consumers can subscribe themselves to

#### Type Parameters

| Type Parameter |
| ------ |
| `TCommand` *extends* [`Command`](../../bus-messages/classes/Command.md) |

#### Parameters

| Parameter | Type | Description |
| ------ | ------ | ------ |
| `command` | `TCommand` | A domain command to be sent |
| `messageOptions?` | [`MessageAttributes`](../../bus-messages/interfaces/MessageAttributes.md)<[`MessageAttributeMap`](../../bus-messages/interfaces/MessageAttributeMap.md), [`MessageAttributeMap`](../../bus-messages/interfaces/MessageAttributeMap.md)> | Options that control the behaviour around how the message is sent and additional information that travels with it. |

#### Returns

`Promise`<`void`>

***

### start()?

```ts
optional start(): Promise<void>;
```

Defined in: [packages/bus-core/src/transport/transport.ts:103](https://github.com/node-ts/bus/blob/2e6cf65c27833b707ae31ee623cfb6343770f434/packages/bus-core/src/transport/transport.ts#L103)

An optional method called on the transport when it should start consuming messages.

#### Returns

`Promise`<`void`>

***

### stop()?

```ts
optional stop(): Promise<void>;
```

Defined in: [packages/bus-core/src/transport/transport.ts:108](https://github.com/node-ts/bus/blob/2e6cf65c27833b707ae31ee623cfb6343770f434/packages/bus-core/src/transport/transport.ts#L108)

An optional method called on the transport when it should no longer consume messages.

#### Returns

`Promise`<`void`>
