Pulsar client with Astra Streaming

This guide assumes you have completed the Astra Streaming quickstart and you have set up your Pulsar binaries to work with your tenant.

Now it’s time to produce and consume messages in your new streaming tenant.

Set the required variables. If you’ve just completed the quickstart, these values are already set.

TOPIC="my-topic"
NAMESPACE="my-namespace"
TENANT="my-stream-<rand>" #replace <rand> with a few alphanumeric characters

Run the following script to create 1 new message.

# Produce a new message on the given tenant/namespace/topic
./bin/pulsar-client produce \
    "$TENANT/$NAMESPACE/$TOPIC" \
    --messages "Hi there" \
    --num-produce 1

Now you have a new, unacknowledged message in your topic.

Run the following script to create a consumer that retrieves and acknowledges that message.

# Consume a new message on the given tenant/namespace/topic
./bin/pulsar-client consume \
    "$TENANT/$NAMESPACE/$TOPIC" \
    --subscription-name "examples-subscriber" \
    --num-messages 1

The output should look similar to this:

# consumer message output
----- got message -----
key:[null], properties:[], content:Hi there
2023-01-09T14:32:40,502-0500 [pulsar-client-io-1-1] INFO  org.apache.pulsar.client.impl.ConsumerImpl - [new-tenant-from-cli/default/demo] [examples-subscriber] Closed consumer
2023-01-09T14:32:40,504-0500 [main] INFO  org.apache.pulsar.client.impl.PulsarClientImpl - Client closing. URL: pulsar+ssl://pulsar-aws-useast2.streaming.datastax.com:6651
2023-01-09T14:32:40,514-0500 [pulsar-client-io-1-1] INFO  org.apache.pulsar.client.impl.ClientCnx - [id: 0x08d05240, L:/192.168.50.167:52883 ! R:pulsar-aws-useast2.streaming.datastax.com/3.138.177.230:6651] Disconnected
2023-01-09T14:32:40,520-0500 [pulsar-client-io-1-1] INFO  org.apache.pulsar.client.impl.ClientCnx - [id: 0x934157ae, L:/192.168.50.167:52884 ! R:pulsar-aws-useast2.streaming.datastax.com/3.138.177.230:6651] Disconnected
2023-01-09T14:32:42,613-0500 [main] INFO  org.apache.pulsar.client.cli.PulsarClientTool - 1 messages successfully consumed

If you made it here then your produce & consume journey was successful. Congrats🎉! Now it’s time to take your skills further 🚀🚀.

Was this helpful?

Give Feedback

How can we improve the documentation?

© 2024 DataStax | Privacy policy | Terms of use

Apache, Apache Cassandra, Cassandra, Apache Tomcat, Tomcat, Apache Lucene, Apache Solr, Apache Hadoop, Hadoop, Apache Pulsar, Pulsar, Apache Spark, Spark, Apache TinkerPop, TinkerPop, Apache Kafka and Kafka are either registered trademarks or trademarks of the Apache Software Foundation or its subsidiaries in Canada, the United States and/or other countries. Kubernetes is the registered trademark of the Linux Foundation.

General Inquiries: +1 (650) 389-6000, info@datastax.com