Getting started: Pub/Sub in Ruby
This guide will get you started with Ably Pub/Sub in a new Ruby application.
You'll establish a realtime connection to Ably and learn to publish and subscribe to messages. You'll also implement presence to track other online clients, and learn how to retrieve message history.
Prerequisites
- Sign up for an Ably account.
- Create a new app, and create your first API key in the API Keys tab of the dashboard.
- Your API key will need the
publish,subscribe,presenceandhistorycapabilities. - Install Ruby version 2.7 or greater.
- Create a new project and install the Ably Pub/Sub Ruby SDK:
Ruby
1
2
3
4
5
6
# Create a new Gemfile
echo "source 'https://rubygems.org'" > Gemfile
echo "gem 'ably-pubsub-server'" >> Gemfile
# Install the gem
bundle installThe realtime interface of the Ruby SDK must be run within an EventMachine reactor which provides an asynchronous evented framework for the library. All functionality within this guide runs within an