Module: Ap4r::AsyncHelper::Base
- Defined in:
- lib/ap4r/async_helper.rb
Constant Summary collapse
- Converters =
{}
- DRUBY_HOST =
ENV['AP4R_DRUBY_HOST'] || 'localhost'
- DRUBY_PORT =
ENV['AP4R_DRUBY_PORT'] || '6438'
- DRUBY_URI =
"druby://#{DRUBY_HOST}:#{DRUBY_PORT}"
- @@druby_uris =
[DRUBY_URI]
- @@druby_uri_options =
{ :rotate => false, :fail_over => false, :fail_reuse => false }
- @@druby_uri_retry_count =
0
- @@druby_uris_size =
1
- @@default_dispatch_mode =
:HTTP
- @@default_rm_options =
{ :delivery => :once, :dispatch_mode => @@default_dispatch_mode }
- @@default_queue_prefix =
"queue."
Class Method Summary collapse
Instance Method Summary collapse
-
#async_dispatch(url_options = {}, async_params = {}, rm_options = {}, &block) ⇒ Object
This method is aliased as ::Ap4r::Client#async_to.
-
#transaction_with_saf(active_record_class = ::Ap4r::StoredMessage, *objects, &block) ⇒ Object
This method is aliased as ::Ap4r::Client#transaction.
Class Method Details
.druby_uris(uris, options = {}) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/ap4r/async_helper.rb', line 34 def druby_uris(uris, = {}) @@druby_uris = [] if uris.empty? @@druby_uris << DRUBY_URI else @@druby_uris << uris @@druby_uris.flatten! end @@druby_uri_options = @@druby_uri_options.merge() @@druby_uris_size = @@druby_uris.size @@druby_uri_retry_count = 0 end |
Instance Method Details
#async_dispatch(url_options = {}, async_params = {}, rm_options = {}, &block) ⇒ Object
This method is aliased as ::Ap4r::Client#async_to
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/ap4r/async_helper.rb', line 97 def async_dispatch( = {}, async_params = {}, = {}, &block) if logger.debug? logger.debug("url_options: ") logger.debug(.inspect) logger.debug("async_params: ") logger.debug(async_params.inspect) logger.debug("rm_options: ") logger.debug(.inspect) end = @@default_rm_options.merge( || {}) # Only async_params is not cloned. options and rm_options are cloned before now. # This is a current contract between this class and converter classes. converter = Converters[[:dispatch_mode]].new(, async_params, , self) # logger.debug("druby uri for queue-manager : #{@@druby_uris.first}") queue_name = converter.queue_name = converter.make_params queue_headers = converter. = ::Ap4r::MessageBuilder.new(queue_name, , queue_headers) if block_given? .instance_eval(&block) end queue_name = .queue_name queue_headers = . # TODO: proces flow of Converter and MessageBuilder should (probably) be reversed 2007/09/19 by shino # This branching is ad-hoc fix if queue_headers[:dispatch_mode] == :HTTP = . else = . end if Thread.current[:use_saf] = ::Ap4r::StoredMessage.store(queue_name, , queue_headers) Thread.current[:stored_messages].store( .id, { :queue_message => , :queue_name => queue_name, :queue_headers => queue_headers } ) return .id end __queue_put(queue_name, , queue_headers) end |
#transaction_with_saf(active_record_class = ::Ap4r::StoredMessage, *objects, &block) ⇒ Object
This method is aliased as ::Ap4r::Client#transaction
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/ap4r/async_helper.rb', line 50 def transaction_with_saf(active_record_class = ::Ap4r::StoredMessage, *objects, &block) Thread.current[:use_saf] = true Thread.current[:stored_messages] = {} # store active_record_class ||= ::Ap4r::StoredMessage active_record_class.transaction(*objects, &block) # forward = {} begin # TODO: reconsider forwarding strategy, 2006/10/13 kato-k # Once some error occured, such as disconnect reliable-msg or server crush, # which is smart to keep to put a message or stop to do it? # In the case of being many async messages, the former strategy is not so good. # # TODO: add delayed forward mode 2007/05/02 by shino Thread.current[:stored_messages].each {|k,v| __queue_put(v[:queue_name], v[:queue_message], v[:queue_headers]) [k] = v } rescue Exception => err # Don't raise any Exception. Application logic has already completed and messages are saved. logger.warn("Failed to put a message into queue: #{err}") end begin StoredMessage.transaction do = {:delete_mode => @@saf_delete_mode || :physical} .keys.each {|id| ::Ap4r::StoredMessage.destroy_if_exists(id, ) } end rescue Exception => err # Don't raise any Exception. Application logic has already completed and messages are saved. logger.warn("Failed to put a message into queue: #{err}") end ensure Thread.current[:use_saf] = false Thread.current[:stored_messages] = nil end |