Module: ASS
- Defined in:
- lib/ass.rb,
lib/ass.rb
Overview
TODO a way to specify serializer (json, marshal…)
Defined Under Namespace
Classes: Actor, CallbackFactory, Client, RPC, Server
Class Method Summary
collapse
-
.actor(name, opts = {}, &block) ⇒ Object
-
.call(name, method, data, opts, meta) ⇒ Object
-
.cast(name, method, data, opts, meta) ⇒ Object
-
.client(opts = {}) ⇒ Object
the opts is used to initiate an RPC.
-
.mq ⇒ Object
-
.rpc(opts = {}) ⇒ Object
-
.server(name, opts = {}, &block) ⇒ Object
-
.start(settings = {}) ⇒ Object
-
.stop ⇒ Object
Class Method Details
.actor(name, opts = {}, &block) ⇒ Object
23
24
25
26
27
28
29
|
# File 'lib/ass.rb', line 23
def actor(name,opts={},&block)
s = ASS::Actor.new(name,opts)
if block
s.react(&block)
end
s
end
|
.call(name, method, data, opts, meta) ⇒ Object
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/ass.rb', line 63
def call(name,method,data,opts,meta)
payload = {
:method => method,
:data => data,
:meta => meta,
}
payload.merge(:version => opts[:version]) if opts.has_key?(:version)
payload.merge(:meta => opts[:meta]) if opts.has_key?(:meta)
@mq.direct(name,:no_declare => true).publish(::Marshal.dump(payload),opts)
true
end
|
.cast(name, method, data, opts, meta) ⇒ Object
59
60
61
|
# File 'lib/ass.rb', line 59
def cast(name,method,data,opts,meta)
call(name,method,data,opts.merge(:reply_to => nil),meta)
end
|
.client(opts = {}) ⇒ Object
the opts is used to initiate an RPC
36
37
38
|
# File 'lib/ass.rb', line 36
def client(opts={})
ASS::Client.new(opts)
end
|
.mq ⇒ Object
55
56
57
|
# File 'lib/ass.rb', line 55
def mq
@mq
end
|
.rpc(opts = {}) ⇒ Object
31
32
33
|
# File 'lib/ass.rb', line 31
def rpc(opts={})
ASS::RPC.new(opts)
end
|
.server(name, opts = {}, &block) ⇒ Object
15
16
17
18
19
20
21
|
# File 'lib/ass.rb', line 15
def server(name,opts={},&block)
s = ASS::Server.new(name,opts)
if block
s.react(&block)
end
s
end
|
.start(settings = {}) ⇒ Object
41
42
43
44
45
46
47
48
|
# File 'lib/ass.rb', line 41
def start(settings={})
raise "should have one ASS per eventmachine" if EM.reactor_running? == true EM.run {
@mq = ::MQ.new(AMQP.start(settings))
yield if block_given?
}
end
|
.stop ⇒ Object
50
51
52
53
|
# File 'lib/ass.rb', line 50
def stop
AMQP.stop{ EM.stop }
true
end
|