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/urgent_messages"
my_remote_queue = FreeMessageQueue::ClientQueue.new(QA)
# pick one message
msg = my_remote_queue.get()
puts " == URGENT MESSSAGE == "
puts msg
# put an urgent message on the queue e.g.in yaml
msg = "
title: server don't answer a ping request
date_time: 2008-06-01 20:19:28
server: 10.10.30.62
"
my_remote_queue.put(msg)
Instance Method Summary collapse
-
#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(data) ⇒ Object
(also: #post)
this puts one message to the queue as a string.
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 = url end |
Instance Method Details
#poll ⇒ Object Also known as: get
this returns one message from the queue as a string
55 56 57 58 59 60 61 62 |
# File 'lib/fmq/client.rb', line 55 def poll() url = URI.parse(@url) req = Net::HTTP::Get.new(url.path) res = Net::HTTP.start(url.host, url.port) do |http| http.request(req) end res.body end |
#put(data) ⇒ Object Also known as: post
this puts one message to the queue as a string
67 68 69 70 71 72 |
# File 'lib/fmq/client.rb', line 67 def put(data) url = URI.parse(@url) res = Net::HTTP.start(url.host, url.port) do |http| http.post(url.path, data) end end |