Clients
Connect to Pulsar cluster using WebSocket API
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
andconsume
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
-
Connect to the Pulsar cluster.
Replace the
CLUSTER_HOST
parameter with the domain name of the cluster. -
Create a consumer and use the consumer to consume messages.
-
Create a producer and use the producer to produce messages.