thrift-amqp 0.2.2 → 0.2.3
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 +4 -4
- data/lib/thrift/amqp/client.rb +33 -8
- data/lib/thrift/amqp/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a39a5e783d243c6a1f4f5a595a6fdcf1fa2552e5
|
4
|
+
data.tar.gz: 4ed02c44bd570c34389a04ae5faa90aa2fec01a2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 68ef35270696f943921db74310a8524ecb4e8a2cebdab831542604f61fd43a57e1b18ba945de7ec358c45a5035d8228a581bf91d5933646dcb4a89ed01619b9d
|
7
|
+
data.tar.gz: 942a385f3975fcbd85e1990cab57ffe0d2f3ae3a5a6d474e559c5123ff1be8a0935de28f15371d409cdab63a0c0f76b3cd4986e207dfd175a0a59b0630a396f5
|
data/lib/thrift/amqp/client.rb
CHANGED
@@ -7,20 +7,43 @@ require 'securerandom'
|
|
7
7
|
|
8
8
|
module Thrift
|
9
9
|
class AMQPClientTransport < BaseTransport
|
10
|
-
|
10
|
+
class << self
|
11
|
+
def from_channel(channel, exchange_name, routing_key)
|
12
|
+
new(nil, exchange_name, routing_key, channel: channel)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def initialize(amqp_uri, exchange_name, routing_key, opts = {})
|
11
17
|
@outbuf = Bytes.empty_byte_buffer
|
12
18
|
@inbuf_r, @inbuf_w = IO.pipe(binmode: true)
|
13
19
|
@inbuf_w.set_encoding('binary')
|
14
|
-
@conn = Bunny.new(amqp_uri)
|
15
20
|
|
16
|
-
|
21
|
+
if opts[:channel]
|
22
|
+
@channel = opts[:channel]
|
23
|
+
else
|
24
|
+
@conn = Bunny.new(amqp_uri)
|
25
|
+
end
|
26
|
+
|
27
|
+
@opened = false
|
28
|
+
@handle_conn_lifecycle = opts[:channel].nil?
|
29
|
+
@exchange_name = exchange_name
|
30
|
+
@routing_key = routing_key
|
17
31
|
end
|
18
32
|
|
19
33
|
def open
|
20
34
|
return if open?
|
21
35
|
|
22
|
-
@
|
23
|
-
|
36
|
+
if @channel.nil? || !@channel.open?
|
37
|
+
unless @conn
|
38
|
+
raise TransportException.new(
|
39
|
+
TransportException::NOT_OPEN, 'channel cosed'
|
40
|
+
)
|
41
|
+
end
|
42
|
+
|
43
|
+
@conn.start
|
44
|
+
@channel = @conn.create_channel
|
45
|
+
end
|
46
|
+
|
24
47
|
@service_exchange = @channel.exchange(@exchange_name)
|
25
48
|
@reply_queue = @channel.queue('', auto_delete: true, exclusive: true)
|
26
49
|
|
@@ -28,18 +51,20 @@ module Thrift
|
|
28
51
|
@inbuf_w << Bytes.force_binary_encoding(payload)
|
29
52
|
@channel.acknowledge(delivery_info.delivery_tag, false)
|
30
53
|
end
|
54
|
+
@opened = true
|
31
55
|
end
|
32
56
|
|
33
57
|
|
34
58
|
def close
|
35
59
|
if open?
|
36
60
|
@reply_queue.delete
|
37
|
-
@channel.close
|
61
|
+
@channel.close if @handle_conn_lifecycle
|
62
|
+
@opened = false
|
38
63
|
end
|
39
64
|
end
|
40
65
|
|
41
66
|
def open?
|
42
|
-
@channel && @channel.open?
|
67
|
+
@opened && @channel && @channel.open?
|
43
68
|
end
|
44
69
|
|
45
70
|
def read(sz)
|
@@ -66,7 +91,7 @@ module Thrift
|
|
66
91
|
protected
|
67
92
|
|
68
93
|
def generate_uuid
|
69
|
-
|
94
|
+
SecureRandom.hex(13)
|
70
95
|
end
|
71
96
|
end
|
72
97
|
end
|
data/lib/thrift/amqp/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: thrift-amqp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexis Montagne
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-07-
|
11
|
+
date: 2017-07-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|