Skip to main content
This example shows how to use the WebSocket API to connect to a Pulsar cluster and then produce and consume messages to and from the Pulsar cluster.
  • This document assumes that you have created a service account, and have granted the service account produce and consume permissions to the namespace for the target topic.
  • To use the WebSocket API to connect to a Pulsar cluster, you need to enable the WebSocket service in advance. For details, see enable WebSocket service.
  • If Web Socket Secure (WSS) protocol is used, you should use the port 9443.

Prerequisites

Steps

  1. Connect to the Pulsar cluster.
    Replace the CLUSTER_HOST parameter with the domain name of the cluster.
  2. Create a consumer and use the consumer to consume messages.
  3. Create a producer and use the producer to produce messages.