Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Ruby: new_task.rb, ARGV fix.

  • Loading branch information...
commit d83ca8fadc31559da477c0c4bcbf6916d057d40c 1 parent f5ad3b0
@botanicus botanicus authored
View
2  ruby/emit_log.rb
@@ -6,7 +6,7 @@
AMQP.start(:host => "localhost") do |connection|
channel = AMQP::Channel.new(connection)
exchange = channel.fanout("logs")
- message = (ARGV[0..-1] || ["info: Hello World!"]).join(" ")
+ message = ARGV.empty? ? "info: Hello World!" : ARGV.join(" ")
exchange.publish(message)
puts " [x] Sent #{message}"
View
4 ruby/emit_log_direct.rb
@@ -6,8 +6,8 @@
AMQP.start(:host => "localhost") do |connection|
channel = AMQP::Channel.new(connection)
exchange = channel.direct("direct_logs")
- severity = ARGV[0] || "info"
- message = (ARGV[1..-1] || ["Hello World!"]).join(" ")
+ severity = ARGV.shift || "info"
+ message = ARGV.empty? ? "Hello World!" : ARGV.join(" ")
exchange.publish(message, :routing_key => severity)
puts " [x] Sent #{severity}:#{message}"
View
4 ruby/emit_log_topic.rb
@@ -6,8 +6,8 @@
AMQP.start(:host => "localhost") do |connection|
channel = AMQP::Channel.new(connection)
exchange = channel.topic("topic_logs")
- severity = ARGV[0] || "anonymous.info"
- message = (ARGV[1..-1] || ["Hello World!"]).join(" ")
+ severity = ARGV.shift || "anonymous.info"
+ message = ARGV.empty? ? "Hello World!" : ARGV.join(" ")
exchange.publish(message, :routing_key => severity)
puts " [x] Sent #{severity}:#{message}"
View
19 ruby/new_task.rb
@@ -0,0 +1,19 @@
+#!/usr/bin/env ruby
+# encoding: utf-8
+
+require "amqp"
+
+AMQP.start(:host => "localhost") do |connection|
+ channel = AMQP::Channel.new(connection)
+ queue = channel.queue("task_queue", :durable => true)
+ message = ARGV.empty? ? "Hello World!" : ARGV.join(" ")
+
+ AMQP::Exchange.default.publish(message, :routing_key => queue.name, :persistent => true)
+ puts " [x] Sent #{message}"
+
+ EM.add_timer(0.5) do
+ connection.close do
+ EM.stop { exit }
+ end
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.