phoenix_pubsub 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +62 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/phoenix/pubsub.rb +69 -0
- data/lib/phoenix/pubsub/version.rb +5 -0
- data/phoenix_pubsub.gemspec +32 -0
- metadata +139 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 09dc48151af907d57e652c72f9f75f545820b523
|
4
|
+
data.tar.gz: 393873ce4756ca2151e4859e6acad9600b7ded1a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8cee86a7af857619eff4584b4ea34df7e18f91f5041ee157285b336fb1f1bcbde39c3106762565ae4e06531c5ec8d436c37bc126ee5388395c765dbc5fc96302
|
7
|
+
data.tar.gz: 0edd2ebddd4eb79e40e689dc029771566eb1578be224539f08bb86650084263d23914052fcfc6c70b959b9a67d7156b1a31df7c2899936c672915e1ea91d3ec4
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Frontrunner Software
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# Phoenix Pubsub for Ruby
|
2
|
+
|
3
|
+
PhoenixPubsub allows you to publish messages to Phoenix Channels from Ruby. Subscriptions are not implemented (yet).
|
4
|
+
|
5
|
+
## Why?
|
6
|
+
|
7
|
+
This might be very interesting for people wanting to enrich their Rails app with Realtime capabilities and to leverage the incredible websocket performance of the Erlang VM.
|
8
|
+
The awaited Rails 5 release with ActionCable will most likely not feature such an ease of scalability as Elixir/Erlang does.
|
9
|
+
|
10
|
+
Also this can help people to transition from Rails to Phoenix.
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
Add this line to your application's Gemfile:
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
gem 'phoenix_pubsub'
|
18
|
+
```
|
19
|
+
|
20
|
+
And then execute:
|
21
|
+
|
22
|
+
$ bundle
|
23
|
+
|
24
|
+
Or install it yourself as:
|
25
|
+
|
26
|
+
$ gem install phoenix_pubsub
|
27
|
+
|
28
|
+
## Usage
|
29
|
+
|
30
|
+
E.g.: using with [sample chat app](https://github.com/chrismccord/phoenix_chat_example):
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
p = Phoenix::Pubsub::Redis.new(redis_url: 'redis://localhost:6379', phoenix_class: 'Chat.PubSub')
|
34
|
+
p.publish 'rooms:lobby', 'new:msg', { user: 'rake', body: 'hello from ruby!' }
|
35
|
+
```
|
36
|
+
|
37
|
+
### Requirements
|
38
|
+
|
39
|
+
- Redis
|
40
|
+
- Phoenix app with [Redis PubSub adapter](https://github.com/phoenixframework/phoenix_pubsub_redis)
|
41
|
+
|
42
|
+
### Sample Chat App
|
43
|
+
|
44
|
+
- Clone Phoenix [Sample Chat app](https://github.com/chrismccord/phoenix_chat_example)
|
45
|
+
- Install and configure the [Redis PubSub adapter](https://github.com/phoenixframework/phoenix_pubsub_redis)
|
46
|
+
- Make sure the demo app is running
|
47
|
+
- Clone this repo, install all dependencies and run `bundle exec rake`
|
48
|
+
- You should see a message coming from Ruby
|
49
|
+
|
50
|
+
## Development
|
51
|
+
|
52
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
53
|
+
|
54
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
55
|
+
|
56
|
+
## Contributing
|
57
|
+
|
58
|
+
1. Fork it ( https://github.com/[my-github-username]/phoenix_pubsub_redis/fork )
|
59
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
60
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
61
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
62
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'phoenix/pubsub'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'phoenix/pubsub/version'
|
2
|
+
require 'erlang/etf'
|
3
|
+
require 'redis'
|
4
|
+
|
5
|
+
module Erlang
|
6
|
+
module ETF
|
7
|
+
module Extensions
|
8
|
+
|
9
|
+
module Symbol
|
10
|
+
def __erlang_type__
|
11
|
+
if to_s.ascii_only?
|
12
|
+
:atom
|
13
|
+
else
|
14
|
+
:atom_utf8
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
module Hash
|
20
|
+
def __erlang_type__
|
21
|
+
:map
|
22
|
+
end
|
23
|
+
|
24
|
+
def __erlang_evolve__
|
25
|
+
if size == 0
|
26
|
+
ETF::Map.new([], [])
|
27
|
+
else
|
28
|
+
values = flatten.map(&:__erlang_evolve__)
|
29
|
+
ETF::Map.new(*values.each_slice(values.size / 2).to_a)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
module Phoenix
|
40
|
+
module Pubsub
|
41
|
+
|
42
|
+
class Redis
|
43
|
+
def initialize(redis_url: 'redis://localhost:6379', phoenix_class: 'Chat.PubSub')
|
44
|
+
@phoenix_class_name = phoenix_class
|
45
|
+
@redis = ::Redis.new(url: redis_url)
|
46
|
+
end
|
47
|
+
|
48
|
+
def publish topic, event, payload
|
49
|
+
@redis.publish("phx:Elixir.#{@phoenix_class_name}", serialize_message(topic, event, payload))
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def serialize_message topic, event, payload
|
55
|
+
term = Erlang::Tuple[
|
56
|
+
# {@redis_msg_vsn, node_ref, pool_size, from_pid, topic, msg}
|
57
|
+
1, '', 1, :none, topic, {
|
58
|
+
:__struct__ => :"Elixir.Phoenix.Socket.Broadcast",
|
59
|
+
:event => event,
|
60
|
+
:payload => payload,
|
61
|
+
:topic => topic
|
62
|
+
}
|
63
|
+
]
|
64
|
+
Erlang.term_to_binary term
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'phoenix/pubsub/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = 'phoenix_pubsub'
|
8
|
+
s.version = Phoenix::Pubsub::VERSION
|
9
|
+
s.summary = %q{Phoenix PubSub for Ruby}
|
10
|
+
s.description = %q{Phoenix PubSub for Ruby}
|
11
|
+
|
12
|
+
s.authors = ['Andreas Böhrnsen']
|
13
|
+
s.email = ['andreas@frontrunner.io']
|
14
|
+
s.homepage = 'https://github.com/frontrunnerio/phoenix_pubsub_rb'
|
15
|
+
|
16
|
+
s.license = 'MIT'
|
17
|
+
|
18
|
+
s.required_ruby_version = '>= 2.0'
|
19
|
+
|
20
|
+
s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
|
+
s.require_paths = ['lib']
|
22
|
+
|
23
|
+
s.add_dependency 'erlang-etf', '~> 1.1.1'
|
24
|
+
s.add_dependency 'redis', '~> 3.0.1'
|
25
|
+
|
26
|
+
s.add_development_dependency 'bundler', '~> 1.9'
|
27
|
+
s.add_development_dependency 'rake', '~> 10.0'
|
28
|
+
|
29
|
+
# testing
|
30
|
+
s.add_development_dependency 'minitest', '~> 5.8.4'
|
31
|
+
s.add_development_dependency 'shoulda-context', '~> 1.2.1'
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: phoenix_pubsub
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andreas Böhrnsen
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-04-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: erlang-etf
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.1.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.1.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: redis
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 3.0.1
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 3.0.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.9'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.9'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: minitest
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 5.8.4
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 5.8.4
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: shoulda-context
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 1.2.1
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 1.2.1
|
97
|
+
description: Phoenix PubSub for Ruby
|
98
|
+
email:
|
99
|
+
- andreas@frontrunner.io
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".travis.yml"
|
106
|
+
- Gemfile
|
107
|
+
- LICENSE
|
108
|
+
- README.md
|
109
|
+
- Rakefile
|
110
|
+
- bin/console
|
111
|
+
- bin/setup
|
112
|
+
- lib/phoenix/pubsub.rb
|
113
|
+
- lib/phoenix/pubsub/version.rb
|
114
|
+
- phoenix_pubsub.gemspec
|
115
|
+
homepage: https://github.com/frontrunnerio/phoenix_pubsub_rb
|
116
|
+
licenses:
|
117
|
+
- MIT
|
118
|
+
metadata: {}
|
119
|
+
post_install_message:
|
120
|
+
rdoc_options: []
|
121
|
+
require_paths:
|
122
|
+
- lib
|
123
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - ">="
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '2.0'
|
128
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
requirements: []
|
134
|
+
rubyforge_project:
|
135
|
+
rubygems_version: 2.2.2
|
136
|
+
signing_key:
|
137
|
+
specification_version: 4
|
138
|
+
summary: Phoenix PubSub for Ruby
|
139
|
+
test_files: []
|