file_mq 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +35 -0
- data/.rspec +2 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +81 -0
- data/LICENSE +22 -0
- data/README.md +9 -0
- data/Rakefile +3 -0
- data/config/cucumber.yml +2 -0
- data/features/publish_message.feature +18 -0
- data/features/step_definitions/hooks.rb +3 -0
- data/features/step_definitions/publish_message_steps.rb +40 -0
- data/file_mq.gemspec +23 -0
- data/lib/file_channel.rb +24 -0
- data/lib/file_message.rb +13 -0
- data/lib/file_mq.rb +18 -0
- data/lib/file_mq/version.rb +3 -0
- data/lib/file_queue.rb +31 -0
- data/lib/file_topic.rb +19 -0
- data/lib/version.rb +3 -0
- data/rubocop.yml +11 -0
- data/spec/file_channel_spec.rb +64 -0
- data/spec/file_message_spec.rb +25 -0
- data/spec/file_mq_spec.rb +55 -0
- data/spec/file_queue_spec.rb +76 -0
- data/spec/file_topic_spec.rb +38 -0
- data/spec/lint/rubocop_spec.rb +6 -0
- data/spec/reek/reek_spec.rb +6 -0
- data/spec/spec_helper.rb +7 -0
- metadata +125 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZTU0MGFhMGNlZDA2YmQ0M2VjY2EwOTUxMzI2MjgzYjRkOWQ4MjdlNw==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZjZkMWVjYzNmOWRkY2YzNTU0MWI1NjJmMWQ1NTUxODU1YzQ5NzMxNw==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ZjE3MTJhZjNkZGQ2MmVkZDQwODllNzg1ZjU4MWQ4NGYyZWZkZjRhNDgyYWY1
|
10
|
+
N2FiZWJkYzEwM2Y0YjM5OTdmMTYxNDE2NmQyMjU2ZWVkNTE3ZjFhMzAyYTE2
|
11
|
+
ZjI2M2FlMzNjYzNiMDFkNTJjMjE3ZTM0MGJiYzczNjQ3ZGZkYTI=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MjM4ZThiNjBlMjhlMTk2MWEwOWIxYzIwOWQ5YWExZTkwM2VhYWY1NjU2NjU0
|
14
|
+
MzNiMWJiMzhjZDRlNWNlMjljZWVhMDc5YTk5MzJhYjRlNzdiZGE3MWNlZjdl
|
15
|
+
MTFkMjBmNWYzMDk4OWZhYjZlYWIyNjRmNmY3OTlmNDAwZWIwOGY=
|
data/.gitignore
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/test/tmp/
|
9
|
+
/test/version_tmp/
|
10
|
+
/tmp/
|
11
|
+
|
12
|
+
## Specific to RubyMotion:
|
13
|
+
.dat*
|
14
|
+
.repl_history
|
15
|
+
build/
|
16
|
+
|
17
|
+
## Documentation cache and generated files:
|
18
|
+
/.yardoc/
|
19
|
+
/_yardoc/
|
20
|
+
/doc/
|
21
|
+
/rdoc/
|
22
|
+
|
23
|
+
## Environment normalisation:
|
24
|
+
/.bundle/
|
25
|
+
/vendor/bundle
|
26
|
+
/lib/bundler/man/
|
27
|
+
|
28
|
+
# for a library or gem, you might want to ignore these files since the code is
|
29
|
+
# intended to run in multiple environments; otherwise, check them in:
|
30
|
+
# Gemfile.lock
|
31
|
+
# .ruby-version
|
32
|
+
# .ruby-gemset
|
33
|
+
|
34
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
35
|
+
.rvmrc
|
data/.rspec
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
GEM
|
2
|
+
remote: https://rubygems.org/
|
3
|
+
specs:
|
4
|
+
ast (2.0.0)
|
5
|
+
astrolabe (1.3.0)
|
6
|
+
parser (>= 2.2.0.pre.3, < 3.0)
|
7
|
+
builder (3.2.2)
|
8
|
+
cucumber (2.0.0)
|
9
|
+
builder (>= 2.1.2)
|
10
|
+
cucumber-core (~> 1.1.3)
|
11
|
+
diff-lcs (>= 1.1.3)
|
12
|
+
gherkin (~> 2.12)
|
13
|
+
multi_json (>= 1.7.5, < 2.0)
|
14
|
+
multi_test (>= 0.1.2)
|
15
|
+
cucumber-core (1.1.3)
|
16
|
+
gherkin (~> 2.12.0)
|
17
|
+
diff-lcs (1.2.5)
|
18
|
+
docile (1.1.5)
|
19
|
+
gherkin (2.12.2)
|
20
|
+
multi_json (~> 1.3)
|
21
|
+
gherkin (2.12.2-x86-mingw32)
|
22
|
+
multi_json (~> 1.3)
|
23
|
+
json (1.8.3)
|
24
|
+
multi_json (1.11.1)
|
25
|
+
multi_test (0.1.2)
|
26
|
+
parser (2.3.0.pre.2)
|
27
|
+
ast (>= 1.1, < 3.0)
|
28
|
+
powerpack (0.1.1)
|
29
|
+
rainbow (2.0.0)
|
30
|
+
rake (10.4.2)
|
31
|
+
reek (1.4.0)
|
32
|
+
rainbow (>= 1.99, < 3.0)
|
33
|
+
ruby2ruby (>= 2.0.8, < 3.0)
|
34
|
+
ruby_parser (>= 3.5.0, < 4.0)
|
35
|
+
sexp_processor (~> 4.4)
|
36
|
+
rspec (3.3.0)
|
37
|
+
rspec-core (~> 3.3.0)
|
38
|
+
rspec-expectations (~> 3.3.0)
|
39
|
+
rspec-mocks (~> 3.3.0)
|
40
|
+
rspec-core (3.3.1)
|
41
|
+
rspec-support (~> 3.3.0)
|
42
|
+
rspec-expectations (3.3.0)
|
43
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
44
|
+
rspec-support (~> 3.3.0)
|
45
|
+
rspec-mocks (3.3.0)
|
46
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
47
|
+
rspec-support (~> 3.3.0)
|
48
|
+
rspec-support (3.3.0)
|
49
|
+
rubocop (0.32.0)
|
50
|
+
astrolabe (~> 1.3)
|
51
|
+
parser (>= 2.2.2.5, < 3.0)
|
52
|
+
powerpack (~> 0.1)
|
53
|
+
rainbow (>= 1.99.1, < 3.0)
|
54
|
+
ruby-progressbar (~> 1.4)
|
55
|
+
ruby-progressbar (1.7.5)
|
56
|
+
ruby2ruby (2.2.0)
|
57
|
+
ruby_parser (~> 3.1)
|
58
|
+
sexp_processor (~> 4.0)
|
59
|
+
ruby_parser (3.7.0)
|
60
|
+
sexp_processor (~> 4.1)
|
61
|
+
sexp_processor (4.6.0)
|
62
|
+
simplecov (0.10.0)
|
63
|
+
docile (~> 1.1.0)
|
64
|
+
json (~> 1.8)
|
65
|
+
simplecov-html (~> 0.10.0)
|
66
|
+
simplecov-html (0.10.0)
|
67
|
+
|
68
|
+
PLATFORMS
|
69
|
+
ruby
|
70
|
+
x86-mingw32
|
71
|
+
|
72
|
+
DEPENDENCIES
|
73
|
+
cucumber
|
74
|
+
rake
|
75
|
+
reek
|
76
|
+
rspec
|
77
|
+
rubocop
|
78
|
+
simplecov
|
79
|
+
|
80
|
+
BUNDLED WITH
|
81
|
+
1.10.6
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Mike Butt
|
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.
|
22
|
+
|
data/README.md
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
# FileMQ
|
2
|
+
[![Circle CI](https://circleci.com/gh/m1ckr1sk/FileMQ.svg?style=svg)](https://circleci.com/gh/m1ckr1sk/FileMQ)
|
3
|
+
|
4
|
+
File based messaging library written in Ruby. The system is intended to be simple development substitute that could be swapped in in place of a more robust messaging system
|
5
|
+
|
6
|
+
## Design
|
7
|
+
The design is simple and based on many of the popular messaging systems. The FileMQ class sets the root of the system. This can then be used to create channels to communicate on. These channels have topics and queues. Topics can be posted to and the messages are then added to the queues that are bound to them.
|
8
|
+
|
9
|
+
|
data/Rakefile
ADDED
data/config/cucumber.yml
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
@cleanup
|
2
|
+
Feature: Publish message to a topic
|
3
|
+
In order to communicate with many other endpoints
|
4
|
+
I need to be able to publish a message to a topic
|
5
|
+
|
6
|
+
Scenario: Publish a message to a topic
|
7
|
+
Given that the file MQ is initialised
|
8
|
+
And a topic is created
|
9
|
+
And a client is listening to the topic
|
10
|
+
When I publish a message to the topic
|
11
|
+
Then the client must receive the message
|
12
|
+
|
13
|
+
Scenario: Publish a message to a topic with multiple listeners
|
14
|
+
Given that the file MQ is initialised
|
15
|
+
And a topic is created
|
16
|
+
And multiple clients are listening to the topic
|
17
|
+
When I publish a message to the topic
|
18
|
+
Then every client must receive the message
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require_relative '../../lib/file_mq'
|
2
|
+
require_relative 'hooks'
|
3
|
+
|
4
|
+
Given(/^that the file MQ is initialised$/) do
|
5
|
+
FileUtils.rm_rf('file_mq_store')
|
6
|
+
@file_mq = FileMQ.new('file_mq_store')
|
7
|
+
end
|
8
|
+
|
9
|
+
Given(/^a topic is created$/) do
|
10
|
+
@channel=@file_mq.create_channel
|
11
|
+
@topic = @channel.topic('test_topic')
|
12
|
+
end
|
13
|
+
|
14
|
+
Given(/^a client is listening to the topic$/) do
|
15
|
+
@queue = @channel.queue
|
16
|
+
@queue.bind(@topic)
|
17
|
+
end
|
18
|
+
|
19
|
+
Given(/^multiple clients are listening to the topic$/) do
|
20
|
+
@queue1 = @channel.queue
|
21
|
+
@queue2 = @channel.queue
|
22
|
+
@queue1.bind(@topic)
|
23
|
+
@queue2.bind(@topic)
|
24
|
+
end
|
25
|
+
|
26
|
+
When(/^I publish a message to the topic$/) do
|
27
|
+
@topic.publish('hello world!')
|
28
|
+
end
|
29
|
+
|
30
|
+
Then(/^the client must receive the message$/) do
|
31
|
+
content = @queue.pop
|
32
|
+
expect(content).to eq('hello world!')
|
33
|
+
end
|
34
|
+
|
35
|
+
Then(/^every client must receive the message$/) do
|
36
|
+
content1 = @queue1.pop
|
37
|
+
content2 = @queue2.pop
|
38
|
+
expect(content1).to eq('hello world!')
|
39
|
+
expect(content2).to eq('hello world!')
|
40
|
+
end
|
data/file_mq.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'file_mq/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "file_mq"
|
8
|
+
spec.version = FileMQ::VERSION
|
9
|
+
spec.authors = ["Mike Butt"]
|
10
|
+
spec.email = ["mjbutt@hotmail.co.uk"]
|
11
|
+
spec.summary = "A message queue library based on RabbitMQ that stores messages on file system"
|
12
|
+
spec.homepage = "https://github.com/m1ckr1sk/FileMQ"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
21
|
+
spec.add_development_dependency "cucumber", "~> 2.0.2"
|
22
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
23
|
+
end
|
data/lib/file_channel.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'securerandom'
|
2
|
+
require_relative 'file_queue'
|
3
|
+
require_relative 'file_topic'
|
4
|
+
|
5
|
+
# FileChannel - channel to hold queues and topics
|
6
|
+
class FileChannel
|
7
|
+
attr_reader :channel_name
|
8
|
+
|
9
|
+
def initialize(root_location)
|
10
|
+
@channel_name = SecureRandom.hex(20).to_s
|
11
|
+
@channel_location = root_location + '/' + @channel_name
|
12
|
+
|
13
|
+
FileUtils.mkdir_p @channel_location
|
14
|
+
@topics = {}
|
15
|
+
end
|
16
|
+
|
17
|
+
def topic(topic_name)
|
18
|
+
@topics[topic_name] = FileTopic.new(@channel_location, topic_name)
|
19
|
+
end
|
20
|
+
|
21
|
+
def queue
|
22
|
+
FileQueue.new
|
23
|
+
end
|
24
|
+
end
|
data/lib/file_message.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# FileMessage - simple class to write a message
|
2
|
+
class FileMessage
|
3
|
+
attr_reader :message_name
|
4
|
+
def initialize(message_name)
|
5
|
+
@message_name = message_name
|
6
|
+
end
|
7
|
+
|
8
|
+
def write_message(queue_location, message)
|
9
|
+
File.open(queue_location + '/' + @message_name, 'w') do |file|
|
10
|
+
file.puts message
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/file_mq.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require_relative 'file_channel'
|
3
|
+
|
4
|
+
# FileMQ - main class and entry point to application
|
5
|
+
class FileMQ
|
6
|
+
def initialize(root_folder)
|
7
|
+
@root_folder = root_folder
|
8
|
+
FileUtils.mkdir_p @root_folder
|
9
|
+
end
|
10
|
+
|
11
|
+
def create_channel
|
12
|
+
FileChannel.new(@root_folder)
|
13
|
+
end
|
14
|
+
|
15
|
+
def close
|
16
|
+
FileUtils.rm_rf(@root_folder)
|
17
|
+
end
|
18
|
+
end
|
data/lib/file_queue.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'securerandom'
|
3
|
+
|
4
|
+
require_relative 'file_topic'
|
5
|
+
|
6
|
+
# FileQueue - simple queue to bind to a topic and pop messages
|
7
|
+
class FileQueue
|
8
|
+
attr_reader :queue_name
|
9
|
+
def initialize
|
10
|
+
@queue_name = SecureRandom.hex(20).to_s
|
11
|
+
end
|
12
|
+
|
13
|
+
def bind(file_topic)
|
14
|
+
@queue_location = file_topic.topic_location + '/' + @queue_name
|
15
|
+
FileUtils.mkdir_p @queue_location
|
16
|
+
end
|
17
|
+
|
18
|
+
def pop
|
19
|
+
latest_message = latest_message_file
|
20
|
+
message_content = File.read(latest_message).chomp
|
21
|
+
File.delete(latest_message)
|
22
|
+
message_content
|
23
|
+
end
|
24
|
+
|
25
|
+
def latest_message_file
|
26
|
+
files_sorted_by_time = Dir[@queue_location + '/*'].sort_by do |file|
|
27
|
+
File.mtime(file)
|
28
|
+
end
|
29
|
+
files_sorted_by_time[0]
|
30
|
+
end
|
31
|
+
end
|
data/lib/file_topic.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require_relative 'file_message'
|
3
|
+
|
4
|
+
# FileTopic - a topic to post messages to that queues can listen to
|
5
|
+
class FileTopic
|
6
|
+
attr_reader :topic_location
|
7
|
+
def initialize(channel_location, topic_name)
|
8
|
+
@topic_location = channel_location + '/' + topic_name
|
9
|
+
FileUtils.mkdir_p @topic_location
|
10
|
+
end
|
11
|
+
|
12
|
+
def publish(message)
|
13
|
+
message_file = FileMessage.new SecureRandom.hex(20).to_s + '.msg'
|
14
|
+
Dir.glob(@topic_location + '/*').select do |queue_location|
|
15
|
+
next unless File.directory? queue_location
|
16
|
+
message_file.write_message(queue_location, message)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/version.rb
ADDED
data/rubocop.yml
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
require_relative '../lib/file_channel'
|
4
|
+
|
5
|
+
describe 'FileChannel' do
|
6
|
+
it 'should create a channel at a root location' do
|
7
|
+
#arrange
|
8
|
+
root_location = './channel_root'
|
9
|
+
FileUtils.rm_rf(root_location)
|
10
|
+
|
11
|
+
#act
|
12
|
+
channel = FileChannel.new(root_location)
|
13
|
+
|
14
|
+
#assert
|
15
|
+
directory_count = 0
|
16
|
+
Dir.glob(root_location + '/*').select do |f|
|
17
|
+
if File.directory? f
|
18
|
+
directory_count += 1
|
19
|
+
end
|
20
|
+
end
|
21
|
+
expect(directory_count).to eq(1)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should create a channel at a root location with a unique name' do
|
25
|
+
#arrange
|
26
|
+
root_location = './channel_root'
|
27
|
+
FileUtils.rm_rf(root_location)
|
28
|
+
|
29
|
+
#act
|
30
|
+
channel = FileChannel.new(root_location)
|
31
|
+
channel2 = FileChannel.new(root_location)
|
32
|
+
|
33
|
+
#assert
|
34
|
+
expect(channel.channel_name).to_not eq(channel2.channel_name)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should allow creation of a topic' do
|
38
|
+
#arrange
|
39
|
+
root_location = './channel_root'
|
40
|
+
FileUtils.rm_rf(root_location)
|
41
|
+
channel = FileChannel.new(root_location)
|
42
|
+
|
43
|
+
#act
|
44
|
+
topic = channel.topic('topic_name')
|
45
|
+
|
46
|
+
#assert
|
47
|
+
expect(topic).to_not be_nil
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should allow creation of a queue' do
|
51
|
+
#arrange
|
52
|
+
root_location = './channel_root'
|
53
|
+
FileUtils.rm_rf(root_location)
|
54
|
+
channel = FileChannel.new(root_location)
|
55
|
+
|
56
|
+
#act
|
57
|
+
queue = channel.queue
|
58
|
+
|
59
|
+
#assert
|
60
|
+
expect(queue).to_not be_nil
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require_relative '../lib/file_message'
|
2
|
+
describe 'file message' do
|
3
|
+
it 'should create a message with a name' do
|
4
|
+
#arrange
|
5
|
+
#act
|
6
|
+
file_message = FileMessage.new('file_message_name')
|
7
|
+
|
8
|
+
#assert
|
9
|
+
expect(file_message).to_not be_nil
|
10
|
+
expect(file_message.message_name).to eq('file_message_name')
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should write a file message to a queue location containing a message' do
|
14
|
+
#arrange
|
15
|
+
file_message = FileMessage.new('file_message_name')
|
16
|
+
FileUtils.mkdir_p('queue_location')
|
17
|
+
|
18
|
+
#act
|
19
|
+
file_message.write_message('queue_location','test message!')
|
20
|
+
|
21
|
+
#assert
|
22
|
+
expect(File).to exist('queue_location/file_message_name')
|
23
|
+
expect(File.read('queue_location/file_message_name').chomp).to eq('test message!')
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
require_relative '../lib/file_mq'
|
4
|
+
|
5
|
+
describe 'FileMQ' do
|
6
|
+
it 'should initialise a new instance of file mq at a specific location' do
|
7
|
+
#arrange
|
8
|
+
file_location = './file_mq_store'
|
9
|
+
FileUtils.rm_rf(file_location)
|
10
|
+
|
11
|
+
#act
|
12
|
+
file_mq = FileMQ.new file_location
|
13
|
+
|
14
|
+
#assert
|
15
|
+
expect(File).to exist(file_location)
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should initialise a new instance of file mq at a different location' do
|
19
|
+
#arrange
|
20
|
+
file_location_new = './file_mq_store_2'
|
21
|
+
FileUtils.rm_rf(file_location_new)
|
22
|
+
|
23
|
+
#act
|
24
|
+
file_mq = FileMQ.new file_location_new
|
25
|
+
|
26
|
+
#assert
|
27
|
+
expect(File).to exist(file_location_new)
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should allow creation of a channel' do
|
31
|
+
#arrange
|
32
|
+
file_location = './file_mq_store'
|
33
|
+
FileUtils.rm_rf(file_location)
|
34
|
+
file_mq = FileMQ.new file_location
|
35
|
+
|
36
|
+
#act
|
37
|
+
channel = file_mq.create_channel
|
38
|
+
|
39
|
+
#assert
|
40
|
+
expect(channel).to_not be_nil
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should clear down its message store on close' do
|
44
|
+
#arrange
|
45
|
+
file_location = './file_mq_store'
|
46
|
+
FileUtils.rm_rf(file_location)
|
47
|
+
file_mq = FileMQ.new file_location
|
48
|
+
|
49
|
+
#act
|
50
|
+
file_mq.close
|
51
|
+
|
52
|
+
#assert
|
53
|
+
expect(File).to_not exist(file_location)
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require_relative '../lib/file_queue'
|
2
|
+
|
3
|
+
describe 'FileQueue' do
|
4
|
+
it 'should create a queue with a unique name' do
|
5
|
+
#arrange
|
6
|
+
#act
|
7
|
+
queue = FileQueue.new
|
8
|
+
queue1 = FileQueue.new
|
9
|
+
|
10
|
+
#assert
|
11
|
+
expect(queue.queue_name).to_not eq(queue1.queue_name)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should allow binding to a topic' do
|
15
|
+
#arrange
|
16
|
+
channel_location = 'test_channel'
|
17
|
+
FileUtils.rm_rf(channel_location)
|
18
|
+
queue = FileQueue.new
|
19
|
+
file_topic = FileTopic.new(channel_location,'test_topic')
|
20
|
+
|
21
|
+
#act
|
22
|
+
queue.bind(file_topic)
|
23
|
+
|
24
|
+
#assert
|
25
|
+
expect(File).to exist(file_topic.topic_location + '/' + queue.queue_name)
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should pop messages from the queue' do
|
29
|
+
#arrange
|
30
|
+
channel_location = 'test_channel'
|
31
|
+
FileUtils.rm_rf(channel_location)
|
32
|
+
queue = FileQueue.new
|
33
|
+
file_topic = FileTopic.new(channel_location,'test_topic')
|
34
|
+
queue.bind(file_topic)
|
35
|
+
message_location = file_topic.topic_location + '/' + queue.queue_name + '/test_message.tst'
|
36
|
+
File.open(message_location, 'w') do |file|
|
37
|
+
file.puts 'test_message'
|
38
|
+
end
|
39
|
+
|
40
|
+
#act
|
41
|
+
content = queue.pop
|
42
|
+
|
43
|
+
#assert
|
44
|
+
expect(content).to eq('test_message')
|
45
|
+
expect(File).to_not exist(message_location)
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should pop the oldest message from the queue first' do
|
49
|
+
#arrange
|
50
|
+
channel_location = 'test_channel'
|
51
|
+
FileUtils.rm_rf(channel_location)
|
52
|
+
queue = FileQueue.new
|
53
|
+
file_topic = FileTopic.new(channel_location,'test_topic')
|
54
|
+
queue.bind(file_topic)
|
55
|
+
|
56
|
+
message_location_oldest = file_topic.topic_location + '/' + queue.queue_name + '/test_message_oldest.tst'
|
57
|
+
File.open(message_location_oldest, 'w') do |file|
|
58
|
+
file.puts 'test_message_oldest'
|
59
|
+
end
|
60
|
+
|
61
|
+
sleep(5)
|
62
|
+
|
63
|
+
message_location_newest = file_topic.topic_location + '/' + queue.queue_name + '/test_message_newest.tst'
|
64
|
+
File.open(message_location_newest, 'w') do |file|
|
65
|
+
file.puts 'test_message_newest'
|
66
|
+
end
|
67
|
+
|
68
|
+
#act
|
69
|
+
content = queue.pop
|
70
|
+
|
71
|
+
#assert
|
72
|
+
expect(content).to eq('test_message_oldest')
|
73
|
+
expect(File).to_not exist(message_location_oldest)
|
74
|
+
expect(File).to exist(message_location_newest)
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require_relative '../lib/file_topic'
|
2
|
+
|
3
|
+
describe 'FileTopic' do
|
4
|
+
it 'should create a topic from a channel location and a topic name' do
|
5
|
+
#arrange
|
6
|
+
channel_location = 'channel_location'
|
7
|
+
topic_name = 'topic_name'
|
8
|
+
|
9
|
+
#act
|
10
|
+
topic = FileTopic.new(channel_location, topic_name)
|
11
|
+
|
12
|
+
#assert
|
13
|
+
expect(File).to exist(channel_location + '/' + topic_name)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should allow messages to be published to a topic' do
|
17
|
+
#arrange
|
18
|
+
channel_location = 'channel_location'
|
19
|
+
FileUtils.rm_rf(channel_location)
|
20
|
+
topic_name = 'topic_name'
|
21
|
+
topic = FileTopic.new(channel_location, topic_name)
|
22
|
+
queue = FileQueue.new
|
23
|
+
queue.bind(topic)
|
24
|
+
queue_location = topic.topic_location + '/' + queue.queue_name
|
25
|
+
|
26
|
+
#act
|
27
|
+
topic.publish('hello world')
|
28
|
+
|
29
|
+
#assert
|
30
|
+
expect(File).to exist(queue_location)
|
31
|
+
message_array = []
|
32
|
+
messages = Dir[queue_location+'/*']
|
33
|
+
messages.each do |message_file|
|
34
|
+
message_array << File.read(message_file).chomp
|
35
|
+
end
|
36
|
+
expect(message_array).to include('hello world')
|
37
|
+
end
|
38
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: file_mq
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mike Butt
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-11-16 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.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: cucumber
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.0.2
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.0.2
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- mjbutt@hotmail.co.uk
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- .rspec
|
64
|
+
- Gemfile
|
65
|
+
- Gemfile.lock
|
66
|
+
- LICENSE
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- config/cucumber.yml
|
70
|
+
- features/publish_message.feature
|
71
|
+
- features/step_definitions/hooks.rb
|
72
|
+
- features/step_definitions/publish_message_steps.rb
|
73
|
+
- file_mq.gemspec
|
74
|
+
- lib/file_channel.rb
|
75
|
+
- lib/file_message.rb
|
76
|
+
- lib/file_mq.rb
|
77
|
+
- lib/file_mq/version.rb
|
78
|
+
- lib/file_queue.rb
|
79
|
+
- lib/file_topic.rb
|
80
|
+
- lib/version.rb
|
81
|
+
- rubocop.yml
|
82
|
+
- spec/file_channel_spec.rb
|
83
|
+
- spec/file_message_spec.rb
|
84
|
+
- spec/file_mq_spec.rb
|
85
|
+
- spec/file_queue_spec.rb
|
86
|
+
- spec/file_topic_spec.rb
|
87
|
+
- spec/lint/rubocop_spec.rb
|
88
|
+
- spec/reek/reek_spec.rb
|
89
|
+
- spec/spec_helper.rb
|
90
|
+
homepage: https://github.com/m1ckr1sk/FileMQ
|
91
|
+
licenses:
|
92
|
+
- MIT
|
93
|
+
metadata: {}
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options: []
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ! '>='
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ! '>='
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
requirements: []
|
109
|
+
rubyforge_project:
|
110
|
+
rubygems_version: 2.5.0
|
111
|
+
signing_key:
|
112
|
+
specification_version: 4
|
113
|
+
summary: A message queue library based on RabbitMQ that stores messages on file system
|
114
|
+
test_files:
|
115
|
+
- features/publish_message.feature
|
116
|
+
- features/step_definitions/hooks.rb
|
117
|
+
- features/step_definitions/publish_message_steps.rb
|
118
|
+
- spec/file_channel_spec.rb
|
119
|
+
- spec/file_message_spec.rb
|
120
|
+
- spec/file_mq_spec.rb
|
121
|
+
- spec/file_queue_spec.rb
|
122
|
+
- spec/file_topic_spec.rb
|
123
|
+
- spec/lint/rubocop_spec.rb
|
124
|
+
- spec/reek/reek_spec.rb
|
125
|
+
- spec/spec_helper.rb
|