Pub/sub - REST API

Overview

Before making use of the REST pub/sub API, a REST endpoint needs to be created with HTTP Basic Auth credentials and appropriate permissions.

REST integration with publish/subscribe is built around two cornerstone operations:

OperationREST
PublishingPOST /pubsub/topic/{topic_name}
Getting messages from queuesPOST /pubsub/messages/get
  • To make use of any of these endpoints, a REST client must use HTTP Basic Auth credentials previously assigned to it by Zato admins

  • REST clients can subscribe to topics if they have proper subscription permissions. Subscribing to the same topic multiple times is safe and has no effect. All messages from all subscribed topics are delivered to a single queue per user.

    • REST clients receive their messages in one of two ways:
      • Pull-style: clients call /pubsub/messages/get to retrieve messages on demand
      • Push-style: Zato delivers messages to configured REST endpoints as soon as they arrive

OpenAPI definition

  • In your Dashboard at http://localhost:8183, click EDA → Download OpenAPI to download the complete specification of the interface, for instance, to generate API clients from it, or to use it with tools such as Postman

  • You can also download the specification from GitHub

Demo credentials, topics and subscriptions

  • In your Dashboard at http://localhost:8183, click EDA → Import test config to auto-configure demo credentials, and a few topics, so that you can quickly try out the REST API

  • The demo credentials are user.1/password.1

  • Note that the test config does not survive container restarts and it's meant to be used during development and testing, for your convenience, but the configuration is real, your actual credentials or topics will look similarly

Publishing messages

Topic name must be provided in the URL path. Message data and optional parameters are given as JSON payload.

VerbURL
POST/pubsub/topic/{topic_name}

Request

ParameterDatatypeRequiredNotes
dataanyYesActual data of the message that is being published. Can be a string or a JSON object.
priorityinteger---Message priority from 0 to 9 (0=lowest, 9=highest). Defaults to 5 if not given.
expirationinteger---Expiration in seconds. Defaults to 31536000 (1 year) if not given.
correl_idstring---Correlation ID for message tracking.
in_reply_tostring---ID of message this is replying to.
ext_client_idstring---External client identifier for logging and audit purposes.
pub_timestring---Custom publication time in ISO format with timezone (e.g., "2025-01-01T12:00:00+00:00"). Server sets to current time if not provided.

Response

ParameterDatatypeRequiredNotes
is_okbooleanYesWhether the operation succeeded
cidstringYesCorrelation ID for request tracking
msg_idstringYesUnique message ID
statusstringYesHTTP status description (e.g., "200 OK")

Samples

OK, data sent and message ID returned:

$ curl -XPOST http://user.1:password.1@localhost:11223/pubsub/topic/orders.processed \
  -d '{"data":"Order #12345 has been processed", "priority": 7}'
{
  "is_ok": true,
  "cid": "correlation-id-123",
  "msg_id": "zpsm.20250829-074432-7264-d47439a9f-abc",
  "status": "200 OK"
}
$

Error, no data sent on input:

$ curl -XPOST http://user.1:password.1@localhost:11223/pubsub/topic/orders.processed \
  -d '{}'
{
  "is_ok": false,
  "cid": "correlation-id-456",
  "details": "Invalid request data",
  "status": "400 Bad Request"
}
$

Getting messages from queues

Messages from all subscribed topics are retrieved through a single endpoint. Optional parameters control the number and size of messages returned.

VerbURL
POST/pubsub/messages/get

Request

ParameterDatatypeRequiredNotes
max_messagesinteger---Maximum number of messages to retrieve. Defaults to 50, maximum is 1000.
max_leninteger---Maximum total length of message data in bytes. Defaults to 5000000 (5 MB), which is also the maximum value.

Response

ParameterDatatypeRequiredNotes
is_okbooleanYesWhether the operation succeeded
cidstringYesCorrelation ID for request tracking
messagesarray---Array of messages (possibly empty if none were enqueued)
dataany---Message data (present for single message response)
metaobject---Message metadata (present for single message response)
message_countintegerYesNumber of messages returned
statusstringYesHTTP status description (e.g., "200 OK")

Message metadata fields

FieldDatatypeNotes
topic_namestringTopic the message was published to
sizeintegerMessage size in bytes
priorityintegerMessage priority (0-9)
expirationintegerMessage expiration time in seconds
msg_idstringUnique message identifier
correl_idstringCorrelation ID for message tracking
pub_time_isostringWhen the message was published (ISO format with timezone)
recv_time_isostringWhen the message was received by the system (ISO format with timezone)
expiration_time_isostringWhen the message will expire (ISO format with timezone)
time_since_pubstringTime elapsed since message was published (duration format)
time_since_recvstringTime elapsed since message was received (duration format)
ext_client_idstringExternal client identifier (optional)
in_reply_tostringID of message this is replying to (optional)

Samples

OK, multiple messages returned:

$ curl -XPOST http://user.1:password.1@localhost:11223/pubsub/messages/get \
  -d '{"max_messages": 5}'
{
  "is_ok": true,
  "cid": "correlation-id-789",
  "messages": [
    {
      "data": {
        "order_id": 12345,
        "status": "completed"
      },
      "meta": {
        "topic_name": "orders.processed",
        "size": 45,
        "priority": 5,
        "expiration": 3600,
        "msg_id": "zpsm.20250829-074432-7264-d47439a9f-abc",
        "correl_id": "order-12345",
        "pub_time_iso": "2025-01-01T12:00:00+00:00",
        "recv_time_iso": "2025-01-01T12:00:01+00:00",
        "expiration_time_iso": "2025-01-01T13:00:00+00:00",
        "time_since_pub": "0:00:30.123456",
        "time_since_recv": "0:00:30.123456"
      }
    }
  ],
  "message_count": 1,
  "status": "200 OK"
}
$

OK, no messages available:

$ curl -XPOST http://user.1:password.1@localhost:11223/pubsub/messages/get
{
  "is_ok": true,
  "cid": "correlation-id-101",
  "messages": [],
  "message_count": 0,
  "status": "200 OK"
}
$

Error, no subscription found for user:

$ curl -XPOST http://user.1:password.1@localhost:11223/pubsub/messages/get
{
  "is_ok": false,
  "cid": "correlation-id-102",
  "details": "No subscription found for user",
  "status": "401 Unauthorized"
}
$

Data format

  • All requests and responses use JSON format
  • Authentication is always with HTTP Basic Auth
  • All responses include an is_ok boolean field indicating success or failure
  • All responses include a cid field for correlation tracking
  • Error responses include a details field with error description
  • Success responses include a status field with HTTP status description

Success response example:

{
  "is_ok": true,
  "cid": "correlation-id-123",
  "status": "200 OK"
}

Error response example:

{
  "is_ok": false,
  "cid": "correlation-id-456",
  "details": "Authentication failed",
  "status": "401 Unauthorized"
}

Topic name restrictions

  • Maximum length: 200 characters
  • Only ASCII characters are permitted
  • The "#" character is not allowed
  • Topic names are case-insensitive

Getting started with EDA

Using EDA