Class: Topic
- Inherits:
-
Object
- Object
- Topic
- Defined in:
- lib/topic.rb
Overview
Simple representation of a topic
Instance Method Summary collapse
- #dequeue(durable) ⇒ Object
- #enqueue(payload, durable) ⇒ Object
- #info ⇒ Object
-
#initialize(server, port, context, topic, subscriber) ⇒ Topic
constructor
A new instance of Topic.
Constructor Details
#initialize(server, port, context, topic, subscriber) ⇒ Topic
Returns a new instance of Topic.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/topic.rb', line 8 def initialize(server,port,context,topic,subscriber) @server = server @port = port @context = context @topic = topic @subscriber = subscriber @base_url = "http://#{@server}:#{@port}/#{@context}/topics/#{@topic}" descriptor = RestClient.get(@base_url) @name = Nokogiri::XML(descriptor).xpath('/topic/name/text()') @create_url = Nokogiri::XML(descriptor).xpath("/topic/link[@rel='create']/@href").text @pull_url = Nokogiri::XML(descriptor).xpath("/topic/link[@rel='pull-consumers']/@href").text warn "Connected to topic #{@name}" # warn "Create URL [#{@create_url}]" # warn "Pull URL [#{@pull_url}]" end |
Instance Method Details
#dequeue(durable) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/topic.rb', line 35 def dequeue(durable) lookup = RestClient.post(@pull_url,{:durable=>durable,:name=>@subscriber}) warn "Getting message from [#{lookup.headers[:msg_consume_next]}]" = RestClient.post(lookup.headers[:msg_consume_next],{:durable=>durable,:name=>@subscriber}) puts end |
#enqueue(payload, durable) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/topic.rb', line 28 def enqueue(payload,durable) warn "Pushing message [#{payload}]" response = RestClient.post("#{@create_url}?durable=#{durable}",payload,{:contentType=>"application/xml"}) raise "Message not created" if response.code != 201 warn "Message created at #{response.headers[:date]}" end |
#info ⇒ Object
24 25 26 |
# File 'lib/topic.rb', line 24 def info puts "" end |