smith 0.5.12 → 0.5.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/smithctl +16 -19
- data/lib/smith.rb +25 -41
- data/lib/smith/agent.rb +96 -66
- data/lib/smith/agent_monitoring.rb +3 -4
- data/lib/smith/agent_process.rb +16 -9
- data/lib/smith/amqp_errors.rb +53 -0
- data/lib/smith/application/agency.rb +23 -20
- data/lib/smith/bootstrap.rb +3 -3
- data/lib/smith/command.rb +2 -2
- data/lib/smith/command_base.rb +4 -0
- data/lib/smith/commands/agency/agents.rb +19 -19
- data/lib/smith/commands/agency/kill.rb +6 -2
- data/lib/smith/commands/agency/list.rb +2 -4
- data/lib/smith/commands/agency/logger.rb +27 -28
- data/lib/smith/commands/agency/metadata.rb +1 -5
- data/lib/smith/commands/agency/object_count.rb +13 -11
- data/lib/smith/commands/agency/restart.rb +18 -9
- data/lib/smith/commands/agency/start.rb +34 -25
- data/lib/smith/commands/agency/stop.rb +58 -41
- data/lib/smith/commands/agency/version.rb +10 -10
- data/lib/smith/commands/common.rb +7 -4
- data/lib/smith/commands/smithctl/acl.rb +46 -37
- data/lib/smith/commands/smithctl/commands.rb +1 -1
- data/lib/smith/commands/smithctl/firehose.rb +30 -0
- data/lib/smith/commands/smithctl/pop.rb +39 -32
- data/lib/smith/commands/smithctl/push.rb +70 -51
- data/lib/smith/commands/smithctl/rm.rb +32 -9
- data/lib/smith/commands/smithctl/subscribe.rb +36 -0
- data/lib/smith/commands/smithctl/top.rb +1 -1
- data/lib/smith/exceptions.rb +2 -0
- data/lib/smith/messaging/acl/agency_command.proto +4 -0
- data/lib/smith/messaging/acl/default.rb +8 -1
- data/lib/smith/messaging/amqp_options.rb +2 -2
- data/lib/smith/messaging/message_counter.rb +21 -0
- data/lib/smith/messaging/payload.rb +47 -49
- data/lib/smith/messaging/queue.rb +50 -0
- data/lib/smith/messaging/queue_definition.rb +18 -0
- data/lib/smith/messaging/queue_factory.rb +20 -29
- data/lib/smith/messaging/receiver.rb +211 -173
- data/lib/smith/messaging/requeue.rb +91 -0
- data/lib/smith/messaging/sender.rb +184 -28
- data/lib/smith/messaging/util.rb +72 -0
- data/lib/smith/queue_definitions.rb +11 -0
- data/lib/smith/version.rb +1 -1
- metadata +18 -10
- data/lib/smith/messaging/endpoint.rb +0 -116
@@ -1,116 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
module Smith
|
3
|
-
module Messaging
|
4
|
-
class Endpoint
|
5
|
-
include Logger
|
6
|
-
|
7
|
-
attr_accessor :denormalized_queue_name, :queue_name
|
8
|
-
|
9
|
-
def initialize(queue_name, options)
|
10
|
-
@denormalized_queue_name = queue_name
|
11
|
-
@queue_name = normalise(queue_name)
|
12
|
-
@message_counts = Hash.new(0)
|
13
|
-
@options = options
|
14
|
-
end
|
15
|
-
|
16
|
-
def ready(&blk)
|
17
|
-
Smith.channel.direct(@queue_name, options.exchange) do |exchange|
|
18
|
-
@exchange = exchange
|
19
|
-
|
20
|
-
exchange.on_return do |basic_return,metadata,payload|
|
21
|
-
logger.error { "#{ACL::Payload.decode(payload.clone, metadata.type)} was returned! Exchange: #{reply_code.exchange}, reply_code = #{basic_return.reply_code}, reply_text = #{basic_return.reply_text}" }
|
22
|
-
logger.error { "Properties: #{metadata.properties}" }
|
23
|
-
end
|
24
|
-
|
25
|
-
logger.verbose { "Creating queue: [queue]:#{denormalized_queue_name} [options]:#{options.queue}" }
|
26
|
-
|
27
|
-
Smith.channel.queue(queue_name, options.queue) do |queue|
|
28
|
-
@queue = queue
|
29
|
-
@options.queue_name = queue_name
|
30
|
-
queue.bind(exchange, :routing_key => queue_name)
|
31
|
-
blk.call(self)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def number_of_messages
|
37
|
-
@queue.status do |num_messages, num_consumers|
|
38
|
-
yield num_messages
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def number_of_consumers
|
43
|
-
@queue.status do |num_messages, num_consumers|
|
44
|
-
yield num_consumers
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
# Return the total number of messages sent or received for the named queue.
|
49
|
-
def counter
|
50
|
-
@message_counts[queue_name]
|
51
|
-
end
|
52
|
-
|
53
|
-
def messages?(blk=nil, err=proc {logger.debug { "No messages on #{@denormalized_queue_name}" } })
|
54
|
-
number_of_messages do |n|
|
55
|
-
if n > 0
|
56
|
-
if blk.respond_to? :call
|
57
|
-
blk.call(self)
|
58
|
-
else
|
59
|
-
yield self
|
60
|
-
end
|
61
|
-
else
|
62
|
-
err.call
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
def consumers?(blk=nil, err=proc {logger.debug { "Nothing listening on #{@denormalized_queue_name}" } })
|
68
|
-
number_of_consumers do |n|
|
69
|
-
if n > 0
|
70
|
-
if blk.respond_to? :call
|
71
|
-
blk.call(self)
|
72
|
-
else
|
73
|
-
yield self
|
74
|
-
end
|
75
|
-
else
|
76
|
-
if err.respond_to? :call
|
77
|
-
err.call
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
def timeout(timeout, blk=nil, &block)
|
84
|
-
cancel_timeout
|
85
|
-
blk ||= block
|
86
|
-
@timeout = EventMachine::Timer.new(timeout, blk)
|
87
|
-
end
|
88
|
-
|
89
|
-
protected
|
90
|
-
|
91
|
-
attr_accessor :exchange, :queue, :options
|
92
|
-
|
93
|
-
def increment_counter(value=1)
|
94
|
-
@message_counts[queue_name] += value
|
95
|
-
end
|
96
|
-
|
97
|
-
def denormalise(name)
|
98
|
-
name.sub(/#{Regexp.escape("#{Smith.config.smith.namespace}.")}/, '')
|
99
|
-
end
|
100
|
-
|
101
|
-
def normalise(name)
|
102
|
-
"#{Smith.config.smith.namespace}.#{name}"
|
103
|
-
end
|
104
|
-
|
105
|
-
def cancel_timeout
|
106
|
-
@timeout.cancel if @timeout
|
107
|
-
end
|
108
|
-
|
109
|
-
private
|
110
|
-
|
111
|
-
def random(prefix = '', suffix = '')
|
112
|
-
"#{prefix}#{SecureRandom.hex(8)}#{suffix}"
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|