Skip to content

Instantly share code, notes, and snippets.

@kano4
Created March 9, 2012 06:16
Show Gist options
  • Save kano4/2005311 to your computer and use it in GitHub Desktop.
Save kano4/2005311 to your computer and use it in GitHub Desktop.
active mq
現在rubyからfirefoxなどを実行する方法を調査中。
クライアント
#!/bin/ruby
require 'yaml'
require 'rubygems'
require 'stomp'
conn = Stomp::Client.new("test", "", "localhost", 61613)
dest = "/queue/stomp_sample"
time = Time.now.to_s
msg = {'ID' => 'AAA', 'URL' => 'http://www.yahoo.co.jp', 'width' => '1024', 'height' => '768'}
conn.publish(dest, msg.to_yaml)
conn.close
サーバ
require 'yaml'
require 'rubygems'
require 'stomp'
conn = Stomp::Connection.open "test", "", "localhost", 61613
dest = "/queue/stomp_sample"
conn.subscribe dest
while true
msg = conn.receive # キューが空の場合は待ち受け
decode_msg = YAML::load(msg.body)
puts 'GET ACTION'
url = decode_msg["URL"]
width = decode_msg["width"]
height = decode_msg["height"]
# fork { exec("echo #{decode_msg["URL"]}") }
fork { exec("./screenshot.sh") }
puts '---------'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment