Code Monkey home page Code Monkey logo

pulsar-client-ruby's Introduction

Apache Pulsar Ruby client

Installation

Add this line to your application's Gemfile:

gem "pulsar-client", "~> 2.6.1.pre"

And then execute:

$ bundle

Or install it yourself as:

$ gem install pulsar-client --pre

Note #1: You will need libpulsar (for linking) and libpulsar-dev (for C++ client header files, for compiling) installed first. For both, the Gem currently targets version 2.6.1. If your libpulsar is older, it will fail to compile. If it is newer, it might compile is not guaranteed.

Note #2: This is a pre-release version of this Gem. You will need the --pre flag to gem install to install it manually, and must include the .pre suffix in the Gemfile to install it via Bundler.

Usage

Setup and basic consumer.receive example:

# use a standard Pulsar client config (see https://github.com/apache/pulsar/blob/master/conf/client.conf)
# export PULSAR_CLIENT_CONF=/path/to/your/client/conf/client_conf.conf
# OR, if not present have these in your shell with appropriate values
# export PULSAR_BROKER_URI=pulsar://your-pulsar-broker:6651
# export PULSAR_CERT_PATH=/path/to/your/pulsar-ca.pem
# export PULSAR_AUTH_TOKEN=your-auth-token
# export PULSAR_AUTH_OAUTH2_PARAMS=your-oauth2-params

# create client using values from environment
client = Pulsar::Client.from_environment

# produce a message on the "hello-world" topic in the "namespace"
# namespace of the "tenant" tenant
topic = "tenant/namespace/topic"
producer = client.create_producer(topic)
producer.send("Hello, world!")

# consumer that message from the topic with an exclusive subscription
# named "hello-consumer"
subscription = "hello-consumer"
consumer = client.subscribe(topic, subscription)

msg = consumer.receive
message = msg.data
puts "got #{message}"
consumer.acknolwedge(msg)

Convenience method for listening to messages in a loop:

consumer.listen do |message, _, done|
  # process message here; call done to stop the loop.
  # messages are auto-acknowledged.
  puts "got #{message}"
  done.call()
end

Convenience method for listening on a separate thread:

listenerThread = consumer.listen_in_thread do |message, _, done|
  # process message here; call done to stop the loop.
  # messages are auto-acknowledged.
  puts "got #{message}"
  done.call()
end
# ...
listenerThread.join # wait for the thread to finish

(more documentation coming; see TODO.md)

Development

If your ruby is not already compiled with --enable-shared, you'll need to rebuild it. Example for rbenv:

CONFIGURE_OPTS="--enable-shared" rbenv install <your ruby version>

If you don't already have them installed, you need libpulsar and automake for the compilation and linking to work. Example with brew:

brew install libpulsar automake

Next, run bin/setup to install dependencies -- Rice in particular. Once that successfully completes, you can rake compile to build the extension. It is then ready to use locally.

You can run bin/console for an interactive prompt that will allow you to experiment. You can also run rake spec to run the tests.

To install this gem onto your local machine, run bundle exec rake install.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/apache/pulsar-client-ruby or https://github.com/instructure/pulsar-client-ruby.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.