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

# Class: InMemoryQueue

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

An in-memory message queue. This isn't intended for production use as all messages
are kept in memory and hence will be wiped when the application or host restarts.

There are however legitimate uses for in-memory queues such as decoupling of non-mission
critical code inside of larger applications; so use at your own discretion.

## Implements

* [`Transport`](../interfaces/Transport.md)<[`InMemoryMessage`](../interfaces/InMemoryMessage.md)>

## Constructors

### Constructor

```ts
new InMemoryQueue(memoryQueueConfiguration?): InMemoryQueue;
```

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

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `memoryQueueConfiguration` | [`InMemoryQueueConfiguration`](../interfaces/InMemoryQueueConfiguration.md) |

#### Returns

`InMemoryQueue`

## Accessors

### deadLetterQueue

#### Get Signature

```ts
get deadLetterQueue(): TransportMessage<InMemoryMessage>[];
```

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

Returns all messages sitting in the dead letter queue. This is a copy of the queue
so mutative actions on this array will have no consequence.

##### Returns

[`TransportMessage`](../interfaces/TransportMessage.md)<[`InMemoryMessage`](../interfaces/InMemoryMessage.md)>\[]

***

### deadLetterQueueDepth

#### Get Signature

```ts
get deadLetterQueueDepth(): number;
```

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

##### Returns

`number`

***

### depth

#### Get Signature

```ts
get depth(): number;
```

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

Gets the queue depth, which is the number of messages both queued and in flight

##### Returns

`number`

***

### numberMessagesVisible

#### Get Signature

```ts
get numberMessagesVisible(): number;
```

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

Gets the number of messages in the queue, excluding those in flight

##### Returns

`number`

## Methods

### deleteMessage()

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

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

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`](../interfaces/TransportMessage.md)<[`InMemoryMessage`](../interfaces/InMemoryMessage.md)> | The message to be removed from the transport |

#### Returns

`Promise`<`void`>

#### Implementation of

[`Transport`](../interfaces/Transport.md).[`deleteMessage`](../interfaces/Transport.md#deletemessage)

***

### dispose()

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

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

Cancels pending retries and reads so that the queue doesn't keep the process alive

#### Returns

`Promise`<`void`>

#### Implementation of

[`Transport`](../interfaces/Transport.md).[`dispose`](../interfaces/Transport.md#dispose)

***

### fail()

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

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

Forwards

#### Parameters

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

#### Returns

`Promise`<`void`>

#### Implementation of

[`Transport`](../interfaces/Transport.md).[`fail`](../interfaces/Transport.md#fail)

***

### initialize()

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

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

Records which messages have local handlers. Messages without one are discarded when sent.

#### Parameters

| Parameter | Type | Description |
| ------ | ------ | ------ |
| `options?` | [`TransportInitializationOptions`](../interfaces/TransportInitializationOptions.md) | the handler registry of the bus |

#### Returns

`Promise`<`void`>

#### Implementation of

[`Transport`](../interfaces/Transport.md).[`initialize`](../interfaces/Transport.md#initialize)

***

### prepare()

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

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

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`](../interfaces/CoreDependencies.md) |

#### Returns

`void`

#### Implementation of

[`Transport`](../interfaces/Transport.md).[`prepare`](../interfaces/Transport.md#prepare)

***

### publish()

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

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

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`>

#### Implementation of

[`Transport`](../interfaces/Transport.md).[`publish`](../interfaces/Transport.md#publish)

***

### readNextMessage()

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

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

Returns the next visible message. If none are visible, waits until one becomes visible or
`receiveTimeoutMs` elapses, in which case undefined is returned.

#### Returns

`Promise`<
| [`TransportMessage`](../interfaces/TransportMessage.md)<[`InMemoryMessage`](../interfaces/InMemoryMessage.md)>
| `undefined`>

#### Implementation of

[`Transport`](../interfaces/Transport.md).[`readNextMessage`](../interfaces/Transport.md#readnextmessage)

***

### returnMessage()

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

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

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`](../interfaces/TransportMessage.md)<[`InMemoryMessage`](../interfaces/InMemoryMessage.md)> | The message to be returned to the queue for reprocessing |

#### Returns

`Promise`<`void`>

#### Implementation of

[`Transport`](../interfaces/Transport.md).[`returnMessage`](../interfaces/Transport.md#returnmessage)

***

### send()

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

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

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`>

#### Implementation of

[`Transport`](../interfaces/Transport.md).[`send`](../interfaces/Transport.md#send)
