Apache Pulsar Adapter Sample

About This Sample

This topic describes how to run the Spotfire Streaming Adapter for Apache Pulsar sample application, which illustrates how to use the adapter to access a Pulsar broker and exchange messages.

For more information on this operator, see Apache Pulsar Adapter.

This sample includes a pair of Pulsar operators, which by default connect to a Pulsar broker named Test Broker, and which is assumed to already be running on localhost. Once connected, use the sample to publish and receive Pulsar messages using the Producer and Consumer operators respectively.

Importing This Sample into StreamBase Studio

In StreamBase Studio, import this sample with the following steps:

  • From the top-level menu, select File>Import Samples and Community Content.

  • Enter pulsar to narrow the list of options.

  • Select Apache Pulsar Adapter from the Messaging category.

  • Click Import Now.

StreamBase Studio creates a single project for the Pulsar Adapter sample.

Running This Sample in StreamBase Studio

  1. Ensure your Pulsar broker is already running on localhost:6650. If your broker is hosted elsewhere, edit the project's src/main/configurations/Pulsar.conf file's broker-uri entry to match.

  2. In the Project Explorer view, open the sample you just loaded.

    If you see red marks on a project folder, wait a moment for the project to load its features.

    If the red marks do not resolve themselves after a minute, select the project, right-click, and select Maven>Update Project from the context menu.

  3. Open the src/main/eventflow/packageName folder.

  4. Open the pulsar.sbapp file and click the Run button. This opens the SB Test/Debug perspective and starts the module.

  5. In the Manual Input view, select the ConsumerIn input stream.

  6. Enter the following values:

    • command: subscribe

    • topic: topic1

    Click Send Data (which causes the adapter to contact the broker and perform the requested subscription operation).

  7. The Output Streams view will report that the ConsumerStatus output port has received a status tuple indicating the success of the subscription operation.

  8. Still in the Manual Input view, select the ProducerIn stream, enter the following values and click Send Data to publish a message:

    • topic: topic1

    • key: key1

    • message.myInt: 42

    • message.myStr: forty-two

  9. The message will be published by the Producer to topic topic1 and the Consumer operator will receive the message and emit it on its ConsumerResults stream, as evidenced in the Output Streams view.

  10. Unsubscribe your consumer from the topic by selecting the Manual Input view's ConsumerIn stream, entering the following values and clicking Send Data:

    • command: unsubscribe

  11. When done, press F9 or click the Terminate EventFlow Fragment button.

This Sample's Files

This sample contains the following files:

pulsar.sbapp

Sample EventFlow application.

Pulsar.conf

Used to configure the connection to the Pulsar broker.

Sample Location

When you load the sample into StreamBase® Studio, Studio copies the sample project's files to your Studio workspace, which is normally part of your home directory, with full access rights.

Important

Load this sample in StreamBase® Studio, and thereafter use the Studio workspace copy of the sample to run and test it, even when running from the command prompt.

Using the workspace copy of the sample avoids permission problems. The default workspace location for this sample is:

studio-workspace/sample/adapter/embedded/pulsar

See Default Installation Directories for the default location of studio-workspace on your system.