activemessaging 0.8.2 → 0.9.0

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.8.2
1
+ 0.9.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{activemessaging}
8
- s.version = "0.8.2"
8
+ s.version = "0.9.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jon Tirsen", "Andrew Kuklewicz", "Olle Jonsson", "Sylvain Perez", "Cliff Moon", "Uwe Kubosch"]
12
- s.date = %q{2011-08-15}
12
+ s.date = %q{2011-12-05}
13
13
  s.description = %q{ActiveMessaging is an attempt to bring the simplicity and elegance of rails development to the world of messaging. Messaging, (or event-driven architecture) is widely used for enterprise integration, with frameworks such as Java's JMS, and products such as ActiveMQ, Tibco, IBM MQSeries, etc. Now supporting Rails 3 as of version 0.8.0.}
14
14
  s.email = %q{activemessaging-discuss@googlegroups.com}
15
15
  s.extra_rdoc_files = [
@@ -67,6 +67,18 @@ Gem::Specification.new do |s|
67
67
  "lib/activemessaging/railtie.rb",
68
68
  "lib/activemessaging/test_helper.rb",
69
69
  "lib/activemessaging/trace_filter.rb",
70
+ "lib/generators/active_messaging/install/USAGE",
71
+ "lib/generators/active_messaging/install/install_generator.rb",
72
+ "lib/generators/active_messaging/install/templates/application_processor.rb",
73
+ "lib/generators/active_messaging/install/templates/broker.yml",
74
+ "lib/generators/active_messaging/install/templates/poller",
75
+ "lib/generators/active_messaging/install/templates/poller.rb",
76
+ "lib/generators/active_messaging/processor/USAGE",
77
+ "lib/generators/active_messaging/processor/processor_generator.rb",
78
+ "lib/generators/active_messaging/processor/templates/messaging.rb",
79
+ "lib/generators/active_messaging/processor/templates/processor.rb",
80
+ "lib/generators/active_messaging/processor/templates/processor_spec.rb",
81
+ "lib/generators/active_messaging/processor/templates/processor_test.rb",
70
82
  "lib/tasks/start_consumers.rake",
71
83
  "poller.rb",
72
84
  "test/all_tests.rb",
@@ -126,3 +126,7 @@ module ActiveMessaging
126
126
  end
127
127
 
128
128
  end
129
+
130
+ if !defined?(Rails::Railtie)
131
+ ActiveMessaging.load_activemessaging
132
+ end
@@ -1,10 +1,13 @@
1
-
2
1
  if defined?(JRUBY_VERSION)
3
2
  #require 'java'
4
3
  include Java
5
4
 
6
- import javax.naming.InitialContext
7
- import javax.jms.MessageListener
5
+ begin
6
+ java_import javax.naming.InitialContext
7
+ java_import javax.jms.MessageListener
8
+ rescue NameError
9
+ raise LoadError, "ActiveMessaging::Adapter::Jms needs Jave EE classes on the CLASSPATH"
10
+ end
8
11
 
9
12
  module ActiveMessaging
10
13
  module Adapters
@@ -20,7 +20,7 @@ module ActiveMessaging
20
20
  cfg[:passcode] ||= ""
21
21
  cfg[:host] ||= "localhost"
22
22
  cfg[:port] ||= "61613"
23
- cfg[:reliable] = cfg[:reliable].nil? ? TRUE : cfg[:reliable].nil?
23
+ cfg[:reliable] = cfg[:reliable].nil? ? TRUE : cfg[:reliable]
24
24
  cfg[:reconnectDelay] ||= 5
25
25
  cfg[:clientId] ||= nil
26
26
 
@@ -11,7 +11,7 @@ module ActiveMessaging
11
11
 
12
12
  if defined? Rails
13
13
  ActiveMessaging.logger.info "ActiveMessaging: Rails available: Adding dispatcher prepare callback."
14
- ActionDispatch::Callbacks.to_prepare :activemessaging do
14
+ ActionDispatch::Callbacks.to_prepare do
15
15
  ActiveMessaging.reload_activemessaging
16
16
  end
17
17
  end
@@ -0,0 +1,21 @@
1
+ Description:
2
+ Configures your application to use active messaging. The following files are installed:
3
+ 1. config/broker.yml - Configures the broker that you will be using.
4
+ 2. script/poller - This script will start/stop/run the process that will be polling your broker. The name of this file/process is configurable. See Usage below.
5
+ 3. lib/poller.rb - The poller script will use this file to start up ActiveMesssaging
6
+
7
+ The generator will also create a app/processors directory and modify your application.rb so that app/processors is in the autoload path
8
+
9
+ Usage:
10
+ If you do not pass in an argument then the poller filename/process will be called poller. You can override this default by passing in the name that you want the file and process to be.
11
+
12
+ Examples:
13
+ rails g activemessaging:install
14
+
15
+ Installs activemessaging with the poller process named poller
16
+
17
+ rails g activemessaging:install POLLER_NAME
18
+
19
+ Installs activemessaging but allows you to customize the name of the poller
20
+
21
+
@@ -0,0 +1,34 @@
1
+ module ActiveMessaging
2
+ class InstallGenerator < Rails::Generators::Base
3
+ source_root File.expand_path("../templates", __FILE__)
4
+
5
+ argument :poller_name, :type => :string, :default => 'poller', :banner => 'poller_name'
6
+
7
+ def copy_application
8
+ copy_file "application_processor.rb", "app/processors/application_processor.rb"
9
+ end
10
+
11
+ def copy_poller
12
+ template "poller", "script/#{poller_name}"
13
+ chmod("script/#{poller_name}", 0755)
14
+ end
15
+
16
+ def copy_poller_rb
17
+ copy_file "poller.rb", "lib/#{poller_name}.rb"
18
+ end
19
+
20
+ def copy_broker_rb
21
+ copy_file "broker.yml", "config/broker.yml"
22
+ end
23
+
24
+ def add_gems
25
+ gem("daemons")
26
+ end
27
+
28
+
29
+ def change_application
30
+ application ' config.autoload_paths += %W(#{config.root}/app/processors)'
31
+ end
32
+
33
+ end
34
+ end
@@ -0,0 +1,18 @@
1
+ class ApplicationProcessor < ActiveMessaging::Processor
2
+
3
+ # Default on_error implementation - logs standard errors but keeps processing. Other exceptions are raised.
4
+ # Have on_error throw ActiveMessaging::AbortMessageException when you want a message to be aborted/rolled back,
5
+ # meaning that it can and should be retried (idempotency matters here).
6
+ # Retry logic varies by broker - see individual adapter code and docs for how it will be treated
7
+ def on_error(err)
8
+ if (err.kind_of?(StandardError))
9
+ logger.error "ApplicationProcessor::on_error: #{err.class.name} rescued:\n" + \
10
+ err.message + "\n" + \
11
+ "\t" + err.backtrace.join("\n\t")
12
+ else
13
+ logger.error "ApplicationProcessor::on_error: #{err.class.name} raised: " + err.message
14
+ raise err
15
+ end
16
+ end
17
+
18
+ end
@@ -0,0 +1,139 @@
1
+ #
2
+ # broker.yml
3
+ #
4
+ # Simple yaml file for the env specific configuration of the broker connections.
5
+ # See the wiki for more information: http://code.google.com/p/activemessaging/wiki/Configuration
6
+ #
7
+ development:
8
+ ############################
9
+ # Stomp Adapter Properties #
10
+ ############################
11
+ adapter: stomp
12
+
13
+ # properties below are all defaults for this adapter
14
+ # login: ""
15
+ # passcode: ""
16
+ # host: localhost
17
+ # port: 61613
18
+ # reliable: true
19
+ # reconnectDelay: 5
20
+
21
+ # NEW! enable stomp retry logic
22
+ # will resend errored out messages to be retried when on_error throws ActiveMessaging::AbortMessageException
23
+ #
24
+ # Max number of times to retry an aborted message, for 0, will not retry (default)
25
+ # retryMax: 0
26
+ #
27
+ # If error still occurs after retryMax, send message to specified dead letter queue
28
+ # deadLetterQueue: '/queue/activemessaging/deadletter'
29
+
30
+
31
+ ###########################
32
+ # AMQP Adapter Properties #
33
+ ###########################
34
+ # adapter: amqp
35
+
36
+ # properties below are defaults for this adapter
37
+ # host: localhost
38
+ # port: 5672
39
+ # user: guest
40
+ # pass: guest
41
+ # vhost: /
42
+ # ssl: false
43
+ # ssl_verify: 1
44
+ # debug: 0
45
+ # queue_name: <autogenerated>
46
+ # queue_durable: false if queue_name is autogenerated, defaults to true otherwise
47
+ # queue_auto_delete: true if queue_name is autogenerated, defaults to false otherwise
48
+ # queue_exclusive: true if queue_name is autogenerated, defaults to true otherwise
49
+
50
+ # SSL:
51
+
52
+ # in order to use SSL you will need to use the following fork of the carrot project:
53
+ #
54
+ # http://github.com/rabbitt/carrot
55
+ #
56
+ # If your certificate is self signed, you will want to set ssl_verify to 0 which corresponds to
57
+ # OpenSSL::SSL::VERIFY_NONE. Otherwise, it defaults to 1 (OpenSSL::SSL::VERIFY_PEER).
58
+
59
+ # QUEUE_*:
60
+
61
+ # queue_name is the name of the "inbox" queue that will be bound to all subscription keys (called queues
62
+ # or destinations here). In other words, you only have one queue where all messages end up using this
63
+ # adapter, and it is bound to the relevant exchanges using routing keys and exchange information
64
+ # you provide in your messages.rb and subscribes_to calls. For example,
65
+ #
66
+ # in messages.rb:
67
+ # s.queue :hello_world, 'hello.world', :exchange_type => :direct, :exchange_name => 'amq.direct'
68
+ #
69
+ # in a processor:
70
+ # subscribes_to :hello_world, :routing_key => 'hello.#'
71
+ #
72
+ # in a model:
73
+ # publish :hello_world, 'Hello world!', :routing_key => 'hello.world'
74
+
75
+
76
+ # Note: in the event that you don't specify a routing_key on publish, the queue_name of the specified
77
+ # destination (as listed in messages.rb) will be used as the routing_key when publishing.
78
+
79
+ ################################
80
+ # Beanstalk Adapter Properties #
81
+ ################################
82
+ # adapter: beanstalk
83
+ # host: localhost
84
+
85
+ ## properties below are all defaults for this adapter
86
+ # port: 11300
87
+
88
+
89
+ #################################
90
+ # Amazon SQS Adapter Properties #
91
+ #################################
92
+ # adapter: asqs
93
+ # access_key_id: XXXXXXXXXXXXXXXXXXXX
94
+ # secret_access_key: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
95
+
96
+ ## properties below are all defaults for this adapter
97
+ # host: queue.amazonaws.com
98
+ # port: 80
99
+ # reliable: true
100
+ # reconnectDelay: 5
101
+ # aws_version: 2006-04-01
102
+ # content_type: text/plain
103
+ # poll_interval: 1
104
+ # cache_queue_list: true
105
+
106
+
107
+ ########################################
108
+ # ReliableMessaging Adapter Properties #
109
+ ########################################
110
+ # adapter: reliable_msg
111
+
112
+ ## properties below are all defaults for this adapter
113
+ # poll_interval: 1
114
+ # reliable: true
115
+
116
+
117
+ ###################################
118
+ # Websphere MQ Adapter Properties #
119
+ ###################################
120
+ # adapter: wmq
121
+ # q_mgr_name: ""
122
+ # poll_interval: .1
123
+
124
+
125
+
126
+ test:
127
+ adapter: test
128
+ reliable: false
129
+
130
+ production:
131
+ adapter: stomp
132
+ reliable: true
133
+ # properties below are all defaults for this adapter
134
+ # login: ""
135
+ # passcode: ""
136
+ # host: localhost
137
+ # port: 61613
138
+ # reliable: true
139
+ # reconnectDelay: 5
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ ENV['APP_ROOT'] ||= File.expand_path(File.join(File.dirname(__FILE__), '..'))
4
+ APP_ROOT = ENV['APP_ROOT']
5
+ script_file = File.join(APP_ROOT, 'lib', '<%=poller_name%>.rb')
6
+ tmp_dir = File.join(APP_ROOT, 'tmp')
7
+
8
+ require 'rubygems'
9
+ require 'daemons'
10
+
11
+
12
+ options = {
13
+ :app_name => "<%=poller_name%>",
14
+ :dir_mode => :normal,
15
+ :dir => tmp_dir,
16
+ :multiple => true,
17
+ :ontop => false,
18
+ :mode => :load,
19
+ :backtrace => true,
20
+ :monitor => true,
21
+ :log_output => true
22
+ }
23
+
24
+ Daemons.run(script_file,options)
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+ # Make sure stdout and stderr write out without delay for using with daemon like scripts
3
+ STDOUT.sync = true; STDOUT.flush
4
+ STDERR.sync = true; STDERR.flush
5
+
6
+ #Try to Load Merb
7
+ merb_init_file = File.expand_path(File.dirname(__FILE__)+'/../config/merb_init')
8
+ if File.exists? merb_init_file
9
+ require File.expand_path(File.dirname(__FILE__)+'/../config/boot')
10
+ #need this because of the CWD
11
+ Merb.root = MERB_ROOT
12
+ require merb_init_file
13
+ else
14
+ # Load Rails
15
+ RAILS_ROOT=File.expand_path(File.join(File.dirname(__FILE__), '..'))
16
+ require File.join(RAILS_ROOT, 'config', 'boot')
17
+ require File.join(RAILS_ROOT, 'config', 'environment')
18
+ end
19
+
20
+ require 'active_support'
21
+ require 'activemessaging'
22
+
23
+ # Load ActiveMessaging processors
24
+ #ActiveMessaging::load_processors
25
+
26
+ # Start it up!
27
+ ActiveMessaging::start
@@ -0,0 +1,2 @@
1
+ Generates a stub ActiveMessaging Processor and associated test.
2
+
@@ -0,0 +1,39 @@
1
+ module ActiveMessaging
2
+ class ProcessorGenerator < Rails::Generators::NamedBase
3
+ # namespace "activemessaging"
4
+ source_root File.expand_path("../templates", __FILE__)
5
+
6
+ # check_class_collision :suffix=>"Processor"
7
+
8
+ def copy_processor
9
+ template "processor.rb", "app/processors/#{file_name}_processor.rb"
10
+ end
11
+
12
+ def copy_messaging
13
+ template "messaging.rb", "config/messaging.rb"
14
+ end
15
+
16
+ hook_for :test_framework, :as => :active_messaging_processor
17
+
18
+ end
19
+ end
20
+
21
+ module TestUnit
22
+ class ActiveMessagingProcessor < Rails::Generators::NamedBase
23
+ source_root File.expand_path("../templates", __FILE__)
24
+
25
+ def copy_processor
26
+ template "processor_test.rb", "test/functional/#{file_name}_processor_test.rb"
27
+ end
28
+ end
29
+ end
30
+
31
+ module Rspec
32
+ class ActiveMessagingProcessor < Rails::Generators::NamedBase
33
+ source_root File.expand_path("../templates", __FILE__)
34
+
35
+ def copy_processor
36
+ template "processor_spec.rb", "spec/functional/#{file_name}_processor_spec.rb"
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,12 @@
1
+ #
2
+ # Add your destination definitions here
3
+ # can also be used to configure filters, and processor groups
4
+ #
5
+ ActiveMessaging::Gateway.define do |s|
6
+ #s.destination :orders, '/queue/Orders'
7
+ #s.filter :some_filter, :only=>:orders
8
+ #s.processor_group :group1, :order_processor
9
+
10
+ s.destination :<%= singular_name %>, '/queue/<%= class_name %>'
11
+
12
+ end
@@ -0,0 +1,8 @@
1
+ class <%= class_name %>Processor < ApplicationProcessor
2
+
3
+ subscribes_to :<%= singular_name %>
4
+
5
+ def on_message(message)
6
+ logger.debug "<%= class_name %>Processor received: " + message
7
+ end
8
+ end
@@ -0,0 +1,24 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+ require 'activemessaging/test_helper'
3
+ require File.dirname(__FILE__) + '/../../app/processors/application_processor'
4
+
5
+ describe <%= class_name %>Processor do
6
+
7
+ include ActiveMessaging::TestHelper
8
+
9
+ before(:each) do
10
+ load File.dirname(__FILE__) + "/../../app/processors/<%= file_name %>_processor.rb"
11
+ @processor = <%= class_name %>Processor.new
12
+ end
13
+
14
+ after(:each) do
15
+ @processor = nil
16
+ end
17
+
18
+ it "should receive message" do
19
+ @processor.on_message('Your test message here!')
20
+ end
21
+
22
+
23
+
24
+ end
@@ -0,0 +1,20 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+ require 'activemessaging/test_helper'
3
+ require File.dirname(__FILE__) + '/../../app/processors/application_processor'
4
+
5
+ class <%= class_name %>ProcessorTest < Test::Unit::TestCase
6
+ include ActiveMessaging::TestHelper
7
+
8
+ def setup
9
+ load File.dirname(__FILE__) + "/../../app/processors/<%= file_name %>_processor.rb"
10
+ @processor = <%= class_name %>Processor.new
11
+ end
12
+
13
+ def teardown
14
+ @processor = nil
15
+ end
16
+
17
+ def test_<%= file_name %>_processor
18
+ @processor.on_message('Your test message here!')
19
+ end
20
+ end
metadata CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 8
9
- - 2
10
- version: 0.8.2
8
+ - 9
9
+ - 0
10
+ version: 0.9.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jon Tirsen
@@ -20,7 +20,7 @@ autorequire:
20
20
  bindir: bin
21
21
  cert_chain: []
22
22
 
23
- date: 2011-08-15 00:00:00 -04:00
23
+ date: 2011-12-05 00:00:00 -05:00
24
24
  default_executable:
25
25
  dependencies:
26
26
  - !ruby/object:Gem::Dependency
@@ -99,6 +99,18 @@ files:
99
99
  - lib/activemessaging/railtie.rb
100
100
  - lib/activemessaging/test_helper.rb
101
101
  - lib/activemessaging/trace_filter.rb
102
+ - lib/generators/active_messaging/install/USAGE
103
+ - lib/generators/active_messaging/install/install_generator.rb
104
+ - lib/generators/active_messaging/install/templates/application_processor.rb
105
+ - lib/generators/active_messaging/install/templates/broker.yml
106
+ - lib/generators/active_messaging/install/templates/poller
107
+ - lib/generators/active_messaging/install/templates/poller.rb
108
+ - lib/generators/active_messaging/processor/USAGE
109
+ - lib/generators/active_messaging/processor/processor_generator.rb
110
+ - lib/generators/active_messaging/processor/templates/messaging.rb
111
+ - lib/generators/active_messaging/processor/templates/processor.rb
112
+ - lib/generators/active_messaging/processor/templates/processor_spec.rb
113
+ - lib/generators/active_messaging/processor/templates/processor_test.rb
102
114
  - lib/tasks/start_consumers.rake
103
115
  - poller.rb
104
116
  - test/all_tests.rb