Class: FreeMessageQueue::ClientQueue
- Inherits:
-
Object
- Object
- FreeMessageQueue::ClientQueue
- Defined in:
- lib/fmq/client.rb
Overview
Here you can find the client side api for the free message queue. This api is build using the net/http facilitys
Some sample usage of the client api:
require "fmq"
# queue adress
QA = "http://localhost/webserver_agent/messages"
queue = FreeMessageQueue::ClientQueue.new(QA)
# pick one message
= queue.poll()
puts " == URGENT MESSSAGE == " if .option["Priority"] == "high"
puts .payload
# put an urgent message on the queue e.g.in yaml
payload = "message:
title: server don't answer a ping request
date_time: 2008-06-01 20:19:28
server: 10.10.30.62
"
= FreeMessageQueue::Message.new(payload, "application/yaml")
queue.put()
Instance Method Summary collapse
-
#bytes ⇒ Object
return the size of the queue in bytes.
-
#initialize(url) ⇒ ClientQueue
constructor
create a connection to a queue (by url).
-
#poll ⇒ Object
(also: #get)
this returns one message from the queue as a string.
-
#put(message) ⇒ Object
(also: #post)
this puts one message to the queue.
-
#size ⇒ Object
return the size (number of messages) of the queue.
Constructor Details
#initialize(url) ⇒ ClientQueue
create a connection to a queue (by url)
50 51 52 |
# File 'lib/fmq/client.rb', line 50 def initialize(url) @url = URI.parse(url) end |
Instance Method Details
#bytes ⇒ Object
return the size of the queue in bytes
98 99 100 |
# File 'lib/fmq/client.rb', line 98 def bytes head["QUEUE_BYTES"].to_i end |
#poll ⇒ Object Also known as: get
this returns one message from the queue as a string
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/fmq/client.rb', line 55 def poll() res = Net::HTTP.start(@url.host, @url.port) do |http| http.get(@url.path) end = Message.new(res.body, res["CONTENT-TYPE"]) res.each_key do |option_name| if option_name.upcase.match(/MESSAGE_([a-zA-Z][a-zA-Z0-9_\-]*)/) .option[$1] = res[option_name] end end return end |
#put(message) ⇒ Object Also known as: post
this puts one message to the queue
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/fmq/client.rb', line 74 def put() header = {} header["CONTENT-TYPE"] = .content_type # send all options of the message back to the client if .respond_to?(:option) && .option.size > 0 for option_name in .option.keys header["MESSAGE_#{option_name}"] = .option[option_name].to_s end end Net::HTTP.start(@url.host, @url.port) do |http| http.post(@url.path, .payload, header) end end |
#size ⇒ Object
return the size (number of messages) of the queue
93 94 95 |
# File 'lib/fmq/client.rb', line 93 def size head["QUEUE_SIZE"].to_i end |