Dark Mode

This quick start will get you up and running with a simple command-line Java JMS client that can talk to an Apache Pulsar™ streaming instance. 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

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.AstraTest , so you can just run the JAR file without any additional specifications.

To create the Astra Streaming 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 AstraTest.java and save the file:

In the code example above, note the following points of interest and make the required changes:

  • This is the topic URI the client will use to publish and consume messages. You can create this using the Astra Streaming console. See the Astra Streaming quick start.
  • Your Astra Streaming security token which you can retrieve from the Connect tab for your tenant in the Astra Streaming console. See the Astra Streaming quick start.
  • A properties object containing your topic URI, your Astra Streaming token and the web and broker service URIs from the Connect tab for your tenant in the Astra Streaming console. See the Astra Streaming quick start.
  • 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
  • Pulsar Jms Quickstart Sa: Create a simple command line Java JMS client that connects to a local Pulsar installation.
  • 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*