Class: Rcom::Topic
- Inherits:
-
Object
- Object
- Rcom::Topic
- Defined in:
- lib/rcom/topic.rb
Overview
Implements pub/sub over topics.
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#node ⇒ Object
readonly
Returns the value of attribute node.
Instance Method Summary collapse
-
#initialize(params) ⇒ Topic
constructor
A new instance of Topic.
-
#publish(message) ⇒ true?
True if it can be published, otherwise nil.
- #subscribe {|message| ... } ⇒ Object
Constructor Details
#initialize(params) ⇒ Topic
Returns a new instance of Topic.
9 10 11 12 |
# File 'lib/rcom/topic.rb', line 9 def initialize(params) @node = params[:node] @key = params[:key] end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
4 5 6 |
# File 'lib/rcom/topic.rb', line 4 def key @key end |
#node ⇒ Object (readonly)
Returns the value of attribute node.
4 5 6 |
# File 'lib/rcom/topic.rb', line 4 def node @node end |
Instance Method Details
#publish(message) ⇒ true?
Returns true if it can be published, otherwise nil.
16 17 18 19 20 21 22 23 |
# File 'lib/rcom/topic.rb', line 16 def publish() begin node.publish(key, .to_msgpack) return true rescue return nil end end |
#subscribe {|message| ... } ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/rcom/topic.rb', line 26 def subscribe begin node.subscribe(key) do |on| on. do |channel, | = MessagePack.unpack( , symbolize_keys: true ) yield end end rescue Interrupt => _ end end |