# BusInstance

A configured instance of a bus used to publish messages.

## Properties

### beforeSend

See [Lifecycle hooks](/guide/lifecycle-hooks.md).

### beforePublish

See [Lifecycle hooks](/guide/lifecycle-hooks.md).

### onError

See [Lifecycle hooks](/guide/lifecycle-hooks.md).

### afterReceive

See [Lifecycle hooks](/guide/lifecycle-hooks.md).

### beforeDispatch

See [Lifecycle hooks](/guide/lifecycle-hooks.md).

### afterDispatch

See [Lifecycle hooks](/guide/lifecycle-hooks.md).

### state

Gets the current state of the bus to see if it's started or stopped.

## Methods

### publish(event, \[messageAttributes])

Publishes an event to the bus, with an optional set of attributes to attach to the outgoing message.

#### Arguments

<table><thead><tr><th width="220.36412604232706">Argument</th><th width="342.81368434354914">Description</th><th width="150">Default</th></tr></thead><tbody><tr><td><code>event</code></td><td>The message to publish to the underlying transport</td><td>None</td></tr><tr><td><code>messageAttributes</code></td><td>An optional set of attributes that will be sent with the outgoing event</td><td>None</td></tr></tbody></table>

### send(command, \[messageAttributes])

Sends a command to the bus, with an optional set of attributes to attach to the outgoing message.

#### Arguments

<table><thead><tr><th width="220.36412604232706">Argument</th><th width="342.81368434354914">Description</th><th width="150">Default</th></tr></thead><tbody><tr><td><code>command</code></td><td>A message to send to the underlying transport</td><td>None</td></tr><tr><td><code>messageAttributes</code></td><td>An optional set of attributes that will be sent with the outgoing</td><td>None</td></tr></tbody></table>

### fail()

Instructs the bus that the current message being handled cannot be processed even with retries and instead should immediately be routed to the dead letter queue.

### start()

Instructs the bus to start reading messages from the underlying service queue and dispatching to message handlers.

### stop()

Stops a bus that has been started by `.start()`. This will wait for all running workers to complete their current message handling contexts before returning.

### dispose()

Stops and disposes all resources allocated to the bus, as well as removing all handler registrations. The bus instance cannot be used after this has been called.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://bus.node-ts.com/reference/businstance.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
