8000 GitHub - ably/ably-ruby: Ruby client library SDK for Ably realtime messaging service
[go: up one dir, main page]

Skip to content

ably/ably-ruby

Repository files navigation

Ably Pub/Sub Ruby SDK

Ably Pub/Sub Ruby Header Gem Version Coverage Status License


Build any realtime experience using Ably’s Pub/Sub Ruby SDK, Supported on all popular platforms and frameworks.

Ably Pub/Sub provides flexible APIs that deliver features such as pub-sub messaging, message history, presence, and push notifications. Utilizing Ably’s realtime messaging platform, applications benefit from its highly performant, reliable, and scalable infrastructure.

Find out more:


Getting started

Everything you need to get started with Ably:


Supported platforms

Ably aims to support a wide range of platforms and browsers. If you experience any compatibility issues, open an issue in the repository or contact Ably support.

Platform Support
Ruby >= 2.7 and 3.x. For EventMachine compatibility with Ruby 3.x
EventMachine Required for using the Realtime API. Compatible with Ruby 3.x with OpenSSL configuration.
libcurl Required since v1.1.5. On Debian-based systems, install via sudo apt-get install libcurl4.

Important

SDK versions < 1.2.5 will be deprecated from November 1, 2025.


Installation

To get started with your project, install the package:

# Create a new Gemfile
echo "source 'https://rubygems.org'" > Gemfile
echo "gem 'ably'" >> Gemfile


# Install the gem
bundle install

Note

Install Ruby version 2.7 or greater.


EventMachine

To use the Ably Realtime SDK in Ruby, the EventMachine reactor loop must be running. This is required because the Realtime library depends on EventMachine to handle asynchronous events.

Wrap your code inside a EventMachine.run block:

require 'ably'

EventMachine.run do
  client = Ably::Realtime.new(key: 'your-api-key')

  client.connection.connect do
    puts "Connected with connection ID: #{client.connection.id}"
  end

Usage

The following code connects to Ably's realtime messaging service, subscribes to a channel to receive messages, and publishes a test message to that same channel.

  # Initialize Ably Realtime client
  realtime_client = Ably::Realtime.new(key: 'your-ably-api-key', client_id: 'me')
  
  # Wait for connection to be established
  realtime_client.connection.on(:connected) do
    puts 'Connected to Ably'
    
    # Get a reference to the 'test-channel' channel
    channel = realtime_client.channels.get('test-channel')
    
    # Subscribe to all messages published to this channel
    channel.subscribe do |message|
      puts "Received message: #{message.data}"
    end
    
    # Publish a test message to the channel
    channel.publish 'test-event', 'hello world'
  end
end

Releases

The CHANGELOG.md contains details of the latest releases for this SDK. You can also view all Ably releases on changelog.ably.com.


Contributing

Read the CONTRIBUTING.md guidelines to contribute to Ably.


Support, feedback and troubleshooting

For help or technical support, visit Ably's support page. You can also view the community reported Github issues or raise one yourself.

About

Ruby client library SDK for Ably realtime messaging service

Topics

Resources

License

Stars

Watchers

Forks

Contributors 21

0