Search Results

Apache Pulsar Go Quick Start

Contents

Getting Started

This quick start guide provides basic instructions for writing Apache Pulsar applications in Go for TIBCO Cloud Messaging.

Building and running samples

Follow the steps below to build and run the Go samples. The Go samples are implemented as a Go module. Dependencies are defined in the included go.mod files.

The Pulsar Go SDK requires GCC to compile (CGO).

Linux and macOS

  • Unzip pulsar-go-samples.zip
  • Change into module directory: cd pulsar-go-samples/tcm/samples/pulsar
  • Set GOBIN: export GOBIN=$PWD/bin
  • Generate vendor directory: go mod tidy then go mod vendor
  • Build and install binaries: go install tibco.com/tcm/samples/pulsar...
  • Use -f option to specify the configuration file.
  • Run samples: $GOBIN/pulsar_consumer -f <path-to>/tcm-config.yaml

Windows

  • Ensure you have mingw64 (5.3 or later) installed and gcc in your PATH
  • Unzip pulsar-go-samples.zip
  • Change into module directory: cd pulsar-go-samples\tcm\samples\pulsar
  • Set GOBIN: set GOBIN=%CD%\bin
  • Generate vendor directory: go mod tidy then go mod vendor
  • Build and install binaries: go install tibco.com/tcm/samples/pulsar...
  • Use -f option to specify the configuration file
  • Run samples: %GOBIN%\pulsar_consumer -f <path-to>\tcm-config.yaml

Description of sample applications

Producer

The producer demonstrates connecting an Apache Pulsar Go application to Cloud Messaging and publishing Pulsar messages on a topic:

pulsar_producer:
  -T string
    	topic to send on (default "demo_tcm")
  -c int
    	the number of messages to send before exiting (default -1)
  -f string
    	the path to a configuration yaml (default "tcm-config.yaml")
  -i duration
    	the duration between sends, e.g. 500ms, 1s, etc. (default 1s)
  -id string
    	client identifier (default "pulsar_producer")
  -t duration
    	duration before timeout, e.g. 1h, 5m, 10s, etc.

Consumer

The consumer demonstrates connecting an Apache Pulsar Go application to Cloud Messaging, creating a subscription, and receiving Pulsar messages on a topic:

pulsar_consumer:
  -S string
    	subscription name (default "demo_tcm_sub")
  -T string
    	topic to consume (default "demo_tcm")
  -c int
    	the number of messages received before exiting (default -1)
  -f string
    	the path to a configuration yaml (default "tcm-config.yaml")
  -id string
    	client identifier (default "pulsar_consumer")
  -latest
    	set subscription position to 'latest'
  -subtype string
    	set subscription type to 'shared', 'exclusive' or 'failover' (default "shared")
  -t duration
    	duration before timeout, e.g. 500ms, 10s, etc.

Connecting to TIBCO Cloud Messaging

The client configuration file contains all the information client applications need to securely connect to TIBCO Cloud Messaging. Generate the client configuration file using the roles REST API or user interface. Generate as many configuration files as needed for each Role.

Note: TIBCO Cloud Messaging samples require a client configuration file to run.

Connection Example

auth := pulsar.NewAuthenticationToken(options.AuthKey)
client, err := pulsar.NewClient(pulsar.ClientOptions{URL: options.PulsarURL, Authentication: auth})