stomping_ground 0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,75 @@
1
+ module StompingGround
2
+
3
+ module Stomp
4
+
5
+ attr_writer :message_body
6
+
7
+ def post_init
8
+ end
9
+
10
+ def receive_data frame
11
+ frame_info = parse(frame)
12
+ case frame_info[:command]
13
+ when "CONNECT"
14
+ send_data "CONNECTED\n"
15
+ send_data "version:1.1\n"
16
+ send_data "\n"
17
+ send_data "\0"
18
+ when "SUBSCRIBE"
19
+ message = @message_body || "hello"
20
+
21
+ send_data "MESSAGE\n"
22
+ send_data "subscription:#{frame_info[:id]}\n"
23
+ send_data "message-id:007\n"
24
+ send_data "destination:#{frame_info[:destination]}\n"
25
+ send_data "content-type:text/plain\n"
26
+ send_data "content-length:#{message.length}\n"
27
+ send_data "\n"
28
+ send_data "#{message}\0"
29
+ when "DISCONNECT"
30
+ send_data "RECEIPT\n"
31
+ send_data "receipt-id:99\n"
32
+ send_data "\0"
33
+ close_connection
34
+ end
35
+ end
36
+
37
+ def unbind
38
+ end
39
+
40
+ private
41
+
42
+ def parse(frame)
43
+ frame_info = {}
44
+ data_array = frame.split("\n").reverse
45
+ frame_info[:command] = data_array.pop
46
+ data_array.each do |info|
47
+ if info.include?(':')
48
+ frame_info[info.split(':')[0].to_sym] = info.split(':')[1]
49
+ end
50
+ end
51
+ frame_info
52
+ end
53
+
54
+ end
55
+
56
+ class Server
57
+
58
+ def initialize(host, port)
59
+ @host = host
60
+ @port = port
61
+ end
62
+
63
+ def start(options={})
64
+ EventMachine.run {
65
+ EventMachine.start_server @host, @port, StompingGround::Stomp do |server|
66
+ server.message_body = options[:message]
67
+ end
68
+ }
69
+ end
70
+
71
+ end
72
+
73
+ end
74
+
75
+
@@ -0,0 +1,5 @@
1
+ module StompingGround
2
+ MAJOR=0
3
+ MINOR=1
4
+ VERSION="#{MAJOR}.#{MINOR}"
5
+ end
@@ -0,0 +1,5 @@
1
+ require 'json'
2
+ require 'socket'
3
+ require 'eventmachine'
4
+
5
+ require 'stomping_ground/server'
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: stomping_ground
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Francisco Trindade
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-27 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: onstomp
16
+ requirement: &2164826800 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *2164826800
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &2164826340 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *2164826340
36
+ - !ruby/object:Gem::Dependency
37
+ name: json
38
+ requirement: &2164825900 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *2164825900
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: &2164825480 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *2164825480
58
+ - !ruby/object:Gem::Dependency
59
+ name: eventmachine
60
+ requirement: &2164825000 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :runtime
67
+ prerelease: false
68
+ version_requirements: *2164825000
69
+ description:
70
+ email:
71
+ executables: []
72
+ extensions: []
73
+ extra_rdoc_files: []
74
+ files:
75
+ - lib/stomping_ground/server.rb
76
+ - lib/stomping_ground/version.rb
77
+ - lib/stomping_ground.rb
78
+ homepage: http://github.com/frankmt/stomping_ground
79
+ licenses: []
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 1.8.17
99
+ signing_key:
100
+ specification_version: 3
101
+ summary: Mock Stomp server to be used when testing stomp consumers
102
+ test_files: []