mbus 1.0.0
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.
- checksums.yaml +7 -0
- data/README.mediawiki +169 -0
- data/Rakefile +24 -0
- data/bin/console +11 -0
- data/bin/messagebus_swarm +77 -0
- data/lib/messagebus.rb +62 -0
- data/lib/messagebus/client.rb +166 -0
- data/lib/messagebus/cluster_map.rb +161 -0
- data/lib/messagebus/connection.rb +118 -0
- data/lib/messagebus/consumer.rb +447 -0
- data/lib/messagebus/custom_errors.rb +37 -0
- data/lib/messagebus/dottable_hash.rb +113 -0
- data/lib/messagebus/error_status.rb +42 -0
- data/lib/messagebus/logger.rb +45 -0
- data/lib/messagebus/message.rb +168 -0
- data/lib/messagebus/messagebus_types.rb +107 -0
- data/lib/messagebus/producer.rb +187 -0
- data/lib/messagebus/swarm.rb +49 -0
- data/lib/messagebus/swarm/controller.rb +296 -0
- data/lib/messagebus/swarm/drone.rb +195 -0
- data/lib/messagebus/swarm/drone/logging_worker.rb +53 -0
- data/lib/messagebus/validations.rb +68 -0
- data/lib/messagebus/version.rb +36 -0
- data/messagebus.gemspec +29 -0
- data/spec/messagebus/client_spec.rb +157 -0
- data/spec/messagebus/cluster_map_spec.rb +178 -0
- data/spec/messagebus/consumer_spec.rb +338 -0
- data/spec/messagebus/dottable_hash_spec.rb +137 -0
- data/spec/messagebus/message_spec.rb +93 -0
- data/spec/messagebus/producer_spec.rb +147 -0
- data/spec/messagebus/swarm/controller_spec.rb +73 -0
- data/spec/messagebus/validations_spec.rb +71 -0
- data/spec/spec_helper.rb +10 -0
- data/vendor/gems/stomp.rb +23 -0
- data/vendor/gems/stomp/client.rb +360 -0
- data/vendor/gems/stomp/connection.rb +583 -0
- data/vendor/gems/stomp/errors.rb +39 -0
- data/vendor/gems/stomp/ext/hash.rb +24 -0
- data/vendor/gems/stomp/message.rb +68 -0
- metadata +138 -0
@@ -0,0 +1,37 @@
|
|
1
|
+
# Copyright (c) 2012, Groupon, Inc.
|
2
|
+
# All rights reserved.
|
3
|
+
#
|
4
|
+
# Redistribution and use in source and binary forms, with or without
|
5
|
+
# modification, are permitted provided that the following conditions
|
6
|
+
# are met:
|
7
|
+
#
|
8
|
+
# Redistributions of source code must retain the above copyright notice,
|
9
|
+
# this list of conditions and the following disclaimer.
|
10
|
+
#
|
11
|
+
# Redistributions in binary form must reproduce the above copyright
|
12
|
+
# notice, this list of conditions and the following disclaimer in the
|
13
|
+
# documentation and/or other materials provided with the distribution.
|
14
|
+
#
|
15
|
+
# Neither the name of GROUPON nor the names of its contributors may be
|
16
|
+
# used to endorse or promote products derived from this software without
|
17
|
+
# specific prior written permission.
|
18
|
+
#
|
19
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
20
|
+
# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
21
|
+
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
22
|
+
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
23
|
+
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
24
|
+
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
25
|
+
# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
26
|
+
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
27
|
+
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
28
|
+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
29
|
+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30
|
+
|
31
|
+
module Messagebus
|
32
|
+
class InvalidAcknowledgementType < StandardError; end
|
33
|
+
class InvalidDestination < StandardError; end
|
34
|
+
class InvalidHost < StandardError; end
|
35
|
+
class MessageReceiveTimeout < RuntimeError; end
|
36
|
+
class ErrorFrameReceived < RuntimeError; end
|
37
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
# Copyright (c) 2012, Groupon, Inc.
|
2
|
+
# All rights reserved.
|
3
|
+
#
|
4
|
+
# Redistribution and use in source and binary forms, with or without
|
5
|
+
# modification, are permitted provided that the following conditions
|
6
|
+
# are met:
|
7
|
+
#
|
8
|
+
# Redistributions of source code must retain the above copyright notice,
|
9
|
+
# this list of conditions and the following disclaimer.
|
10
|
+
#
|
11
|
+
# Redistributions in binary form must reproduce the above copyright
|
12
|
+
# notice, this list of conditions and the following disclaimer in the
|
13
|
+
# documentation and/or other materials provided with the distribution.
|
14
|
+
#
|
15
|
+
# Neither the name of GROUPON nor the names of its contributors may be
|
16
|
+
# used to endorse or promote products derived from this software without
|
17
|
+
# specific prior written permission.
|
18
|
+
#
|
19
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
20
|
+
# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
21
|
+
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
22
|
+
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
23
|
+
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
24
|
+
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
25
|
+
# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
26
|
+
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
27
|
+
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
28
|
+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
29
|
+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30
|
+
|
31
|
+
module Messagebus
|
32
|
+
class DottableHash < Hash
|
33
|
+
|
34
|
+
def initialize(plain_old_hash={})
|
35
|
+
merge!(plain_old_hash)
|
36
|
+
end
|
37
|
+
|
38
|
+
def respond_to?(method)
|
39
|
+
true
|
40
|
+
end
|
41
|
+
|
42
|
+
def method_missing(method, *arguments, &block)
|
43
|
+
key = method.to_s
|
44
|
+
if key.match(/\=$/)
|
45
|
+
self[key.chop] = arguments.first
|
46
|
+
elsif self.has_key?(key)
|
47
|
+
self[key]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def [](key)
|
52
|
+
super(key.to_s)
|
53
|
+
end
|
54
|
+
|
55
|
+
def []=(key, value)
|
56
|
+
super(key.to_s, deep_stringify(value))
|
57
|
+
end
|
58
|
+
|
59
|
+
def merge!(hash)
|
60
|
+
super(stringify_keys(hash))
|
61
|
+
end
|
62
|
+
|
63
|
+
def replace(hash)
|
64
|
+
super(stringify_keys(hash))
|
65
|
+
end
|
66
|
+
|
67
|
+
def delete(key)
|
68
|
+
super(key.to_s)
|
69
|
+
end
|
70
|
+
|
71
|
+
def has_key?(key)
|
72
|
+
super(key.to_s)
|
73
|
+
end
|
74
|
+
|
75
|
+
def fetch(key)
|
76
|
+
super(key.to_s)
|
77
|
+
end
|
78
|
+
|
79
|
+
def assoc(key)
|
80
|
+
super(key.to_s)
|
81
|
+
end
|
82
|
+
|
83
|
+
def values_at(*args)
|
84
|
+
super(*args.collect(&:to_s))
|
85
|
+
end
|
86
|
+
|
87
|
+
alias :store :[]=
|
88
|
+
alias :update :merge!
|
89
|
+
alias :merge :merge!
|
90
|
+
alias :key? :has_key?
|
91
|
+
alias :include? :has_key?
|
92
|
+
|
93
|
+
private
|
94
|
+
|
95
|
+
def stringify_keys(hash)
|
96
|
+
hash.inject({}) do |acc, (key, value)|
|
97
|
+
acc[key.to_s] = deep_stringify(hash[key])
|
98
|
+
acc
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def deep_stringify(element)
|
103
|
+
case element
|
104
|
+
when Array
|
105
|
+
element.collect {|value| deep_stringify(value)}
|
106
|
+
when Hash
|
107
|
+
self.class.new(stringify_keys(element))
|
108
|
+
else
|
109
|
+
element
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# Copyright (c) 2012, Groupon, Inc.
|
2
|
+
# All rights reserved.
|
3
|
+
#
|
4
|
+
# Redistribution and use in source and binary forms, with or without
|
5
|
+
# modification, are permitted provided that the following conditions
|
6
|
+
# are met:
|
7
|
+
#
|
8
|
+
# Redistributions of source code must retain the above copyright notice,
|
9
|
+
# this list of conditions and the following disclaimer.
|
10
|
+
#
|
11
|
+
# Redistributions in binary form must reproduce the above copyright
|
12
|
+
# notice, this list of conditions and the following disclaimer in the
|
13
|
+
# documentation and/or other materials provided with the distribution.
|
14
|
+
#
|
15
|
+
# Neither the name of GROUPON nor the names of its contributors may be
|
16
|
+
# used to endorse or promote products derived from this software without
|
17
|
+
# specific prior written permission.
|
18
|
+
#
|
19
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
20
|
+
# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
21
|
+
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
22
|
+
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
23
|
+
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
24
|
+
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
25
|
+
# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
26
|
+
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
27
|
+
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
28
|
+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
29
|
+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30
|
+
|
31
|
+
module Messagebus
|
32
|
+
class MessageStatus
|
33
|
+
CODES = {
|
34
|
+
"1000" => "Invalid Acknowledgement Type",
|
35
|
+
"1010" => "Invalid Host",
|
36
|
+
"1020" => "Invalid Destination"
|
37
|
+
}
|
38
|
+
|
39
|
+
def initialize(code, message, backtrace = nil)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# Copyright (c) 2012, Groupon, Inc.
|
2
|
+
# All rights reserved.
|
3
|
+
#
|
4
|
+
# Redistribution and use in source and binary forms, with or without
|
5
|
+
# modification, are permitted provided that the following conditions
|
6
|
+
# are met:
|
7
|
+
#
|
8
|
+
# Redistributions of source code must retain the above copyright notice,
|
9
|
+
# this list of conditions and the following disclaimer.
|
10
|
+
#
|
11
|
+
# Redistributions in binary form must reproduce the above copyright
|
12
|
+
# notice, this list of conditions and the following disclaimer in the
|
13
|
+
# documentation and/or other materials provided with the distribution.
|
14
|
+
#
|
15
|
+
# Neither the name of GROUPON nor the names of its contributors may be
|
16
|
+
# used to endorse or promote products derived from this software without
|
17
|
+
# specific prior written permission.
|
18
|
+
#
|
19
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
20
|
+
# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
21
|
+
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
22
|
+
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
23
|
+
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
24
|
+
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
25
|
+
# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
26
|
+
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
27
|
+
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
28
|
+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
29
|
+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30
|
+
|
31
|
+
require 'logger'
|
32
|
+
|
33
|
+
module Messagebus
|
34
|
+
module Logging
|
35
|
+
class MyLogger < Logger
|
36
|
+
def error(message, exception=nil)
|
37
|
+
if exception
|
38
|
+
message += "\n" + exception.message + "\n" + exception.backtrace.join("\n")
|
39
|
+
end
|
40
|
+
|
41
|
+
super(message)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,168 @@
|
|
1
|
+
# Copyright (c) 2012, Groupon, Inc.
|
2
|
+
# All rights reserved.
|
3
|
+
#
|
4
|
+
# Redistribution and use in source and binary forms, with or without
|
5
|
+
# modification, are permitted provided that the following conditions
|
6
|
+
# are met:
|
7
|
+
#
|
8
|
+
# Redistributions of source code must retain the above copyright notice,
|
9
|
+
# this list of conditions and the following disclaimer.
|
10
|
+
#
|
11
|
+
# Redistributions in binary form must reproduce the above copyright
|
12
|
+
# notice, this list of conditions and the following disclaimer in the
|
13
|
+
# documentation and/or other materials provided with the distribution.
|
14
|
+
#
|
15
|
+
# Neither the name of GROUPON nor the names of its contributors may be
|
16
|
+
# used to endorse or promote products derived from this software without
|
17
|
+
# specific prior written permission.
|
18
|
+
#
|
19
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
20
|
+
# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
21
|
+
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
22
|
+
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
23
|
+
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
24
|
+
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
25
|
+
# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
26
|
+
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
27
|
+
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
28
|
+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
29
|
+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30
|
+
|
31
|
+
require "json"
|
32
|
+
require "thrift"
|
33
|
+
require "digest/md5"
|
34
|
+
|
35
|
+
module Messagebus
|
36
|
+
# Container class for frames, misnamed technically
|
37
|
+
class Message
|
38
|
+
attr_reader :raw_message
|
39
|
+
|
40
|
+
@@serializer = ::Thrift::Serializer.new
|
41
|
+
@@deserializer = ::Thrift::Deserializer.new
|
42
|
+
@@serializer_lock = Mutex.new
|
43
|
+
@@deserializer_lock = Mutex.new
|
44
|
+
|
45
|
+
class << self
|
46
|
+
def create(payload, properties = nil, binary = false)
|
47
|
+
Messagebus::Message.create_message(define_thrift(payload, binary), properties)
|
48
|
+
end
|
49
|
+
|
50
|
+
# Creates message from base64 encoded thrift bytes.
|
51
|
+
# We use Stomp protocol for server communication which internally
|
52
|
+
# uses string (utf-8). Base64 encoding is needed to avoid corner
|
53
|
+
# cases with weird bytes etc.
|
54
|
+
def get_message_from_thrift_binary(body)
|
55
|
+
binary_string = Base64.decode64(body)
|
56
|
+
rmessage = nil
|
57
|
+
@@deserializer_lock.synchronize do
|
58
|
+
rmessage = @@deserializer.deserialize(Messagebus::Thrift::MessageInternal.new, binary_string)
|
59
|
+
end
|
60
|
+
Messagebus::Message.create_message_from_message_internal(rmessage)
|
61
|
+
end
|
62
|
+
|
63
|
+
def define_thrift(payload, binary = false)
|
64
|
+
options = {}
|
65
|
+
|
66
|
+
if binary
|
67
|
+
if RUBY_VERSION.to_f >= 1.9
|
68
|
+
payload.force_encoding('UTF-8')
|
69
|
+
end
|
70
|
+
options.merge!({
|
71
|
+
:messageFormat => Messagebus::Thrift::MessagePayloadType::BINARY,
|
72
|
+
:binaryPayload => payload
|
73
|
+
})
|
74
|
+
elsif payload.is_a?(Hash) || (payload.respond_to?(:to_json) && !payload.is_a?(String))
|
75
|
+
options.merge!({
|
76
|
+
:messageFormat => Messagebus::Thrift::MessagePayloadType::JSON,
|
77
|
+
:stringPayload => payload.to_json
|
78
|
+
})
|
79
|
+
elsif payload.is_a?(String)
|
80
|
+
#Only UTF-8 is supported by thrift. Should warn to use binary if not ascii or utf-8 but there's no logger
|
81
|
+
#I believe all users use utf8 or ascii.
|
82
|
+
if RUBY_VERSION.to_f >= 1.9
|
83
|
+
payload.force_encoding('UTF-8')
|
84
|
+
end
|
85
|
+
options.merge!({
|
86
|
+
:messageFormat => Messagebus::Thrift::MessagePayloadType::STRING,
|
87
|
+
:stringPayload => payload
|
88
|
+
})
|
89
|
+
else
|
90
|
+
# TODO: Create specific error class
|
91
|
+
raise "Type not supported"
|
92
|
+
end
|
93
|
+
|
94
|
+
Messagebus::Thrift::MessagePayload.new(options)
|
95
|
+
end
|
96
|
+
|
97
|
+
# TODO: Why use this in utils when
|
98
|
+
# trying to follow a factory pattern?
|
99
|
+
def create_message_from_message_internal(raw_message)
|
100
|
+
Message.new(raw_message)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def message_id
|
105
|
+
@raw_message.messageId
|
106
|
+
end
|
107
|
+
|
108
|
+
def message_properties
|
109
|
+
@raw_message.properties
|
110
|
+
end
|
111
|
+
|
112
|
+
def message_properties=(hash)
|
113
|
+
@raw_message.properties = hash
|
114
|
+
end
|
115
|
+
|
116
|
+
def payload_type
|
117
|
+
@raw_message.payload.messageFormat
|
118
|
+
end
|
119
|
+
|
120
|
+
def payload
|
121
|
+
payload = @raw_message.payload
|
122
|
+
|
123
|
+
if payload.binary?
|
124
|
+
@raw_message.payload.binaryPayload
|
125
|
+
elsif payload.json? || payload.string?
|
126
|
+
@raw_message.payload.stringPayload
|
127
|
+
else
|
128
|
+
raise "Payload is not an understandable type: #{payload.messageFormat}"
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
def to_thrift_binary
|
133
|
+
binary_string = nil
|
134
|
+
@@serializer_lock.synchronize do
|
135
|
+
binary_string = @@serializer.serialize(@raw_message)
|
136
|
+
end
|
137
|
+
Base64.encode64(binary_string);
|
138
|
+
end
|
139
|
+
|
140
|
+
private
|
141
|
+
|
142
|
+
def initialize(raw_message)
|
143
|
+
@raw_message = raw_message
|
144
|
+
end
|
145
|
+
|
146
|
+
|
147
|
+
class << self
|
148
|
+
# Returns the payload as a string salted with current milliseconds since epoch.
|
149
|
+
def get_salted_payload(payload)
|
150
|
+
t = Time.now
|
151
|
+
data = payload.binary? ? payload.binaryPayload : payload.stringPayload
|
152
|
+
data += t.to_i.to_s
|
153
|
+
data += t.tv_usec.to_s
|
154
|
+
data
|
155
|
+
end
|
156
|
+
|
157
|
+
def create_message(payload, properties = nil)
|
158
|
+
raw_message = Messagebus::Thrift::MessageInternal.new
|
159
|
+
raw_message.messageId = Digest::MD5.hexdigest(get_salted_payload(payload))
|
160
|
+
raw_message.payload = payload
|
161
|
+
raw_message.properties = properties if properties
|
162
|
+
|
163
|
+
Message.new(raw_message)
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
@@ -0,0 +1,107 @@
|
|
1
|
+
# Copyright (c) 2012, Groupon, Inc.
|
2
|
+
# All rights reserved.
|
3
|
+
#
|
4
|
+
# Redistribution and use in source and binary forms, with or without
|
5
|
+
# modification, are permitted provided that the following conditions
|
6
|
+
# are met:
|
7
|
+
#
|
8
|
+
# Redistributions of source code must retain the above copyright notice,
|
9
|
+
# this list of conditions and the following disclaimer.
|
10
|
+
#
|
11
|
+
# Redistributions in binary form must reproduce the above copyright
|
12
|
+
# notice, this list of conditions and the following disclaimer in the
|
13
|
+
# documentation and/or other materials provided with the distribution.
|
14
|
+
#
|
15
|
+
# Neither the name of GROUPON nor the names of its contributors may be
|
16
|
+
# used to endorse or promote products derived from this software without
|
17
|
+
# specific prior written permission.
|
18
|
+
#
|
19
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
20
|
+
# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
21
|
+
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
22
|
+
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
23
|
+
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
24
|
+
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
25
|
+
# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
26
|
+
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
27
|
+
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
28
|
+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
29
|
+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30
|
+
|
31
|
+
#
|
32
|
+
# Autogenerated by Thrift
|
33
|
+
#
|
34
|
+
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
|
35
|
+
#
|
36
|
+
|
37
|
+
|
38
|
+
module Messagebus
|
39
|
+
module Thrift
|
40
|
+
module MessagePayloadType
|
41
|
+
JSON = 1
|
42
|
+
BINARY = 2
|
43
|
+
STRING = 3
|
44
|
+
VALUE_MAP = {1 => "JSON", 2 => "BINARY", 3 => "STRING"}
|
45
|
+
VALID_VALUES = Set.new([JSON, BINARY, STRING]).freeze
|
46
|
+
end
|
47
|
+
|
48
|
+
class MessagePayload
|
49
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
50
|
+
MESSAGEFORMAT = 1
|
51
|
+
STRINGPAYLOAD = 2
|
52
|
+
BINARYPAYLOAD = 3
|
53
|
+
|
54
|
+
FIELDS = {
|
55
|
+
MESSAGEFORMAT => {:type => ::Thrift::Types::I32, :name => 'messageFormat', :enum_class => Messagebus::Thrift::MessagePayloadType},
|
56
|
+
STRINGPAYLOAD => {:type => ::Thrift::Types::STRING, :name => 'stringPayload', :optional => true},
|
57
|
+
BINARYPAYLOAD => {:type => ::Thrift::Types::STRING, :name => 'binaryPayload', :binary => true, :optional => true}
|
58
|
+
}
|
59
|
+
|
60
|
+
def struct_fields; FIELDS; end
|
61
|
+
|
62
|
+
def binary?
|
63
|
+
@messageFormat == Messagebus::Thrift::MessagePayloadType::BINARY
|
64
|
+
end
|
65
|
+
|
66
|
+
def json?
|
67
|
+
@messageFormat == Messagebus::Thrift::MessagePayloadType::JSON
|
68
|
+
end
|
69
|
+
|
70
|
+
def string?
|
71
|
+
@messageFormat == Messagebus::Thrift::MessagePayloadType::STRING
|
72
|
+
end
|
73
|
+
|
74
|
+
def validate
|
75
|
+
raise ::Thrift::ProtocolException.new(::Thrift::ProtocolException::UNKNOWN, 'Required field messageFormat is unset!') unless @messageFormat
|
76
|
+
unless @messageFormat.nil? || Messagebus::Thrift::MessagePayloadType::VALID_VALUES.include?(@messageFormat)
|
77
|
+
raise ::Thrift::ProtocolException.new(::Thrift::ProtocolException::UNKNOWN, 'Invalid value of field messageFormat!')
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
::Thrift::Struct.generate_accessors self
|
82
|
+
end
|
83
|
+
|
84
|
+
class MessageInternal
|
85
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
86
|
+
MESSAGEID = 1
|
87
|
+
PAYLOAD = 2
|
88
|
+
PROPERTIES = 3
|
89
|
+
|
90
|
+
FIELDS = {
|
91
|
+
MESSAGEID => {:type => ::Thrift::Types::STRING, :name => 'messageId'},
|
92
|
+
PAYLOAD => {:type => ::Thrift::Types::STRUCT, :name => 'payload', :class => Messagebus::Thrift::MessagePayload},
|
93
|
+
PROPERTIES => {:type => ::Thrift::Types::MAP, :name => 'properties', :key => {:type => ::Thrift::Types::STRING}, :value => {:type => ::Thrift::Types::STRING}, :optional => true}
|
94
|
+
}
|
95
|
+
|
96
|
+
def struct_fields; FIELDS; end
|
97
|
+
|
98
|
+
def validate
|
99
|
+
raise ::Thrift::ProtocolException.new(::Thrift::ProtocolException::UNKNOWN, 'Required field messageId is unset!') unless @messageId
|
100
|
+
raise ::Thrift::ProtocolException.new(::Thrift::ProtocolException::UNKNOWN, 'Required field payload is unset!') unless @payload
|
101
|
+
end
|
102
|
+
|
103
|
+
::Thrift::Struct.generate_accessors self
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
end
|