active_stomp 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +66 -0
- data/Rakefile +1 -0
- data/active_stomp.gemspec +28 -0
- data/lib/active_stomp.rb +6 -0
- data/lib/active_stomp/base.rb +56 -0
- data/lib/active_stomp/version.rb +3 -0
- data/spec/active_stomp/base_spec.rb +42 -0
- data/spec/active_stomp/dummy/service_spec.rb +58 -0
- data/spec/spec_helper.rb +19 -0
- metadata +131 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 26fdf81890ec5cffdb9d47b9f248745b272bb570
|
4
|
+
data.tar.gz: a2673d39ec42b91dfe56fcb31e0a1dda9b485b32
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ef0157e10d12226e77015c4cc51398d58595574ce48f52cf8c8ddcf84fe8ff07352fc2602ae7b8459f17106584feb3f262cbce4b3520c849ed5b39b0b4ab64a3
|
7
|
+
data.tar.gz: e1b9249950c50bbde1b3eec748ca7034c1cb1162be014c79538cdcdf3557f4d7edf682524f8aad307505d28d59e94be66732b448492d73567a9b1a89fa70675c
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Konrad Oleksiuk
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
# ActiveStomp
|
2
|
+
|
3
|
+
ActiveStomp allows to abstract the Stomp protocol
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'active_stomp'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install active_stomp
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Create an instance of ActiveStomp::Base with hash config and then just start it with block
|
22
|
+
|
23
|
+
Config options:
|
24
|
+
* :stomp [required]
|
25
|
+
https://github.com/stompgem/stomp#hash-login-example-usage-this-is-the-recommended-login-technique
|
26
|
+
|
27
|
+
* :queue [optional]
|
28
|
+
Queue that receiver needs to subscribe (default to 'queue/stomp')
|
29
|
+
|
30
|
+
* :respond [optional
|
31
|
+
How client should respond to messages. Default - 'client'. Other options: auto.
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
config = { stomp: {
|
35
|
+
hosts: { host: "localhost", port: 61613, user: '', pass: "", ssl: false }
|
36
|
+
},
|
37
|
+
queue: '/queue/dummy'
|
38
|
+
}
|
39
|
+
|
40
|
+
receiver = ActiveStomp::Base.new(config)
|
41
|
+
|
42
|
+
receiver.start do |message|
|
43
|
+
begin
|
44
|
+
# do something here with received message
|
45
|
+
# e.g. parse
|
46
|
+
msg = JSON.parse(message)
|
47
|
+
save!(msg)
|
48
|
+
|
49
|
+
:ack # notify that everything is ok
|
50
|
+
rescue
|
51
|
+
:error # something went wrong!
|
52
|
+
end
|
53
|
+
end
|
54
|
+
```
|
55
|
+
|
56
|
+
## Contributing
|
57
|
+
|
58
|
+
1. Fork it
|
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 new Pull Request
|
63
|
+
|
64
|
+
## License
|
65
|
+
|
66
|
+
MIT
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'active_stomp/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "active_stomp"
|
8
|
+
spec.version = ActiveStomp::VERSION
|
9
|
+
spec.authors = ["Konrad Oleksiuk"]
|
10
|
+
spec.email = ["konrad@up-next.com"]
|
11
|
+
spec.description = %q{ActiveStomp allows to abstract the Stomp protocol}
|
12
|
+
spec.summary = %q{Thanks to ActiveStomp you can stop thinking about Stomp details when dealing with ActiveMQ queues}
|
13
|
+
spec.homepage = "https://github.com/koleksiuk/active_stomp"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
|
24
|
+
spec.add_development_dependency 'rspec'
|
25
|
+
spec.add_development_dependency 'shoulda'
|
26
|
+
|
27
|
+
spec.add_dependency 'stomp'
|
28
|
+
end
|
data/lib/active_stomp.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
module ActiveStomp
|
2
|
+
class Base
|
3
|
+
def initialize(configuration = {})
|
4
|
+
self.config = configuration
|
5
|
+
|
6
|
+
self.client = ::Stomp::Client.new(config[:stomp])
|
7
|
+
self.queue = config[:queue] || '/queue/stomp'
|
8
|
+
self.respond = config[:respond] || 'client'
|
9
|
+
end
|
10
|
+
|
11
|
+
def start(&block)
|
12
|
+
Signal.trap('INT') do
|
13
|
+
destroy
|
14
|
+
end
|
15
|
+
|
16
|
+
listen(&block)
|
17
|
+
|
18
|
+
client.join
|
19
|
+
end
|
20
|
+
|
21
|
+
def stop
|
22
|
+
client.unsubscribe queue
|
23
|
+
client.join
|
24
|
+
end
|
25
|
+
|
26
|
+
def destroy
|
27
|
+
client.close
|
28
|
+
end
|
29
|
+
|
30
|
+
protected
|
31
|
+
|
32
|
+
def listen(&block)
|
33
|
+
client.subscribe queue, { ack: respond } do |message|
|
34
|
+
reply = block.call(message.body)
|
35
|
+
|
36
|
+
if respond == 'client'
|
37
|
+
if reply == :ack
|
38
|
+
client.acknowledge(message)
|
39
|
+
else
|
40
|
+
client.nack(message)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
attr_accessor :config, :client, :queue, :respond
|
47
|
+
attr_reader :respond
|
48
|
+
|
49
|
+
# param [String] value
|
50
|
+
def respond=(value)
|
51
|
+
value = :auto unless ['auto', 'client'].include? value
|
52
|
+
|
53
|
+
@respond = value
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ActiveStomp::Base do
|
4
|
+
let(:config) do
|
5
|
+
{ stomp: { hosts: { host: "localhost", port: 61613, user: '', pass: "", ssl: false } }, queue: '/queue/dummy' }
|
6
|
+
end
|
7
|
+
|
8
|
+
let(:stomp_client) { double('stomp_client').as_null_object }
|
9
|
+
|
10
|
+
before do
|
11
|
+
Stomp::Client.stub(:new).with(config[:stomp]).and_return stomp_client
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '.initialize' do
|
15
|
+
it 'should create new Stomp::Base instance' do
|
16
|
+
described_class.should_receive(:new).with(config[:stomp])
|
17
|
+
|
18
|
+
described_class.new(config[:stomp])
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#start' do
|
23
|
+
let!(:client) { described_class.new(config) }
|
24
|
+
|
25
|
+
it 'should subscribe to stomp protocol' do
|
26
|
+
stomp_client.should_receive(:subscribe).with('/queue/dummy', { ack: 'client' })
|
27
|
+
|
28
|
+
client.start {|msg| msg }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '#destroy' do
|
33
|
+
let!(:client) { described_class.new(config) }
|
34
|
+
|
35
|
+
it 'should send #close message to client' do
|
36
|
+
stomp_client.should_receive(:close)
|
37
|
+
client.destroy
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
class Dummy
|
5
|
+
def initialize(config)
|
6
|
+
self.config = config
|
7
|
+
self.receiver = ActiveStomp::Base.new(config)
|
8
|
+
end
|
9
|
+
|
10
|
+
def start
|
11
|
+
receiver.start do |message|
|
12
|
+
begin
|
13
|
+
JSON.parse(message)
|
14
|
+
:ack
|
15
|
+
rescue
|
16
|
+
:error
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
attr_accessor :config, :receiver
|
22
|
+
end
|
23
|
+
|
24
|
+
describe Dummy do
|
25
|
+
let(:stomp_receiver) { double('stomp_receiver').as_null_object }
|
26
|
+
|
27
|
+
let(:config) do
|
28
|
+
{ stomp: { hosts: { host: "localhost", port: 61613, user: '', pass: "", ssl: false } }, queue: '/queue/dummy' }
|
29
|
+
end
|
30
|
+
|
31
|
+
before do
|
32
|
+
ActiveStomp::Base.stub(:new).and_return(stomp_receiver)
|
33
|
+
end
|
34
|
+
|
35
|
+
describe '#start' do
|
36
|
+
let(:service) { described_class.new(config) }
|
37
|
+
|
38
|
+
it 'should start Receivers::Stomp' do
|
39
|
+
stomp_receiver.should_receive(:start)
|
40
|
+
|
41
|
+
service.start
|
42
|
+
end
|
43
|
+
|
44
|
+
describe 'should handle received messages' do
|
45
|
+
before do
|
46
|
+
stomp_receiver.stub(:start)
|
47
|
+
stomp_receiver.should_receive(:start).and_yield({a: 'b'}.to_json)
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'and send received messages to JSON parser' do
|
51
|
+
JSON.should_receive(:parse).with({a: 'b'}.to_json)
|
52
|
+
|
53
|
+
service.start
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
require_relative '../lib/active_stomp'
|
7
|
+
|
8
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
9
|
+
RSpec.configure do |config|
|
10
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
11
|
+
config.run_all_when_everything_filtered = true
|
12
|
+
config.filter_run :focus
|
13
|
+
|
14
|
+
# Run specs in random order to surface order dependencies. If you find an
|
15
|
+
# order dependency and want to debug it, you can fix the order by providing
|
16
|
+
# the seed, which is printed after each run.
|
17
|
+
# --seed 1234
|
18
|
+
config.order = 'random'
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: active_stomp
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Konrad Oleksiuk
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-07-31 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: shoulda
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: stomp
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: ActiveStomp allows to abstract the Stomp protocol
|
84
|
+
email:
|
85
|
+
- konrad@up-next.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- .gitignore
|
91
|
+
- .rspec
|
92
|
+
- Gemfile
|
93
|
+
- LICENSE.txt
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- active_stomp.gemspec
|
97
|
+
- lib/active_stomp.rb
|
98
|
+
- lib/active_stomp/base.rb
|
99
|
+
- lib/active_stomp/version.rb
|
100
|
+
- spec/active_stomp/base_spec.rb
|
101
|
+
- spec/active_stomp/dummy/service_spec.rb
|
102
|
+
- spec/spec_helper.rb
|
103
|
+
homepage: https://github.com/koleksiuk/active_stomp
|
104
|
+
licenses:
|
105
|
+
- MIT
|
106
|
+
metadata: {}
|
107
|
+
post_install_message:
|
108
|
+
rdoc_options: []
|
109
|
+
require_paths:
|
110
|
+
- lib
|
111
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - '>='
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - '>='
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
requirements: []
|
122
|
+
rubyforge_project:
|
123
|
+
rubygems_version: 2.0.3
|
124
|
+
signing_key:
|
125
|
+
specification_version: 4
|
126
|
+
summary: Thanks to ActiveStomp you can stop thinking about Stomp details when dealing
|
127
|
+
with ActiveMQ queues
|
128
|
+
test_files:
|
129
|
+
- spec/active_stomp/base_spec.rb
|
130
|
+
- spec/active_stomp/dummy/service_spec.rb
|
131
|
+
- spec/spec_helper.rb
|