firehose 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +40 -29
- data/bin/firehose +5 -2
- data/firehose.gemspec +1 -0
- data/lib/firehose.rb +1 -0
- data/lib/firehose/cli.rb +18 -0
- data/lib/firehose/version.rb +1 -1
- metadata +35 -23
data/README.md
CHANGED
@@ -11,52 +11,46 @@
|
|
11
11
|
|
12
12
|
Firehose is both a Rack application and JavasScript library that makes building scalable real-time web applications possible.
|
13
13
|
|
14
|
-
# How is it different from socket.io?
|
15
|
-
|
16
|
-
socket.io attempts to store connection state per node instance. Firehose makes no attempt to store connection state.
|
17
|
-
|
18
|
-
Also, socket.io attempts to abstract a low-latency full-duplex port. Firehose assumes that its impossible to simulate this in older web browsers that don't support WebSockets. As such, Firehose focuses on low-latency server-to-client connections and encourages the use of existing HTTP transports, like POST and PUT, for client-to-server communications.
|
19
|
-
|
20
|
-
Finally, Firehose attempts to solve data consistency issues and authentication by encourage the use of proxying to the web application.
|
21
|
-
|
22
14
|
# Getting Started
|
23
15
|
|
24
16
|
First, you'll need to install and run RabbitMQ.
|
25
17
|
|
26
18
|
```sh
|
27
|
-
apt-get install rabbitmq # Install on Ubuntu
|
28
|
-
brew install rabbitmq # Install on Mac Homebrew
|
19
|
+
$ apt-get install rabbitmq # Install on Ubuntu
|
20
|
+
$ brew install rabbitmq # Install on Mac Homebrew
|
29
21
|
```
|
30
22
|
|
31
|
-
|
23
|
+
Then install the gem.
|
32
24
|
|
33
|
-
|
34
|
-
|
35
|
-
```ruby
|
36
|
-
require 'rubygems'
|
37
|
-
require 'firehose'
|
38
|
-
|
39
|
-
run Firehose::Rack::App.new
|
25
|
+
```sh
|
26
|
+
$ gem install firehose
|
40
27
|
```
|
41
28
|
|
42
|
-
|
29
|
+
## The Server
|
30
|
+
|
31
|
+
Now fire up the server.
|
43
32
|
|
44
33
|
```ruby
|
45
|
-
|
34
|
+
$ firehose start
|
35
|
+
>> Thin web server (v1.3.1 codename Triple Espresso)
|
36
|
+
>> Maximum connections set to 1024
|
37
|
+
>> Listening on 127.0.0.1:7478, CTRL+C to stop
|
46
38
|
```
|
47
39
|
|
48
|
-
|
40
|
+
In case you're wondering, the Firehose application server runs the Rack app `Firehose::Rack::App.new` inside of Thin.
|
41
|
+
|
42
|
+
## Publish a message to a bunch of subscribers
|
49
43
|
|
50
44
|
Lets test it out! Open two terminal windows. In one window, curl:
|
51
45
|
|
52
46
|
```sh
|
53
|
-
curl "http://localhost:
|
47
|
+
$ curl "http://localhost:7474/hello"
|
54
48
|
```
|
55
49
|
|
56
50
|
Then run the following in the other terminal:
|
57
51
|
|
58
52
|
```sh
|
59
|
-
curl -X PUT -d "Greetings fellow human being..." "http://localhost:
|
53
|
+
$ curl -X PUT -d "Greetings fellow human being..." "http://localhost:7474/hello"
|
60
54
|
```
|
61
55
|
|
62
56
|
and you should see the message in the other terminal.
|
@@ -67,7 +61,7 @@ Greetings fellow human being...
|
|
67
61
|
|
68
62
|
## Yeah, so?
|
69
63
|
|
70
|
-
You have a dirt simple HTTP pub-sub feed. You could setup an `after_commit` hook on ActiveRecord to push JSON to an end-point. On the
|
64
|
+
You have a dirt simple HTTP pub-sub feed. You could setup an `after_commit` hook on ActiveRecord to push JSON to an end-point. On the other side, you could have a Backbone.js application that picks up the changes and updates the client-side UI.
|
71
65
|
|
72
66
|
Holy mackerel! Its a nice, clean, RESTful way to build real-time web applications.
|
73
67
|
|
@@ -75,11 +69,13 @@ Holy mackerel! Its a nice, clean, RESTful way to build real-time web application
|
|
75
69
|
|
76
70
|
Firehose doesn't just stop at curl; it has a full-featured JavaScript client that lets you subscribe to channels for live updates.
|
77
71
|
|
72
|
+
Still have the server running? Copy and paste the code below into Firebug or the WebKit console.
|
73
|
+
|
78
74
|
```javascript
|
79
75
|
new Firehose.Client()
|
80
76
|
.url({
|
81
|
-
websocket: 'ws://localhost:
|
82
|
-
longpoll: 'http://localhost:
|
77
|
+
websocket: 'ws://localhost:7478/hello',
|
78
|
+
longpoll: 'http://localhost:7478/hello'
|
83
79
|
})
|
84
80
|
.params({
|
85
81
|
cid: '024023948234'
|
@@ -88,13 +84,28 @@ new Firehose.Client()
|
|
88
84
|
timeout: 5000
|
89
85
|
})
|
90
86
|
.message(function(msg){
|
91
|
-
console.log(msg);
|
87
|
+
console.log(msg);
|
92
88
|
})
|
93
89
|
.connected(function(){
|
94
90
|
console.log('Howdy friend!');
|
95
91
|
})
|
96
92
|
.disconnected(function(){
|
97
|
-
console.log('Bu bye');
|
93
|
+
console.log('Bu bye.');
|
98
94
|
})
|
99
95
|
.connect()
|
100
|
-
```
|
96
|
+
```
|
97
|
+
|
98
|
+
Then publish another message.
|
99
|
+
|
100
|
+
|
101
|
+
```sh
|
102
|
+
$ curl -X PUT -d "This is almost magical" "http://localhost:7478/hello"
|
103
|
+
```
|
104
|
+
|
105
|
+
# How is it different from socket.io?
|
106
|
+
|
107
|
+
socket.io attempts to store connection state per node instance. Firehose makes no attempt to store connection state.
|
108
|
+
|
109
|
+
Also, socket.io attempts to abstract a low-latency full-duplex port. Firehose assumes that its impossible to simulate this in older web browsers that don't support WebSockets. As such, Firehose focuses on low-latency server-to-client connections and encourages the use of existing HTTP transports, like POST and PUT, for client-to-server communications.
|
110
|
+
|
111
|
+
Finally, Firehose attempts to solve data consistency issues and authentication by encourage the use of proxying to the web application.
|
data/bin/firehose
CHANGED
data/firehose.gemspec
CHANGED
@@ -23,6 +23,7 @@ Gem::Specification.new do |s|
|
|
23
23
|
s.add_runtime_dependency "eventmachine", ">= 1.0.0.beta"
|
24
24
|
s.add_runtime_dependency "amqp", ">= 0.9.4"
|
25
25
|
s.add_runtime_dependency "thin"
|
26
|
+
s.add_runtime_dependency "thor"
|
26
27
|
s.add_runtime_dependency "websocket-rack"
|
27
28
|
|
28
29
|
s.add_development_dependency "rspec"
|
data/lib/firehose.rb
CHANGED
@@ -7,6 +7,7 @@ module Firehose
|
|
7
7
|
autoload :Publisher, 'firehose/publisher'
|
8
8
|
autoload :Goliath, 'firehose/goliath'
|
9
9
|
autoload :Rack, 'firehose/rack'
|
10
|
+
autoload :CLI, 'firehose/cli'
|
10
11
|
|
11
12
|
# TODO move this into a configuration or session class.
|
12
13
|
# Hang on to AMQP configuration settings.
|
data/lib/firehose/cli.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'thor'
|
2
|
+
|
3
|
+
module Firehose
|
4
|
+
class CLI < Thor
|
5
|
+
desc "start", "starts the firehose server"
|
6
|
+
method_option :port, :type => :numeric, :default => 7474, :required => true, :aliases => '-p'
|
7
|
+
method_option :host, :type => :string, :default => '127.0.0.1', :required => true, :aliases => '-h'
|
8
|
+
def start
|
9
|
+
require 'thin'
|
10
|
+
|
11
|
+
server = Thin::Server.new(options[:host], options[:port]) do
|
12
|
+
run Firehose::Rack::App.new
|
13
|
+
end
|
14
|
+
|
15
|
+
server.start!
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/firehose/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: firehose
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -14,7 +14,7 @@ date: 2012-04-16 00:00:00.000000000 Z
|
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: eventmachine
|
17
|
-
requirement: &
|
17
|
+
requirement: &70096762306280 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: 1.0.0.beta
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *70096762306280
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: amqp
|
28
|
-
requirement: &
|
28
|
+
requirement: &70096762305560 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ! '>='
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: 0.9.4
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *70096762305560
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: thin
|
39
|
-
requirement: &
|
39
|
+
requirement: &70096762305160 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ! '>='
|
@@ -44,10 +44,21 @@ dependencies:
|
|
44
44
|
version: '0'
|
45
45
|
type: :runtime
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *70096762305160
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: thor
|
50
|
+
requirement: &70096762304600 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
type: :runtime
|
57
|
+
prerelease: false
|
58
|
+
version_requirements: *70096762304600
|
48
59
|
- !ruby/object:Gem::Dependency
|
49
60
|
name: websocket-rack
|
50
|
-
requirement: &
|
61
|
+
requirement: &70096762304060 !ruby/object:Gem::Requirement
|
51
62
|
none: false
|
52
63
|
requirements:
|
53
64
|
- - ! '>='
|
@@ -55,10 +66,10 @@ dependencies:
|
|
55
66
|
version: '0'
|
56
67
|
type: :runtime
|
57
68
|
prerelease: false
|
58
|
-
version_requirements: *
|
69
|
+
version_requirements: *70096762304060
|
59
70
|
- !ruby/object:Gem::Dependency
|
60
71
|
name: rspec
|
61
|
-
requirement: &
|
72
|
+
requirement: &70096762294340 !ruby/object:Gem::Requirement
|
62
73
|
none: false
|
63
74
|
requirements:
|
64
75
|
- - ! '>='
|
@@ -66,10 +77,10 @@ dependencies:
|
|
66
77
|
version: '0'
|
67
78
|
type: :development
|
68
79
|
prerelease: false
|
69
|
-
version_requirements: *
|
80
|
+
version_requirements: *70096762294340
|
70
81
|
- !ruby/object:Gem::Dependency
|
71
82
|
name: rack-test
|
72
|
-
requirement: &
|
83
|
+
requirement: &70096762293700 !ruby/object:Gem::Requirement
|
73
84
|
none: false
|
74
85
|
requirements:
|
75
86
|
- - ! '>='
|
@@ -77,10 +88,10 @@ dependencies:
|
|
77
88
|
version: '0'
|
78
89
|
type: :development
|
79
90
|
prerelease: false
|
80
|
-
version_requirements: *
|
91
|
+
version_requirements: *70096762293700
|
81
92
|
- !ruby/object:Gem::Dependency
|
82
93
|
name: guard-rspec
|
83
|
-
requirement: &
|
94
|
+
requirement: &70096762292860 !ruby/object:Gem::Requirement
|
84
95
|
none: false
|
85
96
|
requirements:
|
86
97
|
- - ! '>='
|
@@ -88,10 +99,10 @@ dependencies:
|
|
88
99
|
version: '0'
|
89
100
|
type: :development
|
90
101
|
prerelease: false
|
91
|
-
version_requirements: *
|
102
|
+
version_requirements: *70096762292860
|
92
103
|
- !ruby/object:Gem::Dependency
|
93
104
|
name: guard-bundler
|
94
|
-
requirement: &
|
105
|
+
requirement: &70096762291880 !ruby/object:Gem::Requirement
|
95
106
|
none: false
|
96
107
|
requirements:
|
97
108
|
- - ! '>='
|
@@ -99,10 +110,10 @@ dependencies:
|
|
99
110
|
version: '0'
|
100
111
|
type: :development
|
101
112
|
prerelease: false
|
102
|
-
version_requirements: *
|
113
|
+
version_requirements: *70096762291880
|
103
114
|
- !ruby/object:Gem::Dependency
|
104
115
|
name: thin
|
105
|
-
requirement: &
|
116
|
+
requirement: &70096762290940 !ruby/object:Gem::Requirement
|
106
117
|
none: false
|
107
118
|
requirements:
|
108
119
|
- - ! '>='
|
@@ -110,10 +121,10 @@ dependencies:
|
|
110
121
|
version: '0'
|
111
122
|
type: :development
|
112
123
|
prerelease: false
|
113
|
-
version_requirements: *
|
124
|
+
version_requirements: *70096762290940
|
114
125
|
- !ruby/object:Gem::Dependency
|
115
126
|
name: em-http-request
|
116
|
-
requirement: &
|
127
|
+
requirement: &70096762289780 !ruby/object:Gem::Requirement
|
117
128
|
none: false
|
118
129
|
requirements:
|
119
130
|
- - ~>
|
@@ -121,10 +132,10 @@ dependencies:
|
|
121
132
|
version: 0.3.0
|
122
133
|
type: :development
|
123
134
|
prerelease: false
|
124
|
-
version_requirements: *
|
135
|
+
version_requirements: *70096762289780
|
125
136
|
- !ruby/object:Gem::Dependency
|
126
137
|
name: guard-coffeescript
|
127
|
-
requirement: &
|
138
|
+
requirement: &70096762288920 !ruby/object:Gem::Requirement
|
128
139
|
none: false
|
129
140
|
requirements:
|
130
141
|
- - ! '>='
|
@@ -132,7 +143,7 @@ dependencies:
|
|
132
143
|
version: '0'
|
133
144
|
type: :development
|
134
145
|
prerelease: false
|
135
|
-
version_requirements: *
|
146
|
+
version_requirements: *70096762288920
|
136
147
|
description: Firehose is a realtime web application toolkit for building realtime
|
137
148
|
Ruby web applications.
|
138
149
|
email:
|
@@ -163,6 +174,7 @@ files:
|
|
163
174
|
- lib/assets/javascripts/firehose/transport.js.coffee
|
164
175
|
- lib/assets/javascripts/firehose/web_socket.js.coffee
|
165
176
|
- lib/firehose.rb
|
177
|
+
- lib/firehose/cli.rb
|
166
178
|
- lib/firehose/goliath.rb
|
167
179
|
- lib/firehose/http_publisher.rb
|
168
180
|
- lib/firehose/publisher.rb
|