Dark Mode

This quick start will get you up and running with a simple command-line Java JMS client that can talk to a local Apache Pulsar™ installation. The client:

  • Initializes a undefined queue.
  • Attaches a message listener to that queue.
  • Produces 10 messages that are then consumed and printed out in an onMessage callback.

Prerequisites

To install a Docker Pulsar instance:

  • Make sure you have Docker installed on your platform.
  • Open a terminal and create a Pulsar Docker instance:

You've now got a Pulsar instance up and running.

We'll use Apache Maven to handle dependency management so you don't have to manually download and install required libraries.

  • Create a project directory in a convenient location.
  • Save the following file as pom.xml in your project directory.

Note the following elements:

  • The main name for the compiled JAR file.
  • The undefined dependency. In this case we're using a "fat" JAR file, pulsar-jms-all , that includes all dependencies.
  • The Log4J dependency.
  • An additional descriptor appended to the JAR file name.
  • The default package and class, example.StandaloneTest , so you can just run the JAR file without any additional specifications.

To create the standalone example app:

  • In the project directory you created above, create the following directory hierarchy, <project-directory>/src/main/java/example :
  • Copy the following code into a file named StandaloneTest.java and save the file:

In the code example above, note the following points of interest:

  • The topic URI the client will use to publish and consume messages. We're using the default tenant and namespace here, but you can call the topic itself anything you like and it will be auto-created.
  • Creates an empty properties hashmap. Refer to Pulsar Jms Reference for additional undefined configuration options.
  • Creates a undefined queue. For more information on mapping Pulsar to JMS concepts, see Pulsar Jms Mappings.
  • Creates a undefined consumer context using the createConsumer method...
  • ... and initializes an onMessage callback to consume the messages as they arrive.
  • Sends 10 "Hello World!" messages to the queue using the createProducer method.
  • Sleeps for 10 seconds to make sure all of the messages are consumed.

To compile the sample application:

  • Change to the <product_directory .
  • Run the maven command:

To run the sample app, from the <product_directory :

  • 1

Results:

  • 1

Once you're done, you can use Ctrl-C to terminate the Pulsar Docker instance running in your terminal.

To delete the Pulsar Docker container:

  • Get a list of all Docker containers and note the container ID ( 5116f0d16eb3 in the example):
  • Delete the container using the container ID:
  • Pulsar Jms Quickstart Astra: Create a simple command line Java JMS client that connects to an Astra Streaming instance.
  • Pulsar Jms Install: Install undefined in your own JMS project.
  • Pulsar Jms Mappings: Understand Pulsar concepts in the context of JMS.Pulsar Jms Implementation: Understand key implementation details for undefined.
  • Pulsar Jms Faq: Frequently asked questions about undefined.
  • Pulsar Jms Reference: undefined configuration reference.
  • *undefined Github repo*