Skip to content

Commit

Permalink
make Participant#amqp_connect overridable
Browse files Browse the repository at this point in the history
  • Loading branch information
jmettraux committed Sep 2, 2012
1 parent 12c433b commit dbcf112
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
13 changes: 7 additions & 6 deletions Gemfile.lock
@@ -1,9 +1,10 @@
GIT
remote: git://github.com/jmettraux/ruote.git
revision: e5996817d09313ebc19b5586dbc9671f99d55420
revision: 75398e451bea4c269cdf24d61d3235b1b1b96519
specs:
ruote (2.3.0)
parslet (>= 1.2.3)
blankslate (>= 2.1.2.4)
parslet (>= 1.4.0)
rufus-cloche (>= 1.0.2)
rufus-dollar (>= 1.0.4)
rufus-json (>= 1.0.1)
Expand Down Expand Up @@ -33,9 +34,9 @@ GEM
blankslate (2.1.2.4)
diff-lcs (1.1.3)
eventmachine (0.12.10)
file-tail (1.0.10)
tins (~> 0.4.3)
parslet (1.3.0)
file-tail (1.0.11)
tins (~> 0.5.0)
parslet (1.4.0)
blankslate (~> 2.0)
rake (0.9.2.2)
rspec (2.11.0)
Expand Down Expand Up @@ -66,7 +67,7 @@ GEM
ruby2ruby (>= 1.2.5)
ruby_parser (>= 2.0.5)
sexp_processor (>= 3.0.5)
tins (0.4.3)
tins (0.5.3)
tzinfo (0.3.33)
yajl-ruby (1.1.0)

Expand Down
23 changes: 13 additions & 10 deletions lib/ruote/amqp/participant.rb
Expand Up @@ -260,7 +260,7 @@ def forget; opt('forget'); end

# How a workitem is turned into an AMQP message payload (string).
#
# Feel free to override this method to accomodate your needs.
# Feel free to override this method to accommodate your needs.
#
def encode_workitem

Expand All @@ -269,28 +269,31 @@ def encode_workitem

# How a "cancelitem" is turned into an AMQP message payload (string).
#
# Feel free to override this method to accomodate your needs.
# Feel free to override this method to accommodate your needs.
#
def encode_cancelitem

Rufus::Json.encode(
'cancel' => true, 'fei' => @fei.h, 'flavour' => @flavour)
end

# Default AMQP.connect method.
#
# Feel free to override this method to accommodate your needs (See
# the README for an example).
#
def amqp_connect

AMQP.connect(Ruote.keys_to_sym(opt('connection') || {}))
end

# Given connection options passed at registration time (when the
# participant is registered in ruote) or from the process definition,
# returns an AMQP::Channel instance.
#
def channel

Thread.current['_ruote_amqp_channel'] ||= begin

conn_opts = (opt('connection') || {}).each_with_object({}) { |(k, v), h|
h[k.to_sym] = v
}

AMQP::Channel.new(AMQP.connect(conn_opts))
end
Thread.current['_ruote_amqp_channel'] ||= AMQP::Channel.new(amqp_connect)
end

# Given exchange options passed at registrations time or from the process
Expand Down

0 comments on commit dbcf112

Please sign in to comment.