activemessaging 0.6.1 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
data/README ADDED
@@ -0,0 +1,22 @@
1
+ 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.
2
+
3
+ ActiveMessaging is a generic framework to ease using messaging, but is not tied to any particular messaging system - in fact, it now has support for Stomp, Amazon Simple Queue Service (SQS), Beanstalk, JMS (using StompConnect or [JMSWithJRuby direct on JRuby]), WebSphere MQ, and the all-Ruby ReliableMessaging.
4
+
5
+ Here's a sample of a processor class that handles incoming messages:
6
+
7
+ class HelloWorldProcessor < ActiveMessaging::Processor
8
+
9
+ subscribes_to :hello_world
10
+
11
+ def on_message(message)
12
+ puts "received: " + message
13
+ end
14
+
15
+ end
16
+
17
+
18
+ h1. Support
19
+
20
+ Best bet is the google groups mailing list:
21
+
22
+ http://groups.google.com/group/activemessaging-discuss
data/Rakefile CHANGED
@@ -19,32 +19,54 @@ task :rdoc do
19
19
  RDoc::RDoc.new.document(%w(--line-numbers --inline-source --title ActiveMessaging README lib))
20
20
  end
21
21
 
22
- gem_spec = Gem::Specification.new do |s|
23
- s.name = %q{activemessaging}
24
- s.version = "0.6.1"
25
-
26
- s.specification_version = 2 if s.respond_to? :specification_version=
27
-
28
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
29
- s.authors = ["jon.tirsen", "kookster", "olle.jonsson", "sylvain.perez", "anti.god.botherer", 'uwe.kubosch']
30
- s.date = %q{2008-08-15}
31
- 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.}
32
- s.email = %q{activemessaging-discuss@googlegroups.com}
33
- s.files = FileList['generators/**/*', 'lib/**/*', 'tasks/**/*', 'Rakefile', 'messaging.rb.example'].to_a
34
- s.homepage = %q{http://code.google.com/p/activemessaging/}
35
- s.require_paths = ["lib"]
36
- s.rubygems_version = %q{1.2.0}
37
- s.summary = %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.}
38
- #s.test_files = ["test"]
39
- #s.autorequire = 'activemessaging'
40
- s.has_rdoc = true
41
-
42
- s.add_dependency(%q<activesupport>, [">= 1.0.0"])
43
- s.add_dependency(%q<rubigen>, [">= 1.5.2"])
44
- #s.add_dependency(%q<common-pool-cliffmoon>, [">= 0.0.3"])
45
- end
22
+ begin
23
+ require 'jeweler'
24
+ Jeweler::Tasks.new do |gemspec|
25
+
26
+ # basic
27
+ gemspec.name = "activemessaging"
28
+ gemspec.summary = "Official activemessaging gem, now hosted on github.com/kookster. (kookster prefix temporary)"
29
+ gemspec.description = "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."
30
+ gemspec.email = "activemessaging-discuss@googlegroups.com"
31
+ gemspec.homepage = "http://github.com/kookster/activemessaging"
32
+ gemspec.authors = ["Jon Tirsen", "Andrew Kuklewicz", "Olle Jonsson", "Sylvain Perez", "Cliff Moon", 'Uwe Kubosch']
46
33
 
47
- desc 'Generate ActiveMessaging gem.'
48
- Rake::GemPackageTask.new(gem_spec) do |pkg|
34
+ # added
35
+ gemspec.add_dependency('activesupport', '>= 1.0.0')
36
+
37
+ end
38
+ Jeweler::GemcutterTasks.new
39
+ rescue LoadError
40
+ puts "Jeweler not available. Install it with: gem install jeweler"
49
41
  end
50
42
 
43
+
44
+ # gem_spec = Gem::Specification.new do |s|
45
+ # s.name = %q{activemessaging}
46
+ # s.version = "0.6.1"
47
+ #
48
+ # s.specification_version = 2 if s.respond_to? :specification_version=
49
+ #
50
+ # s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
51
+ # s.authors = ["jon.tirsen", "kookster", "olle.jonsson", "sylvain.perez", "anti.god.botherer", 'uwe.kubosch']
52
+ # s.date = %q{2008-08-15}
53
+ # 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.}
54
+ # s.email = %q{activemessaging-discuss@googlegroups.com}
55
+ # s.files = FileList['generators/**/*', 'lib/**/*', 'tasks/**/*', 'Rakefile', 'messaging.rb.example'].to_a
56
+ # s.homepage = %q{http://code.google.com/p/activemessaging/}
57
+ # s.require_paths = ["lib"]
58
+ # s.rubygems_version = %q{1.2.0}
59
+ # s.summary = %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.}
60
+ # #s.test_files = ["test"]
61
+ # #s.autorequire = 'activemessaging'
62
+ # s.has_rdoc = true
63
+ #
64
+ # s.add_dependency(%q<activesupport>, [">= 1.0.0"])
65
+ # s.add_dependency(%q<rubigen>, [">= 1.5.2"])
66
+ # #s.add_dependency(%q<common-pool-cliffmoon>, [">= 0.0.3"])
67
+ # end
68
+
69
+ # desc 'Generate ActiveMessaging gem.'
70
+ # Rake::GemPackageTask.new(gem_spec) do |pkg|
71
+ # end
72
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.7.1
@@ -0,0 +1,113 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{activemessaging}
8
+ s.version = "0.7.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Jon Tirsen", "Andrew Kuklewicz", "Olle Jonsson", "Sylvain Perez", "Cliff Moon", "Uwe Kubosch"]
12
+ s.date = %q{2010-04-08}
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.}
14
+ s.email = %q{activemessaging-discuss@googlegroups.com}
15
+ s.extra_rdoc_files = [
16
+ "README"
17
+ ]
18
+ s.files = [
19
+ "README",
20
+ "Rakefile",
21
+ "VERSION",
22
+ "activemessaging.gemspec",
23
+ "generators/a13g_test_harness/a13g_test_harness_generator.rb",
24
+ "generators/a13g_test_harness/templates/active_messaging_test.rhtml",
25
+ "generators/a13g_test_harness/templates/active_messaging_test_controller.rb",
26
+ "generators/a13g_test_harness/templates/index.rhtml",
27
+ "generators/filter/USAGE",
28
+ "generators/filter/filter_generator.rb",
29
+ "generators/filter/templates/filter.rb",
30
+ "generators/filter/templates/filter_test.rb",
31
+ "generators/processor/USAGE",
32
+ "generators/processor/processor_generator.rb",
33
+ "generators/processor/templates/application.rb",
34
+ "generators/processor/templates/broker.yml",
35
+ "generators/processor/templates/jruby_poller",
36
+ "generators/processor/templates/messaging.rb",
37
+ "generators/processor/templates/poller",
38
+ "generators/processor/templates/poller.rb",
39
+ "generators/processor/templates/processor.rb",
40
+ "generators/processor/templates/processor_test.rb",
41
+ "generators/tracer/USAGE",
42
+ "generators/tracer/templates/controller.rb",
43
+ "generators/tracer/templates/helper.rb",
44
+ "generators/tracer/templates/index.rhtml",
45
+ "generators/tracer/templates/layout.rhtml",
46
+ "generators/tracer/templates/trace_processor.rb",
47
+ "generators/tracer/tracer_generator.rb",
48
+ "init.rb",
49
+ "lib/activemessaging.rb",
50
+ "lib/activemessaging/adapter.rb",
51
+ "lib/activemessaging/adapters/asqs.rb",
52
+ "lib/activemessaging/adapters/base.rb",
53
+ "lib/activemessaging/adapters/beanstalk.rb",
54
+ "lib/activemessaging/adapters/jms.rb",
55
+ "lib/activemessaging/adapters/reliable_msg.rb",
56
+ "lib/activemessaging/adapters/stomp.rb",
57
+ "lib/activemessaging/adapters/test.rb",
58
+ "lib/activemessaging/adapters/wmq.rb",
59
+ "lib/activemessaging/base_message.rb",
60
+ "lib/activemessaging/filter.rb",
61
+ "lib/activemessaging/gateway.rb",
62
+ "lib/activemessaging/message_sender.rb",
63
+ "lib/activemessaging/named_base.rb",
64
+ "lib/activemessaging/processor.rb",
65
+ "lib/activemessaging/support.rb",
66
+ "lib/activemessaging/test_helper.rb",
67
+ "lib/activemessaging/trace_filter.rb",
68
+ "poller.rb",
69
+ "tasks/start_consumers.rake",
70
+ "test/all_tests.rb",
71
+ "test/app/config/broker.yml",
72
+ "test/asqs_test.rb",
73
+ "test/config_test.rb",
74
+ "test/filter_test.rb",
75
+ "test/gateway_test.rb",
76
+ "test/jms_test.rb",
77
+ "test/reliable_msg_test.rb",
78
+ "test/stomp_test.rb",
79
+ "test/test_helper.rb",
80
+ "test/tracer_test.rb"
81
+ ]
82
+ s.homepage = %q{http://github.com/kookster/activemessaging}
83
+ s.rdoc_options = ["--charset=UTF-8"]
84
+ s.require_paths = ["lib"]
85
+ s.rubygems_version = %q{1.3.5}
86
+ s.summary = %q{Official activemessaging gem, now hosted on github.com/kookster. (kookster prefix temporary)}
87
+ s.test_files = [
88
+ "test/all_tests.rb",
89
+ "test/asqs_test.rb",
90
+ "test/config_test.rb",
91
+ "test/filter_test.rb",
92
+ "test/gateway_test.rb",
93
+ "test/jms_test.rb",
94
+ "test/reliable_msg_test.rb",
95
+ "test/stomp_test.rb",
96
+ "test/test_helper.rb",
97
+ "test/tracer_test.rb"
98
+ ]
99
+
100
+ if s.respond_to? :specification_version then
101
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
102
+ s.specification_version = 3
103
+
104
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
105
+ s.add_runtime_dependency(%q<activesupport>, [">= 1.0.0"])
106
+ else
107
+ s.add_dependency(%q<activesupport>, [">= 1.0.0"])
108
+ end
109
+ else
110
+ s.add_dependency(%q<activesupport>, [">= 1.0.0"])
111
+ end
112
+ end
113
+
@@ -20,7 +20,7 @@ class <%= class_name %>FilterTest < Test::Unit::TestCase
20
20
  end
21
21
 
22
22
  def test_<%= file_name %>_filter
23
- @message = ActiveMessaging::TestMessage.new(@destination.value, {'message-id'=>'test-message-id-header'}, 'message body')
23
+ @message = ActiveMessaging::TestMessage.new('message body', {'message-id'=>'test-message-id-header'}, @destination.value )
24
24
  @routing = {:direction=>:incoming, :destination=>@destination}
25
25
  @filter.process(@message, @routing)
26
26
  end
@@ -27,13 +27,14 @@ development:
27
27
  # If error still occurs after retryMax, send message to specified dead letter queue
28
28
  # deadLetterQueue: '/queue/activemessaging/deadletter'
29
29
 
30
+ ################################
31
+ # Beanstalk Adapter Properties #
32
+ ################################
33
+ # adapter: beanstalk
34
+ # host: localhost
30
35
 
31
- ###################################
32
- # Websphere MQ Adapter Properties #
33
- ###################################
34
- # adapter: wmq
35
- # q_mgr_name: ""
36
- # poll_interval: .1
36
+ ## properties below are all defaults for this adapter
37
+ # port: 11300
37
38
 
38
39
 
39
40
  #################################
@@ -61,8 +62,18 @@ development:
61
62
 
62
63
  ## properties below are all defaults for this adapter
63
64
  # poll_interval: 1
64
- # reliable: true
65
+ # reliable: true
66
+
67
+
68
+ ###################################
69
+ # Websphere MQ Adapter Properties #
70
+ ###################################
71
+ # adapter: wmq
72
+ # q_mgr_name: ""
73
+ # poll_interval: .1
74
+
65
75
 
76
+
66
77
  test:
67
78
  adapter: test
68
79
  reliable: false
data/init.rb ADDED
@@ -0,0 +1,3 @@
1
+ require 'active_support'
2
+ require 'ostruct'
3
+ require 'activemessaging'
@@ -1,5 +1,4 @@
1
1
  module ActiveMessaging
2
- VERSION = "0.6.1"
3
2
  APP_ROOT = ENV['APP_ROOT'] || ENV['RAILS_ROOT'] || ((defined? RAILS_ROOT) && RAILS_ROOT) || File.dirname($0)
4
3
  APP_ENV = ENV['APP_ENV'] || ENV['RAILS_ENV'] || 'development'
5
4
  ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
@@ -49,9 +48,7 @@ module ActiveMessaging
49
48
  end
50
49
 
51
50
  def self.load_config
52
- p APP_ROOT
53
51
  path = File.expand_path("#{APP_ROOT}/config/messaging.rb")
54
- p path
55
52
  begin
56
53
  load path
57
54
  rescue MissingSourceFile
@@ -1,22 +1,22 @@
1
1
  require 'rubygems'
2
2
  require 'net/http'
3
+ require 'net/https'
3
4
  require 'openssl'
4
5
  require 'base64'
5
6
  require 'cgi'
6
7
  require 'time'
7
- require 'activemessaging/adapter'
8
+ require 'uri'
9
+
10
+ require 'activemessaging/adapters/base'
8
11
 
9
12
  module ActiveMessaging
10
13
  module Adapters
11
- module AmazonSQS
12
-
13
- class Connection
14
- include ActiveMessaging::Adapter
14
+ module AmazonSqs
15
15
 
16
+ class Connection < ActiveMessaging::Adapters::BaseConnection
16
17
  register :asqs
17
18
 
18
19
  QUEUE_NAME_LENGTH = 1..80
19
- # MESSAGE_SIZE = 1..(256 * 1024)
20
20
  MESSAGE_SIZE = 1..(8 * 1024)
21
21
  VISIBILITY_TIMEOUT = 0..(24 * 60 * 60)
22
22
  NUMBER_OF_MESSAGES = 1..255
@@ -24,37 +24,38 @@ module ActiveMessaging
24
24
  SET_QUEUE_ATTRIBUTES = ['VisibilityTimeout']
25
25
 
26
26
  #configurable params
27
- attr_accessor :reliable, :reconnectDelay, :access_key_id, :secret_access_key, :aws_version, :content_type, :host, :port, :poll_interval, :cache_queue_list
28
-
27
+ attr_accessor :reconnectDelay, :access_key_id, :secret_access_key, :aws_version, :content_type, :host, :port, :poll_interval, :cache_queue_list
28
+
29
29
  #generic init method needed by a13g
30
30
  def initialize cfg
31
- raise "Must specify a access_key_id" if (cfg[:access_key_id].nil? || cfg[:access_key_id].empty?)
32
- raise "Must specify a secret_access_key" if (cfg[:secret_access_key].nil? || cfg[:secret_access_key].empty?)
33
-
34
- @access_key_id=cfg[:access_key_id]
35
- @secret_access_key=cfg[:secret_access_key]
36
- @request_expires = cfg[:requestExpires] || 10
37
- @request_retry_count = cfg[:requestRetryCount] || 5
38
- @aws_version = cfg[:aws_version] || '2008-01-01'
39
- @content_type = cfg[:content_type] || 'text/plain'
40
- @host = cfg[:host] || 'queue.amazonaws.com'
41
- @port = cfg[:port] || 80
42
- @protocol = cfg[:protocol] || 'http'
43
- @poll_interval = cfg[:poll_interval] || 1
44
- @reconnect_delay = cfg[:reconnectDelay] || 5
45
- @aws_url="#{@protocol}://#{@host}"
46
-
47
- @cache_queue_list = cfg[:cache_queue_list].nil? ? true : cfg[:cache_queue_list]
48
- @reliable = cfg[:reliable].nil? ? true : cfg[:reliable]
49
-
50
- #initialize the subscriptions and queues
51
- @subscriptions = {}
52
- @current_subscription = 0
53
- queues
31
+ raise "Must specify a access_key_id" if (cfg[:access_key_id].nil? || cfg[:access_key_id].empty?)
32
+ raise "Must specify a secret_access_key" if (cfg[:secret_access_key].nil? || cfg[:secret_access_key].empty?)
33
+
34
+ @access_key_id=cfg[:access_key_id]
35
+ @secret_access_key=cfg[:secret_access_key]
36
+ @request_expires = cfg[:requestExpires] || 10
37
+ @request_retry_count = cfg[:requestRetryCount] || 5
38
+ @aws_version = cfg[:aws_version] || '2008-01-01'
39
+ @content_type = cfg[:content_type] || 'text/plain'
40
+ @host = cfg[:host] || 'queue.amazonaws.com'
41
+ @port = cfg[:port] || 80
42
+ @protocol = cfg[:protocol] || 'http'
43
+ @poll_interval = cfg[:poll_interval] || 1
44
+ @reconnect_delay = cfg[:reconnectDelay] || 5
45
+ @aws_url="#{@protocol}://#{@host}"
46
+
47
+ @cache_queue_list = cfg[:cache_queue_list].nil? ? true : cfg[:cache_queue_list]
48
+ @reliable = cfg[:reliable].nil? ? true : cfg[:reliable]
49
+
50
+ #initialize the subscriptions and queues
51
+ @subscriptions = {}
52
+ @current_subscription = 0
53
+ queues
54
54
  end
55
55
 
56
56
  def disconnect
57
57
  #it's an http request - there is no disconnect - ha!
58
+ return true
58
59
  end
59
60
 
60
61
  # queue_name string, headers hash
@@ -108,18 +109,18 @@ module ActiveMessaging
108
109
  begin
109
110
  delete_message message
110
111
  rescue Object=>exception
111
- logger.error "Exception in ActiveMessaging::Adapters::AmazonSQS::Connection.received() logged and ignored: "
112
+ logger.error "Exception in ActiveMessaging::Adapters::AmazonSWS::Connection.received() logged and ignored: "
112
113
  logger.error exception
113
114
  end
114
115
  end
115
116
 
117
+ # do nothing; by not deleting the message will eventually become visible again
116
118
  def unreceive message, headers={}
117
- # do nothing; by not deleting the message will eventually become visible again
118
119
  return true
119
120
  end
120
-
121
+
121
122
  protected
122
-
123
+
123
124
  def create_queue(name)
124
125
  validate_new_queue name
125
126
  response = make_request('CreateQueue', nil, {'QueueName'=>name})
@@ -137,7 +138,7 @@ module ActiveMessaging
137
138
  response = make_request('ListQueues', nil, params)
138
139
  response.nil? ? [] : response.nodes("//QueueUrl").collect{ |n| add_queue(n.text) }
139
140
  end
140
-
141
+
141
142
  def get_queue_attributes(queue, attribute='All')
142
143
  validate_get_queue_attribute(attribute)
143
144
  params = {'AttributeName'=>attribute}
@@ -185,7 +186,7 @@ module ActiveMessaging
185
186
  response = make_request('ReceiveMessage', "#{queue.queue_url}", params)
186
187
  response.nodes("//Message").collect{ |n| Message.from_element n, response, queue } unless response.nil?
187
188
  end
188
-
189
+
189
190
  def delete_message message
190
191
  response = make_request('DeleteMessage', "#{message.queue.queue_url}", {'ReceiptHandle'=>message.receipt_handle})
191
192
  end
@@ -193,7 +194,7 @@ module ActiveMessaging
193
194
  def make_request(action, url=nil, params = {})
194
195
  # puts "make_request a=#{action} u=#{url} p=#{params}"
195
196
  url ||= @aws_url
196
-
197
+
197
198
  # Add Actions
198
199
  params['Action'] = action
199
200
  params['Version'] = @aws_version
@@ -238,14 +239,22 @@ module ActiveMessaging
238
239
  return Net::HTTP.start(h, p){ |http| http.request(r) }
239
240
  end
240
241
 
242
+ def http_request h, p, r
243
+ http = Net::HTTP.new(h, p)
244
+ http.use_ssl = true if "https" == @protocol
245
+ # Don't carp about SSL cert verification
246
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
247
+ return http.request(r)
248
+ end
249
+
241
250
  def check_errors(response)
242
251
  raise "http response was nil" if (response.nil?)
243
252
  raise response.errors if (response && response.errors?)
244
253
  response
245
254
  end
246
-
255
+
247
256
  private
248
-
257
+
249
258
  # internal data structure methods
250
259
  def add_queue(url)
251
260
  q = Queue.from_url url
@@ -300,19 +309,18 @@ module ActiveMessaging
300
309
  def validate_number_of_messages nom
301
310
  raise "Number of messages, #{nom}, must be between #{NUMBER_OF_MESSAGES.min} and #{NUMBER_OF_MESSAGES.max}." unless NUMBER_OF_MESSAGES.include?(nom)
302
311
  end
303
-
304
312
  end
305
313
 
306
314
  class SQSResponse
307
315
  attr_accessor :headers, :doc, :http_response
308
-
316
+
309
317
  def initialize response
310
318
  # puts "response.body = #{response.body}"
311
319
  @http_response = response
312
320
  @headers = response.to_hash()
313
321
  @doc = REXML::Document.new(response.body)
314
322
  end
315
-
323
+
316
324
  def message_type
317
325
  return doc ? doc.root.name : ''
318
326
  end
@@ -335,16 +343,16 @@ module ActiveMessaging
335
343
 
336
344
  return msg
337
345
  end
338
-
346
+
339
347
  def get_text(xpath,default='')
340
348
  e = REXML::XPath.first( doc, xpath)
341
349
  e.nil? ? default : e.text
342
350
  end
343
-
351
+
344
352
  def each_node(xp)
345
353
  REXML::XPath.each(doc.root, xp) {|n| yield n}
346
354
  end
347
-
355
+
348
356
  def nodes(xp)
349
357
  doc.elements.to_a(xp)
350
358
  end
@@ -352,11 +360,11 @@ module ActiveMessaging
352
360
 
353
361
  class Subscription
354
362
  attr_accessor :name, :headers, :count
355
-
363
+
356
364
  def initialize(destination, headers={}, count=1)
357
365
  @destination, @headers, @count = destination, headers, count
358
366
  end
359
-
367
+
360
368
  def add
361
369
  @count += 1
362
370
  end
@@ -364,15 +372,16 @@ module ActiveMessaging
364
372
  def remove
365
373
  @count -= 1
366
374
  end
367
-
368
375
  end
369
376
 
370
377
  class Queue
371
378
  attr_accessor :name, :pathinfo, :domain, :visibility_timeout
372
379
 
373
380
  def self.from_url url
374
- return Queue.new($2,$1) if (url =~ /^http:\/\/(.+)\/([-a-zA-Z0-9_]+)$/)
375
- raise "Bad Queue URL: #{url}"
381
+ u = URI.parse(url)
382
+ name = u.path.gsub(/\//, "")
383
+ domain = u.host
384
+ return Queue.new(name,domain)
376
385
  end
377
386
 
378
387
  def queue_url
@@ -389,21 +398,20 @@ module ActiveMessaging
389
398
  end
390
399
 
391
400
  # based on stomp message, has pointer to the SQSResponseObject
392
- class Message
393
- attr_accessor :headers, :id, :body, :command, :response, :queue, :md5_of_body, :receipt_handle
394
-
401
+ class Message < ActiveMessaging::BaseMessage
402
+ attr_accessor :response, :queue, :md5_of_body, :receipt_handle
403
+
395
404
  def self.from_element e, response, queue
396
- Message.new(response.headers, e.elements['MessageId'].text, e.elements['Body'].text, e.elements['MD5OfBody'].text, e.elements['ReceiptHandle'].text, response, queue)
405
+ Message.new(e.elements['Body'].text, response.headers, e.elements['MessageId'].text, e.elements['MD5OfBody'].text, e.elements['ReceiptHandle'].text, response, queue)
397
406
  end
398
-
399
- def initialize headers, id, body, md5_of_body, receipt_handle, response, queue, command='MESSAGE'
400
- @headers, @id, @body, @md5_of_body, @receipt_handle, @response, @queue, @command = headers, id, body, md5_of_body, receipt_handle, response, queue, command
401
- headers['destination'] = queue.name
407
+
408
+ def initialize body, headers, id, md5_of_body, receipt_handle, response, queue
409
+ super(body, id, headers, queue.name)
410
+ @md5_of_body, @receipt_handle, @response, @queue = md5_of_body, receipt_handle, response, queue
402
411
  end
403
412
 
404
-
405
413
  def to_s
406
- "<AmazonSQS::Message id='#{id}' body='#{body}' headers='#{headers.inspect}' command='#{command}' response='#{response}'>"
414
+ "<AmazonSQS::Message id='#{id}' body='#{body}' headers='#{headers.inspect}' response='#{response}'>"
407
415
  end
408
416
  end
409
417