eventbus 0.0.20
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/admin/Gemfile +50 -0
- data/admin/Gemfile.lock +141 -0
- data/admin/Rakefile +7 -0
- data/admin/app/assets/images/rails.png +0 -0
- data/admin/app/assets/javascripts/application.js +15 -0
- data/admin/app/assets/javascripts/applications.js.coffee +3 -0
- data/admin/app/assets/javascripts/message_routes.js.coffee +3 -0
- data/admin/app/assets/javascripts/message_types.js.coffee +3 -0
- data/admin/app/assets/javascripts/messages.js.coffee +3 -0
- data/admin/app/assets/stylesheets/application.css +13 -0
- data/admin/app/assets/stylesheets/applications.css.scss +3 -0
- data/admin/app/assets/stylesheets/global.css.scss +72 -0
- data/admin/app/assets/stylesheets/message_routes.css.scss +3 -0
- data/admin/app/assets/stylesheets/message_types.css.scss +3 -0
- data/admin/app/assets/stylesheets/messages.css.scss +30 -0
- data/admin/app/assets/stylesheets/scaffolds.css.scss +56 -0
- data/admin/app/controllers/application_controller.rb +3 -0
- data/admin/app/controllers/applications_controller.rb +83 -0
- data/admin/app/controllers/message_routes_controller.rb +85 -0
- data/admin/app/controllers/message_types_controller.rb +83 -0
- data/admin/app/controllers/messages_controller.rb +75 -0
- data/admin/app/helpers/application_helper.rb +2 -0
- data/admin/app/helpers/applications_helper.rb +2 -0
- data/admin/app/helpers/message_routes_helper.rb +2 -0
- data/admin/app/helpers/message_types_helper.rb +2 -0
- data/admin/app/helpers/messages_helper.rb +2 -0
- data/admin/app/models/application.rb +7 -0
- data/admin/app/models/message.rb +4 -0
- data/admin/app/models/message_route.rb +5 -0
- data/admin/app/models/message_type.rb +7 -0
- data/admin/app/views/applications/_form.html.haml +27 -0
- data/admin/app/views/applications/edit.html.haml +5 -0
- data/admin/app/views/applications/index.html.haml +28 -0
- data/admin/app/views/applications/new.html.haml +3 -0
- data/admin/app/views/applications/show.html.haml +16 -0
- data/admin/app/views/layouts/application.html.haml +24 -0
- data/admin/app/views/message_routes/_form.html.haml +31 -0
- data/admin/app/views/message_routes/edit.html.haml +5 -0
- data/admin/app/views/message_routes/index.html.haml +28 -0
- data/admin/app/views/message_routes/new.html.haml +3 -0
- data/admin/app/views/message_routes/show.html.haml +16 -0
- data/admin/app/views/message_types/_form.html.haml +29 -0
- data/admin/app/views/message_types/edit.html.haml +5 -0
- data/admin/app/views/message_types/index.html.haml +28 -0
- data/admin/app/views/message_types/new.html.haml +5 -0
- data/admin/app/views/message_types/show.html.haml +17 -0
- data/admin/app/views/messages/index.html.haml +48 -0
- data/admin/app/views/messages/show.html.haml +45 -0
- data/admin/config/application.rb +64 -0
- data/admin/config/boot.rb +6 -0
- data/admin/config/database.yml +29 -0
- data/admin/config/environment.rb +5 -0
- data/admin/config/environments/development.rb +37 -0
- data/admin/config/environments/production.rb +72 -0
- data/admin/config/environments/test.rb +37 -0
- data/admin/config/initializers/backtrace_silencers.rb +7 -0
- data/admin/config/initializers/inflections.rb +15 -0
- data/admin/config/initializers/mime_types.rb +5 -0
- data/admin/config/initializers/secret_token.rb +7 -0
- data/admin/config/initializers/session_store.rb +8 -0
- data/admin/config/initializers/wrap_parameters.rb +14 -0
- data/admin/config/locales/en.yml +5 -0
- data/admin/config/routes.rb +69 -0
- data/admin/config.ru +4 -0
- data/admin/db/development.sqlite3-journal +0 -0
- data/admin/db/migrate/20120218124300_create_messages.rb +16 -0
- data/admin/db/migrate/20120219021535_create_applications.rb +11 -0
- data/admin/db/migrate/20120219021806_create_message_types.rb +13 -0
- data/admin/db/migrate/20120219021940_create_message_routes.rb +13 -0
- data/admin/db/migrate/20120411001040_add_app_id_key_msg_type_id_to_messages.rb +7 -0
- data/admin/db/migrate/20120411001823_rename_message_type_to_message_type_name_in_messages.rb +5 -0
- data/admin/db/migrate/20120413024953_add_message_guid_to_messages.rb +5 -0
- data/admin/db/migrate/20120523112257_add_match_all_errors_to_routes.rb +5 -0
- data/admin/db/schema.rb +68 -0
- data/admin/db/seeds.rb +7 -0
- data/admin/doc/README_FOR_APP +2 -0
- data/admin/public/404.html +26 -0
- data/admin/public/422.html +26 -0
- data/admin/public/500.html +25 -0
- data/admin/public/favicon.ico +0 -0
- data/admin/public/robots.txt +5 -0
- data/admin/script/rails +6 -0
- data/admin/script/railsrunner +3 -0
- data/admin/test/fixtures/applications.yml +14 -0
- data/admin/test/fixtures/message_routes.yml +11 -0
- data/admin/test/fixtures/message_types.yml +17 -0
- data/admin/test/fixtures/messages.yml +45 -0
- data/admin/test/functional/applications_controller_test.rb +49 -0
- data/admin/test/functional/message_routes_controller_test.rb +49 -0
- data/admin/test/functional/message_types_controller_test.rb +49 -0
- data/admin/test/functional/messages_controller_test.rb +49 -0
- data/admin/test/performance/browsing_test.rb +12 -0
- data/admin/test/test_helper.rb +13 -0
- data/admin/test/unit/application_test.rb +7 -0
- data/admin/test/unit/helpers/applications_helper_test.rb +4 -0
- data/admin/test/unit/helpers/message_routes_helper_test.rb +4 -0
- data/admin/test/unit/helpers/message_types_helper_test.rb +4 -0
- data/admin/test/unit/helpers/messages_helper_test.rb +4 -0
- data/admin/test/unit/message_route_test.rb +7 -0
- data/admin/test/unit/message_test.rb +7 -0
- data/admin/test/unit/message_type_test.rb +7 -0
- data/bin/eventbus_dispatcher.rb +118 -0
- data/bin/eventbus_emailer.rb +41 -0
- data/lib/eventbus/connectors/amqp.rb +70 -0
- data/lib/eventbus/connectors/bunny.rb +71 -0
- data/lib/eventbus/connectors/stomp.rb +77 -0
- data/lib/eventbus/message.rb +180 -0
- data/lib/eventbus/queue.rb +28 -0
- data/lib/eventbus/service.rb +116 -0
- metadata +188 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class ApplicationsControllerTest < ActionController::TestCase
|
|
4
|
+
setup do
|
|
5
|
+
@application = applications(:one)
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
test "should get index" do
|
|
9
|
+
get :index
|
|
10
|
+
assert_response :success
|
|
11
|
+
assert_not_nil assigns(:applications)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
test "should get new" do
|
|
15
|
+
get :new
|
|
16
|
+
assert_response :success
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
test "should create application" do
|
|
20
|
+
assert_difference('Application.count') do
|
|
21
|
+
post :create, application: @application.attributes
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
assert_redirected_to application_path(assigns(:application))
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
test "should show application" do
|
|
28
|
+
get :show, id: @application
|
|
29
|
+
assert_response :success
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
test "should get edit" do
|
|
33
|
+
get :edit, id: @application
|
|
34
|
+
assert_response :success
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
test "should update application" do
|
|
38
|
+
put :update, id: @application, application: @application.attributes
|
|
39
|
+
assert_redirected_to application_path(assigns(:application))
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
test "should destroy application" do
|
|
43
|
+
assert_difference('Application.count', -1) do
|
|
44
|
+
delete :destroy, id: @application
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
assert_redirected_to applications_path
|
|
48
|
+
end
|
|
49
|
+
end
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class MessageRoutesControllerTest < ActionController::TestCase
|
|
4
|
+
setup do
|
|
5
|
+
@message_route = message_routes(:one)
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
test "should get index" do
|
|
9
|
+
get :index
|
|
10
|
+
assert_response :success
|
|
11
|
+
assert_not_nil assigns(:message_routes)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
test "should get new" do
|
|
15
|
+
get :new
|
|
16
|
+
assert_response :success
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
test "should create message_route" do
|
|
20
|
+
assert_difference('MessageRoute.count') do
|
|
21
|
+
post :create, message_route: @message_route.attributes
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
assert_redirected_to message_route_path(assigns(:message_route))
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
test "should show message_route" do
|
|
28
|
+
get :show, id: @message_route
|
|
29
|
+
assert_response :success
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
test "should get edit" do
|
|
33
|
+
get :edit, id: @message_route
|
|
34
|
+
assert_response :success
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
test "should update message_route" do
|
|
38
|
+
put :update, id: @message_route, message_route: @message_route.attributes
|
|
39
|
+
assert_redirected_to message_route_path(assigns(:message_route))
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
test "should destroy message_route" do
|
|
43
|
+
assert_difference('MessageRoute.count', -1) do
|
|
44
|
+
delete :destroy, id: @message_route
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
assert_redirected_to message_routes_path
|
|
48
|
+
end
|
|
49
|
+
end
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class MessageTypesControllerTest < ActionController::TestCase
|
|
4
|
+
setup do
|
|
5
|
+
@message_type = message_types(:one)
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
test "should get index" do
|
|
9
|
+
get :index
|
|
10
|
+
assert_response :success
|
|
11
|
+
assert_not_nil assigns(:message_types)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
test "should get new" do
|
|
15
|
+
get :new
|
|
16
|
+
assert_response :success
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
test "should create message_type" do
|
|
20
|
+
assert_difference('MessageType.count') do
|
|
21
|
+
post :create, message_type: @message_type.attributes
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
assert_redirected_to message_type_path(assigns(:message_type))
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
test "should show message_type" do
|
|
28
|
+
get :show, id: @message_type
|
|
29
|
+
assert_response :success
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
test "should get edit" do
|
|
33
|
+
get :edit, id: @message_type
|
|
34
|
+
assert_response :success
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
test "should update message_type" do
|
|
38
|
+
put :update, id: @message_type, message_type: @message_type.attributes
|
|
39
|
+
assert_redirected_to message_type_path(assigns(:message_type))
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
test "should destroy message_type" do
|
|
43
|
+
assert_difference('MessageType.count', -1) do
|
|
44
|
+
delete :destroy, id: @message_type
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
assert_redirected_to message_types_path
|
|
48
|
+
end
|
|
49
|
+
end
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class MessagesControllerTest < ActionController::TestCase
|
|
4
|
+
setup do
|
|
5
|
+
@message = messages(:one)
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
test "should get index" do
|
|
9
|
+
get :index
|
|
10
|
+
assert_response :success
|
|
11
|
+
assert_not_nil assigns(:messages)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
test "should get new" do
|
|
15
|
+
get :new
|
|
16
|
+
assert_response :success
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
test "should create message" do
|
|
20
|
+
assert_difference('Message.count') do
|
|
21
|
+
post :create, message: @message.attributes
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
assert_redirected_to message_path(assigns(:message))
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
test "should show message" do
|
|
28
|
+
get :show, id: @message
|
|
29
|
+
assert_response :success
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
test "should get edit" do
|
|
33
|
+
get :edit, id: @message
|
|
34
|
+
assert_response :success
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
test "should update message" do
|
|
38
|
+
put :update, id: @message, message: @message.attributes
|
|
39
|
+
assert_redirected_to message_path(assigns(:message))
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
test "should destroy message" do
|
|
43
|
+
assert_difference('Message.count', -1) do
|
|
44
|
+
delete :destroy, id: @message
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
assert_redirected_to messages_path
|
|
48
|
+
end
|
|
49
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
require 'rails/performance_test_help'
|
|
3
|
+
|
|
4
|
+
class BrowsingTest < ActionDispatch::PerformanceTest
|
|
5
|
+
# Refer to the documentation for all available options
|
|
6
|
+
# self.profile_options = { :runs => 5, :metrics => [:wall_time, :memory]
|
|
7
|
+
# :output => 'tmp/performance', :formats => [:flat] }
|
|
8
|
+
|
|
9
|
+
def test_homepage
|
|
10
|
+
get '/'
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
ENV["RAILS_ENV"] = "test"
|
|
2
|
+
require File.expand_path('../../config/environment', __FILE__)
|
|
3
|
+
require 'rails/test_help'
|
|
4
|
+
|
|
5
|
+
class ActiveSupport::TestCase
|
|
6
|
+
# Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
|
|
7
|
+
#
|
|
8
|
+
# Note: You'll currently still have to declare fixtures explicitly in integration tests
|
|
9
|
+
# -- they do not yet inherit this setting
|
|
10
|
+
fixtures :all
|
|
11
|
+
|
|
12
|
+
# Add more helper methods to be used by all tests here...
|
|
13
|
+
end
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
admin_base = ENV['EVENTBUS_PORTAL_BASE'] || './admin'
|
|
4
|
+
puts "Loading environment.rb from: #{admin_base}/config/"
|
|
5
|
+
|
|
6
|
+
require 'eventbus/service'
|
|
7
|
+
require 'eventbus/message'
|
|
8
|
+
require "#{admin_base}/config/environment"
|
|
9
|
+
|
|
10
|
+
class DispatcherService < EventBus::Service
|
|
11
|
+
|
|
12
|
+
class ConfigurationError < RuntimeError
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def initialize
|
|
16
|
+
super("EVENT_BUS_CORE")
|
|
17
|
+
self.listen_queue = "dispatcher"
|
|
18
|
+
self.system_process = true
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def process_message(incoming_msg)
|
|
23
|
+
|
|
24
|
+
msg = EventBus::Message.new("EVENT_BUS_CORE")
|
|
25
|
+
msg.load(incoming_msg)
|
|
26
|
+
|
|
27
|
+
puts "Application Key: #{msg.application_id}"
|
|
28
|
+
puts "Message ID: #{msg.message_id}"
|
|
29
|
+
puts "Message type: #{msg.message_type}"
|
|
30
|
+
puts "Message status: #{msg.status}"
|
|
31
|
+
|
|
32
|
+
puts "Finding application for key #{msg.application_id}"
|
|
33
|
+
app = Application.find_by_key(msg.application_id)
|
|
34
|
+
|
|
35
|
+
if app.nil?
|
|
36
|
+
puts "Unable to find an application with key #{msg.application_id}"
|
|
37
|
+
|
|
38
|
+
msg.status = "DispatcherConfigurationError"
|
|
39
|
+
msg.is_error = true
|
|
40
|
+
msg.error_message = "Dispatcher has no application defined with key #{msg.application_id}"
|
|
41
|
+
log_message nil, msg
|
|
42
|
+
return
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
puts "Found application: #{app.inspect}"
|
|
46
|
+
|
|
47
|
+
msg_type = app.message_types.find_by_name(msg.message_type)
|
|
48
|
+
|
|
49
|
+
if msg_type.nil?
|
|
50
|
+
log_message app, msg
|
|
51
|
+
puts "No configuration found for Application Key #{app.key}, MessageType #{msg.message_type}"
|
|
52
|
+
|
|
53
|
+
msg.status = "DispatcherConfigurationError"
|
|
54
|
+
msg.is_error = true
|
|
55
|
+
msg.error_message = "Application #{app.name} (#{app.key}) has no message type defined as: (#{msg.message_type})"
|
|
56
|
+
log_message app, msg
|
|
57
|
+
return
|
|
58
|
+
else
|
|
59
|
+
count = 0
|
|
60
|
+
msg_type.message_routes.where(:incoming_status => msg.status).each do | route |
|
|
61
|
+
puts "Found route: #{route.dispatch_to}"
|
|
62
|
+
msg.send(:queue_name => route.dispatch_to)
|
|
63
|
+
count = count + 1
|
|
64
|
+
|
|
65
|
+
log_message app, msg, msg_type, route
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
if msg.is_error
|
|
69
|
+
msg_type.message_routes.where(:match_errors => true).each do | route |
|
|
70
|
+
puts "Matched error route: #{route.dispatch_to}"
|
|
71
|
+
msg.send(:queue_name => route.dispatch_to)
|
|
72
|
+
count = count + 1
|
|
73
|
+
|
|
74
|
+
log_message app, msg, msg_type, route
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
if count == 0
|
|
79
|
+
puts "No routes found for MessageType #{msg_type.name} Status #{msg.status}. Will log only."
|
|
80
|
+
log_message app, msg, msg_type
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def log_message(application = nil, msg = nil, msg_type = nil, route = nil)
|
|
88
|
+
|
|
89
|
+
log = Message.new
|
|
90
|
+
|
|
91
|
+
unless application.nil?
|
|
92
|
+
log.application_id = application.id
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
unless msg.nil?
|
|
96
|
+
log.application_key = msg.application_id
|
|
97
|
+
log.message_type_name = msg.message_type
|
|
98
|
+
log.status = msg.status
|
|
99
|
+
log.content = msg.dump
|
|
100
|
+
log.is_error = msg.is_error
|
|
101
|
+
log.message_guid = msg.message_id
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
unless msg_type.nil?
|
|
105
|
+
log.message_type_id = msg_type.id
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
unless route.nil?
|
|
109
|
+
log.dispatch_to = route.dispatch_to
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
log.save
|
|
113
|
+
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
DispatcherService.new.start(:max_workers => 5)
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
#!/usr/bin/env railsrunner
|
|
2
|
+
|
|
3
|
+
gem 'eventbus'
|
|
4
|
+
require 'eventbus/service'
|
|
5
|
+
require 'eventbus/message'
|
|
6
|
+
|
|
7
|
+
class EmailRequest < EventBus::Message
|
|
8
|
+
def initialize
|
|
9
|
+
super("EVENT_BUS_CORE")
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def contents
|
|
13
|
+
get("web_message")
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class EmailService < EventBus::Service
|
|
19
|
+
|
|
20
|
+
def initialize
|
|
21
|
+
super("EVENT_BUS_CORE")
|
|
22
|
+
self.listen_queue = "email"
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def process_message(incoming_msg)
|
|
27
|
+
|
|
28
|
+
msg = EmailRequest.new
|
|
29
|
+
msg.load(incoming_msg[:payload])
|
|
30
|
+
|
|
31
|
+
puts "Sending email with contents:"
|
|
32
|
+
puts msg.contents
|
|
33
|
+
|
|
34
|
+
msg.status = "EMAIL_SENT"
|
|
35
|
+
msg.send
|
|
36
|
+
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
EmailService.new.start
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
|
|
2
|
+
require 'amqp'
|
|
3
|
+
|
|
4
|
+
module AMQPConnectionDriver
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def connection_driver_initialize
|
|
8
|
+
puts "AMQPConnectionDriver is loaded!"
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def get_connection
|
|
12
|
+
new_opts = {
|
|
13
|
+
:vhost => ENV["BROKER_VHOST"] || "eventbus",
|
|
14
|
+
:host => ENV["BROKER_HOST"] || "localhost",
|
|
15
|
+
:port => ENV["BROKER_PORT"] || 5672,
|
|
16
|
+
:user => ENV["BROKER_USER"] || "eventbus",
|
|
17
|
+
:pass => ENV["BROKER_PASS"] || "eventbus",
|
|
18
|
+
# :logging => opts.delete(:logging) || false,
|
|
19
|
+
#:logfile => opts.delete(:logfile) || STDOUT
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return AMQP.connect(new_opts)
|
|
23
|
+
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def send_raw(content, opts = {})
|
|
27
|
+
queue_name = opts.delete(:queue_name)
|
|
28
|
+
EventMachine.run do
|
|
29
|
+
client = get_connection
|
|
30
|
+
channel = AMQP::Channel.new(client)
|
|
31
|
+
|
|
32
|
+
exchange = channel.direct('eventbus', :durable => true,
|
|
33
|
+
:persistent => true, :immediate => false,
|
|
34
|
+
:auto_delete => false)
|
|
35
|
+
|
|
36
|
+
puts "Declaring queue: #{queue_name}"
|
|
37
|
+
q = channel.queue(queue_name, :durable => true, :persistent => true, :immediate => false, :auto_delete => false)
|
|
38
|
+
q.bind(exchange, :routing_key => queue_name)
|
|
39
|
+
|
|
40
|
+
puts "Sending message..."
|
|
41
|
+
exchange.publish(content, :routing_key => queue_name) do
|
|
42
|
+
puts "Published to #{queue_name}: #{content}"
|
|
43
|
+
client.close { EventMachine.stop }
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def watch_queue(listen_queue)
|
|
49
|
+
EventMachine.run do
|
|
50
|
+
client = get_connection
|
|
51
|
+
channel = AMQP::Channel.new(client)
|
|
52
|
+
|
|
53
|
+
@logger.info "Listening on #{listen_queue}"
|
|
54
|
+
|
|
55
|
+
exchange = channel.direct('eventbus', :durable => true,
|
|
56
|
+
:persistent => true, :immediate => false,
|
|
57
|
+
:auto_delete => false)
|
|
58
|
+
|
|
59
|
+
q = channel.queue(listen_queue, :durable => true, :persistent => true, :immediate => false, :auto_delete => false)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
q.bind(exchange, :routing_key => listen_queue)
|
|
63
|
+
|
|
64
|
+
q.subscribe do |headers, payload|
|
|
65
|
+
yield payload
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# BunnyConnectionDriver is the original implementation of
|
|
2
|
+
# the AMQP-based broker. I am trying to make this work with
|
|
3
|
+
# straight Ruby AMQP driver, but this one is the default
|
|
4
|
+
# until I get that working properly.
|
|
5
|
+
|
|
6
|
+
module BunnyConnectionDriver
|
|
7
|
+
|
|
8
|
+
@@BunnyConnector_Connection = nil
|
|
9
|
+
|
|
10
|
+
def connection_driver_initialize
|
|
11
|
+
puts "BunnyConnectionDriver is loaded!"
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def get_connection
|
|
15
|
+
if @@BunnyConnector_Connection.nil?
|
|
16
|
+
new_opts = {
|
|
17
|
+
:vhost => ENV["BROKER_VHOST"] || "eventbus",
|
|
18
|
+
:host => ENV["BROKER_HOST"] || "localhost",
|
|
19
|
+
:port => ENV["BROKER_PORT"] || 5672,
|
|
20
|
+
:user => ENV["BROKER_USER"] || "eventbus",
|
|
21
|
+
:pass => ENV["BROKER_PASS"] || "eventbus",
|
|
22
|
+
# :logging => opts.delete(:logging) || false,
|
|
23
|
+
#:logfile => opts.delete(:logfile) || STDOUT
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
@@BunnyConnector_Connection = Bunny.new(new_opts)
|
|
27
|
+
@@BunnyConnector_Connection.start
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
return @@BunnyConnector_Connection
|
|
31
|
+
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def send_raw(content, opts = {})
|
|
35
|
+
queue_name = opts.delete(:queue_name)
|
|
36
|
+
client = get_connection
|
|
37
|
+
|
|
38
|
+
exchange = client.exchange('eventbus', :durable => true, :persistent => true, :immediate => false)
|
|
39
|
+
|
|
40
|
+
puts "Declaring queue: #{queue_name}"
|
|
41
|
+
q = client.queue(queue_name, :durable => true, :persistent => true, :immediate => false)
|
|
42
|
+
q.bind('eventbus', :key => queue_name)
|
|
43
|
+
|
|
44
|
+
puts "Publishing content to #{queue_name}: #{content}"
|
|
45
|
+
exchange.publish(content, :key => queue_name)
|
|
46
|
+
puts "Done!"
|
|
47
|
+
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def watch_queue(listen_queue)
|
|
51
|
+
|
|
52
|
+
b = get_connection
|
|
53
|
+
|
|
54
|
+
@logger.info "Listening on #{listen_queue}"
|
|
55
|
+
|
|
56
|
+
exchange = b.exchange('eventbus', :durable => true, :persistent => true, :immediate => false)
|
|
57
|
+
|
|
58
|
+
q = b.queue(listen_queue, :durable => true, :persistent => true, :immediate => false)
|
|
59
|
+
q.bind(exchange, :key => listen_queue)
|
|
60
|
+
|
|
61
|
+
q.pop do |msg|
|
|
62
|
+
if msg[:delivery_details].nil?
|
|
63
|
+
# Gotta figure out why this is necessary. Blech.
|
|
64
|
+
sleep 0.25
|
|
65
|
+
else
|
|
66
|
+
yield msg[:payload]
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
end
|
|
71
|
+
end
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# This module is primarily intended for use with ActiveMQ, though
|
|
2
|
+
# it should work with any Stomp-speaking broker.
|
|
3
|
+
require 'stomp'
|
|
4
|
+
module StompConnectionDriver
|
|
5
|
+
|
|
6
|
+
@@StompConnector_Connection = nil
|
|
7
|
+
|
|
8
|
+
def connection_driver_initialize
|
|
9
|
+
puts "StompConnectionDriver is loaded!"
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def get_connection
|
|
13
|
+
if @@StompConnector_Connection.nil?
|
|
14
|
+
opts = {
|
|
15
|
+
:host => ENV["BROKER_HOST"] || "localhost",
|
|
16
|
+
:port => ENV["BROKER_PORT"] || 61613,
|
|
17
|
+
:user => ENV["BROKER_USER"],
|
|
18
|
+
:pass => ENV["BROKER_PASS"],
|
|
19
|
+
# :logging => opts.delete(:logging) || false,
|
|
20
|
+
#:logfile => opts.delete(:logfile) || STDOUT
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
stomp_url = ENV['STOMP_URL'] ||
|
|
24
|
+
"stomp://#{opts[:user]}:#{opts[:pass]}@#{opts[:host]}:#{opts[:port]}?initialReconnectDelay=5000&randomize=false&useExponentialBackOff=false"
|
|
25
|
+
@@StompConnector_Connection = Stomp::Client.new(stomp_url)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
return @@StompConnector_Connection
|
|
29
|
+
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# opts basically just gets passed to the Stomp client.send, so it can be things
|
|
33
|
+
# like :persistent => false, etc. :persistent is true by default.
|
|
34
|
+
def send_raw(content, opts = {})
|
|
35
|
+
|
|
36
|
+
queue_name = opts.delete(:queue_name)
|
|
37
|
+
queue_name = "/queue/#{queue_name}"
|
|
38
|
+
|
|
39
|
+
opts[:persistent] = true if opts[:persistent].nil?
|
|
40
|
+
|
|
41
|
+
# "Fix" an ActiveMQ "bug" where it assumes that any message with a content-length
|
|
42
|
+
# header is a bytes-message instead of a text message. This behavior prevents the
|
|
43
|
+
# message conent from showing up in the "Message Details" section when you try
|
|
44
|
+
# to view the message in ActiveMQ's admin interface.
|
|
45
|
+
#
|
|
46
|
+
# Note that the *correct* behavior is the opposite of this: All Stomp messages
|
|
47
|
+
# are recommended to include content-length. However, this is the *less annoying*
|
|
48
|
+
# and *more useful* behavior.
|
|
49
|
+
opts[:suppress_content_length] = true if opts[:suppress_content_length].nil?
|
|
50
|
+
|
|
51
|
+
puts "Stomp sending message to: #{queue_name}"
|
|
52
|
+
|
|
53
|
+
client = get_connection
|
|
54
|
+
client.publish(queue_name, content, opts)
|
|
55
|
+
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def watch_queue(listen_queue)
|
|
59
|
+
client = get_connection
|
|
60
|
+
|
|
61
|
+
queue_name = listen_queue.match('^/') ? listen_queue : "/queue/#{listen_queue}"
|
|
62
|
+
|
|
63
|
+
# OK, so some assumption that we're using ActiveMQ here. We'll work that out eventually. The point
|
|
64
|
+
# is, though, that we want to allow for maximum parallelism -- not just by thread but also across
|
|
65
|
+
# processes and machines. Therefore, don't lock the queue exclusively (i.e. don't kill other clients!)
|
|
66
|
+
# and only take blocks of one message rather than claiming large blocks. These assumptions should become
|
|
67
|
+
# configurable at some point, but for now it's not really a concern.
|
|
68
|
+
puts "Subscribing to #{queue_name}..."
|
|
69
|
+
|
|
70
|
+
client.subscribe(queue_name, {"activemq.prefetchSize" => 1, "activemq.exclusive" => false}) do |msg|
|
|
71
|
+
yield msg.body
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
end
|