Getting Started with containers

Published: February 22, 2022

Prerequisites

You’re going to need virtualization enabled on your desktop and a container runtime. Options like Docker and containerd are a great choice.

Steps

Start a standalone broker

1
docker run -d -p 6650:6650 -p 8080:8080 --name pulsar apachepulsar/pulsar:latest bin/pulsar standalone

Get the Pulsar binaries

Pulsar is developed for 64-bit Java. To run the binaries you need either the Java Runtime Environment(JRE) or Java Developer Kit(JDK) version 8 or later installed. Installers and more info available here.

With a Java environment in place, all popular 64-bit desktops are supported - Windows, Linux, and MacOS. The tarball is around 300mb, so please be patient while downloading.

Send a message to the Broker

Otherwise known as producing a message. Pulsar will create a new topic (if it doesn’t already exist) named “my-first-topic”.

1
./bin/pulsar-client --url "pulsar://localhost:6650/default/public/" produce "my-first-topic" --messages "Hello there"

There will be quite a bit of feedback output to the screen. Upon a successful publish, the last line should be…

[main] INFO org.apache.pulsar.client.cli.PulsarClientTool - 1 messages successfully produced

Get messages from the Broker

Otherwise known as consuming messages. Similar to producing, if the topic does not exists Pulsar will create it.

1
./bin/pulsar-client --url "pulsar://localhost:6650/default/public/" consume "my-first-topic" -s "my-subscription"

There will be quite a bit of feedback output to the screen. Upon a successful connection, the last line should be…

[main] INFO org.apache.pulsar.client.cli.PulsarClientTool - 1 messages successfully consumed

Stop the Broker

If you chose to run the Broker in the current thread Ctrl+c will stop the process. To stop the background process:

Summary

It doesn’t get any easier than that! You’ve successfully started a Pulsar instance, produced messages, and consumed messages. Let’s move on to something a little more challenging.

Troubleshooting

Error: JAVA_HOME not set, and no java executable found in…

The JAVA_HOME environment variable is a way of interacting with the runtime. Usually when this value is not set, that indicates there is no Java environment installed. Refer to the prerequisites.

Popup window: How do you want to open this file?

This is a popup that appears in Windows when you try to execute an unknown type of binary. Refer to the prerequisites to install the Java environment.