# IMessageQueue.publish() method · @imqueue/core

Source: https://imqueue.org/api/core/latest/core.imessagequeue.publish/
Published: 2026-08-04
Author: @imqueue maintainers (https://github.com/imqueue)
Package: @imqueue/core 3.3.2 — generated reference, not hand-written

Publishes data to the current queue channel

If toName is specified, publishes to a pubsub with a different name. This can be used to broadcast messages to other subscribers on different pubsub channels. Different names must be in the same namespace (same imq prefix).

**Signature:**

```typescript
publish(data: JsonObject, toName?: string): Promise<void>;
```

## Parameters


| Parameter | Type | Description |
| --- | --- | --- |
| data | [JsonObject](https://imqueue.org/api/core/latest/core.jsonobject/) | data to publish as a channel message |
| toName | string | _(Optional)_ optional different pubsub name to publish to |


**Returns:**

Promise<void>

## Exceptions

TypeError when the queue has no writer connection

## Remarks

Unlike [IMessageQueue.send()](https://imqueue.org/api/core/latest/core.imessagequeue.send/), this does not start the queue implicitly — [IMessageQueue.start()](https://imqueue.org/api/core/latest/core.imessagequeue.start/) must have completed first. The payload is always plain JSON ([IMQOptions.useGzip](https://imqueue.org/api/core/latest/core.imqoptions.usegzip/) does not apply), and pub/sub delivery is not persisted, so subscribers that are not connected at publish time never receive the message.

