Skip to content

Commit 3f8b298

Browse files
author
Adam Eberlin
committed
Update README, generator, fixtures, etc.
1 parent b9d7988 commit 3f8b298

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
<%= include_sync_config %>
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
## Current Caveats
97137
The current implementation uses a DOM range query (jQuery's `nextUntil`) to match your partial's "element" in
98138
the DOM. The way this selector works requires your sync'd partial to be wrapped in a root level html tag for that partial file.

lib/generators/sync/templates/sync.yml

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

1818
# Stomp
1919
# development:
20+
# adapter_javascript_url:
21+
# - 'https://cdnjs.cloudflare.com/ajax/libs/sockjs-client/1.0.3/sockjs.js'
22+
# - 'https://cdnjs.cloudflare.com/ajax/libs/stomp.js/2.3.3/stomp.js'
2023
# server: 'stomp://YOUR_STOMP_SERVER_LOGIN:YOUR_STOMP_SERVER_PASSCODE@HOST:STOMP_PORT'
2124
# api_key: 'YOUR_STOMP_CLIENT_LOGIN'
2225
# 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)