Skip to content

Getting Started

Scott Hill edited this page Jul 21, 2020 · 4 revisions

Getting Started

Subserver can be used with any ruby app but takes special care to integrate with Rails.

Rails

  1. Add Subserver to your Gemfile:
gem 'subserver'
  1. Add a Subscriber in app/subscribers to process messages asynchronously:
class TestSubscriber
  include Subserver::Subscriber
  subserver_options subscription: 'your-gcloud-subscription-name'

  def perform(message)
    # do something with message
    message.acknowledge!
  end
end
  1. Add configuration file `config/subserver.yml' to add Google Cloud credentials
---
project_id: 'subserver-test-id'
credentails: 'path/to/credentails.json'

Note: Subserver respects Google's Credential Enviroment variables like PUBSUB_PROJECT and GOOGLE_APPLICATION_CREDENTIALS. If no config is provided the default env varriables will be used. See Google's authentication guide for more info.

  1. Start subserver from the root of your Rails application so the jobs will be processed:
bundle exec subserver

Plain Ruby

Plain ruby applications can follow the same setup as the Rails application. Simply put your Subscriber classes in the ./subscribers directory and your config file in ./config/subserver.yml.

Next: Configuration

Clone this wiki locally