Skip to content

Commit 494f89b

Browse files
author
Adam Eberlin
committed
Update README, generator, fixtures, etc.
1 parent ac9e5fd commit 494f89b

File tree

4 files changed

+49
-2
lines changed

4 files changed

+49
-2
lines changed

README.md

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ gem 'pusher'
5959
gem 'sync'
6060
```
6161

62+
#### Using STOMP
63+
64+
```ruby
65+
gem 'stomp'
66+
gem 'sync'
67+
```
68+
6269
#### Install
6370

6471
```bash
@@ -78,10 +85,15 @@ $ rails g sync:install
7885
<%= javascript_include_tag Sync.adapter_javascript_url %>
7986
```
8087

81-
#### 4) Configure your pubsub server (Faye or Pusher)
88+
> NOTE: If you have multiple adapter_javascript_url that you need to include, such as in the STOMP example config below, use the following instead:
89+
90+
```erb
91+
<%= javascript_include_tag *Sync.adapter_javascript_url %>
92+
```
8293

94+
#### 4) Configure your pubsub server (Faye, Pusher, or STOMP)
8395

84-
#### Using [Faye](http://faye.jcoglan.com/) (self hosted)
96+
#### Using [Faye](http://faye.jcoglan.com/) (self-hosted)
8597

8698
Set your configuration in the generated `config/sync.yml` file, using the Faye adapter. Then run Faye alongside your app.
8799

@@ -93,6 +105,34 @@ rackup sync.ru -E production
93105

94106
Set your configuration in the generated `config/sync.yml` file, using the Pusher adapter. No extra process/setup.
95107

108+
#### Using [STOMP](https://stomp.github.io) with [RabbitMQ](https://www.rabbitmq.com) (self-hosted)
109+
110+
> NOTE: Sync will probably play nicely with other STOMP servers besides RabbitMQ, but these have not been tested and are not guaranteed to be supported.
111+
112+
- Install [RabbitMQ](https://www.rabbitmq.com/download.html).
113+
- Start the RabbitMQ server (see your installation guide in link above).
114+
- Enable the RabbitMQ STOMP plugin: `rabbitmq-plugins enable rabbitmq_web_stomp` ([see page](https://www.rabbitmq.com/stomp.html))
115+
- Set your configuration in the generated `config/sync.yml` file, using the Stomp adapter. Ensure the default `amq.topic` exchange is available on your RabbitMQ instance (although experienced users may adjust the `websocket` and `destination` endpoints to suit their needs).
116+
- The Stomp adapter needs access to vendor javascript assets for [`sockjs-client`](https://github.com/sockjs/sockjs-client) and [`stomp-websocket`](https://github.com/jmesnil/stomp-websocket). Either add them to your asset pipeline, and require them in your `application.js` manifest *before* the `//= require sync` declaration, or handle their inclusion in your layout as laid out in [Step #3](#3-add-the-pubsub-adapters-javascript-to-your-application-layout-appviewslayoutsapplicationhtmlerb).
117+
118+
An example configuration for RabbitMQ servers (local, out-of-box, and STOMP-enabled):
119+
```yaml
120+
# config/sync.yml
121+
122+
development:
123+
adapter_javascript_url:
124+
- 'https://cdnjs.cloudflare.com/ajax/libs/sockjs-client/1.0.3/sockjs.js'
125+
- 'https://cdnjs.cloudflare.com/ajax/libs/stomp.js/2.3.3/stomp.js'
126+
server: 'stomp://guest:guest@localhost:61613'
127+
api_key: 'guest'
128+
auth_token: 'guest'
129+
adapter: 'Stomp'
130+
encryption: false
131+
async: true
132+
websocket: 'http://localhost:15674/stomp'
133+
destination: '/topic/sync-'
134+
```
135+
96136
#### Important: clear your asset cache
97137
98138
Because Sync interpolates your configuration settings into its compiled JavaScript, you may need to clear the Rails asset cache before your changes are reflected. You can do so by running `rake assets:clobber` from the command line.

lib/generators/sync/templates/sync.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ development:
1818

1919
# Stomp
2020
# development:
21+
# adapter_javascript_url:
22+
# - 'https://cdnjs.cloudflare.com/ajax/libs/sockjs-client/1.0.3/sockjs.js'
23+
# - 'https://cdnjs.cloudflare.com/ajax/libs/stomp.js/2.3.3/stomp.js'
2124
# server: 'stomp://YOUR_STOMP_SERVER_LOGIN:YOUR_STOMP_SERVER_PASSCODE@HOST:STOMP_PORT'
2225
# api_key: 'YOUR_STOMP_CLIENT_LOGIN'
2326
# auth_token: 'YOUR_STOMP_CLIENT_PASSCODE'

test/dummy/app/views/layouts/application.html.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<html>
33
<head>
44
<title>Dummy</title>
5+
<%= javascript_include_tag *[Sync.adapter_javascript_url].flatten %>
56
<%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
67
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>
78
<%= csrf_meta_tags %>

test/fixtures/sync_stomp.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Stomp
22
test:
3+
adapter_javascript_url:
4+
- 'https://cdnjs.cloudflare.com/ajax/libs/sockjs-client/1.0.3/sockjs.js'
5+
- 'https://cdnjs.cloudflare.com/ajax/libs/stomp.js/2.3.3/stomp.js'
36
server: 'stomp://guest:guest@localhost:61613'
47
api_key: 'guest'
58
auth_token: 'guest'

0 commit comments

Comments
 (0)