# serve_zmq

Listens on a ZeroMQ endpoint and sends events.

```tql
serve_zmq endpoint:string, encoding=string, [prefix=string, monitor=bool]
```

## Description

Binds a ZeroMQ `PUB` socket to the specified endpoint and publishes one message per input event.

The operator serializes each event with the selected `encoding` and optionally prepends a prefix to the serialized bytes before publishing the message. This lets subscribers use ZeroMQ’s native prefix filtering while keeping the event payload available to a `read_*` operator on the receiving side.

Use `serve_zmq` when Tenzir should own the listening endpoint. This mirrors the transport-oriented naming used by operators such as [`serve_tcp`](https://preview.docs.tenzir.com/375/375/reference/operators/serve_tcp.md).

### `endpoint: string`

The endpoint to listen on, for example `tcp://0.0.0.0:5555`, `ipc://path`, or `inproc://name`.

### `encoding = string`

The encoding to use when serializing input events into ZeroMQ message payloads.

Use the same format names that you would otherwise select with a `write_*` operator, for example `json`, `ndjson`, `csv`, or `yaml`.

### `prefix = string (optional)`

An expression that evaluates to the prefix to prepend to each published message.

This expression may depend on event fields. The operator evaluates it for every input event.

### `monitor = bool (optional)`

Waits for the first peer connection before publishing messages on TCP transports.

## Examples

### Listen and publish JSON

```tql
export
serve_zmq "tcp://0.0.0.0:5555", encoding="json"
```

### Publish with a dynamic prefix

```tql
export
serve_zmq "tcp://0.0.0.0:5555", encoding="json", prefix=f"{kind}/"
```

## See Also

* [`to_zmq`](https://preview.docs.tenzir.com/375/375/reference/operators/to_zmq.md)
* [`from_zmq`](https://preview.docs.tenzir.com/375/375/reference/operators/from_zmq.md)
* [`accept_zmq`](https://preview.docs.tenzir.com/375/375/reference/operators/accept_zmq.md)
* [`to_zmq`](https://preview.docs.tenzir.com/375/375/reference/operators/to_zmq.md)
* [ZeroMQ](https://preview.docs.tenzir.com/375/375/integrations/zeromq.md)