modern_times 0.3.3 → 0.3.4

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/Rakefile CHANGED
@@ -11,7 +11,7 @@ begin
11
11
  gemspec.authors = ['Brad Pardee', 'Reid Morrison']
12
12
  gemspec.email = ['bradpardee@gmail.com', 'rubywmq@gmail.com']
13
13
  gemspec.homepage = 'http://github.com/ClarityServices/modern_times'
14
- gemspec.add_dependency 'jruby-jms', ['>= 0.11.0']
14
+ gemspec.add_dependency 'jruby-jms', ['>= 0.11.2']
15
15
  gemspec.add_dependency 'jmx', ['>= 0.6']
16
16
  end
17
17
  rescue LoadError
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.3
1
+ 0.3.4
data/examples/jms.yml CHANGED
@@ -3,7 +3,7 @@
3
3
  :require_jars:
4
4
  - <%= Dir.glob("#{ENV['ACTIVEMQ_HOME']}/activemq-all-*.jar")[0] %>
5
5
  #Uncomment the following for 5.5 version
6
- #- <%= Dir.glob("#{ENV['ACTIVEMQ_HOME']}/lib/optional/slf4j-log4j*.jar")[0] %>
7
- #- <%= Dir.glob("#{ENV['ACTIVEMQ_HOME']}/lib/optional/log4j-*.jar")[0] %>
6
+ - <%= Dir.glob("#{ENV['ACTIVEMQ_HOME']}/lib/optional/slf4j-log4j*.jar")[0] %>
7
+ - <%= Dir.glob("#{ENV['ACTIVEMQ_HOME']}/lib/optional/log4j-*.jar")[0] %>
8
8
  #:username: myuser
9
9
  #:password: mypassword
@@ -19,7 +19,7 @@ $sim_count = (ARGV[3] || 1).to_i
19
19
 
20
20
  config = YAML.load(ERB.new(File.read(File.join(File.dirname(__FILE__), '..', 'jms.yml'))).result(binding))
21
21
  ModernTimes::JMS::Connection.init(config)
22
- $publisher = ModernTimes::JMS::Publisher.new(:queue_name => ReverseEchoWorker.default_name, :response =>true, :marshal => :string)
22
+ $publisher = ModernTimes::JMS::Publisher.new(:queue_name => ReverseEchoWorker.default_name, :response_time_to_live => 10000, :marshal => :string)
23
23
 
24
24
  def make_request(ident='')
25
25
  puts "#{ident}Making request at #{Time.now.to_f}"
@@ -60,9 +60,9 @@ module ModernTimes
60
60
  start = Time.now
61
61
  message = nil
62
62
  Connection.session_pool.producer(@real_producer_options) do |session, producer|
63
- producer.time_to_live = @time_to_live if @time_to_live
63
+ producer.time_to_live = @time_to_live if @time_to_live
64
+ producer.delivery_mode_sym = @persistent_sym
64
65
  message = ModernTimes::JMS.create_message(session, @marshaler, object)
65
- message.jms_delivery_mode_sym = @persistent_sym
66
66
  message.jms_reply_to = @reply_queue if @reply_queue
67
67
  message['mt:marshal'] = @marshal.to_s
68
68
  message['mt:response:time_to_live'] = @response_time_to_live_str if @response_time_to_live_str
@@ -82,11 +82,11 @@ module ModernTimes
82
82
  persistent = (message['mt:response:persistent'] == 'true') if persistent.nil? && message['mt:response:persistent']
83
83
  # If persistent isn't set anywhere, then default to true unless time_to_live has been set
84
84
  persistent = !time_to_live if persistent.nil?
85
+ # The reply is persistent if we explicitly set it or if we don't expire
86
+ producer.delivery_mode_sym = persistent ? :persistent : :non_persistent
85
87
  producer.time_to_live = time_to_live.to_i if time_to_live
86
88
  reply_message = ModernTimes::JMS.create_message(session, marshaler, object)
87
89
  reply_message.jms_correlation_id = message.jms_message_id
88
- # The reply is persistent if we explicitly set it or if we don't expire
89
- reply_message.jms_delivery_mode_sym = persistent ? :persistent : :non_persistent
90
90
  reply_message['mt:marshal'] = marshal_type.to_s
91
91
  reply_message['mt:worker'] = self.name
92
92
  yield reply_message if block_given?
@@ -1,5 +1,4 @@
1
1
  require 'modern_times/jms/connection'
2
- require 'modern_times/jms/consumer'
3
2
  require 'modern_times/jms/publisher'
4
3
  require 'modern_times/jms/publish_handle'
5
4
  require 'modern_times/jms/supervisor_mbean'
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: modern_times
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.3.3
5
+ version: 0.3.4
6
6
  platform: ruby
7
7
  authors:
8
8
  - Brad Pardee
@@ -22,7 +22,7 @@ dependencies:
22
22
  requirements:
23
23
  - - ">="
24
24
  - !ruby/object:Gem::Version
25
- version: 0.11.0
25
+ version: 0.11.2
26
26
  type: :runtime
27
27
  version_requirements: *id001
28
28
  - !ruby/object:Gem::Dependency
@@ -66,7 +66,6 @@ files:
66
66
  - examples/advanced_requestor/publish.rb
67
67
  - examples/advanced_requestor/reverse_worker.rb
68
68
  - examples/advanced_requestor/triple_worker.rb
69
- - examples/consumer/consumer.rb
70
69
  - examples/jms.yml
71
70
  - examples/requestor/.gitignore
72
71
  - examples/requestor/README
@@ -86,7 +85,6 @@ files:
86
85
  - lib/modern_times/base/worker.rb
87
86
  - lib/modern_times/jms.rb
88
87
  - lib/modern_times/jms/connection.rb
89
- - lib/modern_times/jms/consumer.rb
90
88
  - lib/modern_times/jms/publish_handle.rb
91
89
  - lib/modern_times/jms/publisher.rb
92
90
  - lib/modern_times/jms/request_worker.rb
@@ -150,7 +148,6 @@ test_files:
150
148
  - examples/advanced_requestor/publish.rb
151
149
  - examples/advanced_requestor/reverse_worker.rb
152
150
  - examples/advanced_requestor/triple_worker.rb
153
- - examples/consumer/consumer.rb
154
151
  - examples/requestor/manager.rb
155
152
  - examples/requestor/request.rb
156
153
  - examples/requestor/reverse_echo_worker.rb
@@ -1,24 +0,0 @@
1
- # Allow examples to be run in-place without requiring a gem install
2
- $LOAD_PATH.unshift File.dirname(__FILE__) + '/../../lib'
3
-
4
- require 'rubygems'
5
- require 'erb'
6
- require 'modern_times'
7
- require 'yaml'
8
-
9
- if ARGV.size < 2
10
- $stderr.puts "Usage: {$0} <message> <id>"
11
- end
12
-
13
- #ModernTimes::JMS::Publisher.setup_dummy_publishing([])
14
- #ModernTimes::JMS::Consumer.setup_dummy_receiving
15
-
16
- config = YAML.load(ERB.new(File.read(File.join(File.dirname(__FILE__), '..', 'jms.yml'))).result(binding))
17
- ModernTimes::JMS::Connection.init(config)
18
- publisher = ModernTimes::JMS::Publisher.new(:queue_name => 'Foo', :marshal => :string)
19
- consumer = ModernTimes::JMS::Consumer.new(:queue_name => 'Foo', :marshal => :string)
20
-
21
- publisher.publish(ARGV[0], :jms_correlation_id => ARGV[1])
22
- msg = consumer.receive(:jms_correlation_id => ARGV[1], :timeout => 30000)
23
- #msg = consumer.receive(:timeout => 1000)
24
- puts "msg=#{msg}"
@@ -1,76 +0,0 @@
1
- require 'jms'
2
-
3
- # Protocol independent class to handle Publishing
4
- module ModernTimes
5
- module JMS
6
- class Consumer
7
- attr_reader :consumer_options, :persistent, :marshaler
8
-
9
- # Parameters:
10
- # One of the following must be specified
11
- # :queue_name => String: Name of the Queue to publish to
12
- # :topic_name => String: Name of the Topic to publish to
13
- # :virtual_topic_name => String: Name of the Virtual Topic to publish to
14
- # (ActiveMQ only, see http://activemq.apache.org/virtual-destinations.html
15
- # :destination=> Explicit javax::Jms::Destination to use
16
- # Optional:
17
- # :persistent => true or false (defaults to false)
18
- # :marshal => Symbol: One of :ruby, :string, or :json
19
- # => Module: Module that defines marshal and unmarshal method
20
- def initialize(options)
21
- consumer_keys = [:queue_name, :topic_name, :virtual_topic_name, :destination]
22
- @consumer_options = options.reject {|k,v| !consumer_keys.include?(k)}
23
- raise "One of #{consumer_keys.join(',')} must be given in #{self.class.name}" if @consumer_options.empty?
24
-
25
- # Save our @consumer_options for destination comparison when doing dummy_publish,
26
- # but create the real options by translating virtual_topic_name to a real topic_name.
27
- @real_consumer_options = @consumer_options.dup
28
- virtual_topic_name = @real_consumer_options.delete(:virtual_topic_name)
29
- @real_consumer_options[:topic_name] = "VirtualTopic.#{virtual_topic_name}" if virtual_topic_name
30
- @marshaler = ModernTimes::MarshalStrategy.find(options[:marshal])
31
- end
32
-
33
- # Publish the given object to the address.
34
- def receive(options={})
35
- options = @real_consumer_options.merge(options)
36
- correlation_id = options.delete(:jms_correlation_id)
37
- options[:selector] = "JMSCorrelationID = '#{correlation_id}'" if correlation_id && !options[:selector]
38
- timeout = options.delete(:timeout) || 0
39
- obj = nil
40
-
41
- Connection.session_pool.consumer(options) do |session, consumer|
42
- message = consumer.get(:timeout => timeout)
43
- obj = @marshaler.unmarshal(message.data) if message
44
- end
45
- return obj
46
- end
47
-
48
- # For non-configured Rails projects, The above publish method will be overridden to
49
- # call this publish method instead which calls all the JMS workers that
50
- # operate on the given address.
51
- def dummy_receive(options={})
52
- if correlation_id = options.delete(:jms_correlation_id)
53
- return Publisher.dummy_cache(correlation_id)
54
- else
55
- # TODO: Pop off if no correlation id given
56
- end
57
- end
58
-
59
- def to_s
60
- "#{self.class.name}:#{@real_consumer_options.inspect}"
61
- end
62
-
63
- def self.setup_dummy_receiving
64
- alias_method :real_receive, :receive
65
- alias_method :receive, :dummy_receive
66
- end
67
-
68
- # For testing
69
- def self.clear_dummy_receiving
70
- alias_method :dummy_receive, :receive
71
- alias_method :receive, :real_receive
72
- #remove_method :real_receive
73
- end
74
- end
75
- end
76
- end