angie-core-api 0.4.0 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/angie-core-api/configuration.rb +1 -1
- data/lib/angie-core-api/message/amqp_client.rb +64 -0
- data/lib/angie-core-api/message/queue.rb +2 -2
- data/lib/angie-core-api/message/{client.rb → stomp_client.rb} +1 -1
- data/lib/angie-core-api/message/topic.rb +42 -0
- data/lib/angie-core-api/message.rb +3 -1
- metadata +21 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3da094ea147d35ccaeaee12c4a6281f135bd656f59ec01953130d89140dab7c7
|
4
|
+
data.tar.gz: 03d586544e65919eab587c55275091e3dd5aae221b3d04016c663ea3b312facb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 26bb0f6396229f20656fd73d0c5326261c333ac8d159dca1df8e54bd6bdc551c318d972505119f95f80febd5c1a45997f7a9b5e084c36ad47a2831a268851964
|
7
|
+
data.tar.gz: 025fe3564796719622ee751ac76d0cf8a14877993fa5d6dc74df8a45bedaf94c05dda85737033fcb96c442a5c98b2ab8a16f414968728ac09896989dcaf80b6c
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "bunny"
|
4
|
+
|
5
|
+
module AngieCoreApi
|
6
|
+
module Message
|
7
|
+
class AMQPClient
|
8
|
+
include Singleton
|
9
|
+
|
10
|
+
attr :config, :connection, :channel
|
11
|
+
|
12
|
+
def self.instance
|
13
|
+
@@instance ||= new
|
14
|
+
end
|
15
|
+
|
16
|
+
def initialize
|
17
|
+
@rabbitmq_config = AngieCoreApi.configuration.rabbitmq
|
18
|
+
@config = HashWithIndifferentAccess.new(@rabbitmq_config)
|
19
|
+
|
20
|
+
@connection = Bunny.new(config[:url])
|
21
|
+
@connection.start
|
22
|
+
|
23
|
+
@channel = @connection.create_channel
|
24
|
+
|
25
|
+
puts "Connected to #{amqp_url}"
|
26
|
+
rescue Bunny::TCPConnectionFailed => e
|
27
|
+
puts "Connection to #{amqp_url} failed: #{e.message}"
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.classes
|
31
|
+
Dir["app/topics/*.rb"].
|
32
|
+
map { |file| File.basename(file, ".rb") }.
|
33
|
+
select { |type| type != "application_topic" }.
|
34
|
+
map(&:camelize).
|
35
|
+
map(&:constantize)
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.connect
|
39
|
+
AMQPClient.instance
|
40
|
+
|
41
|
+
classes.each { |k| k.new }
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.disconnect!
|
45
|
+
amqp_url = AMQPClient.instance.amqp_url
|
46
|
+
|
47
|
+
AMQPClient.instance.channel.close
|
48
|
+
AMQPClient.instance.connection.close
|
49
|
+
@@instance = nil
|
50
|
+
|
51
|
+
puts "Disconnected from #{amqp_url}"
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.reconnect!
|
55
|
+
disconnect!
|
56
|
+
connect
|
57
|
+
end
|
58
|
+
|
59
|
+
def amqp_url
|
60
|
+
@config[:url].sub(/\/\/.*@/, "//")
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -17,11 +17,11 @@ module AngieCoreApi
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def self.publish(message)
|
20
|
-
|
20
|
+
StompClient.new.async.publish(queue, message)
|
21
21
|
end
|
22
22
|
|
23
23
|
def self.subscribe
|
24
|
-
|
24
|
+
StompClient.new.async.subscribe(queue) do |message|
|
25
25
|
self.new.receive(message)
|
26
26
|
end
|
27
27
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module AngieCoreApi
|
4
|
+
module Message
|
5
|
+
class Topic
|
6
|
+
def self.topic_name
|
7
|
+
@topic_name ||= name.underscore.dasherize
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.exchange
|
11
|
+
@exchange ||= AMQPClient.instance.channel.topic(topic_name, durable: true, auto_delete: true)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.subscribe(routing_key, options = { manual_ack: false })
|
15
|
+
queue = AMQPClient.instance.channel.queue(queue_name(routing_key), durable: true)
|
16
|
+
queue.bind(exchange, routing_key: routing_key)
|
17
|
+
|
18
|
+
queue.subscribe(options.merge(block: false)) do |delivery_info, properties, payload|
|
19
|
+
yield delivery_info, properties, payload
|
20
|
+
AMQPClient.instance.channel.acknowledge(delivery_info.delivery_tag) if options[:manual_ack]
|
21
|
+
end
|
22
|
+
rescue Interrupt => _
|
23
|
+
AMQPClient.reconnect!
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.publish(routing_key, message_id, payload)
|
27
|
+
exchange.publish(payload,
|
28
|
+
message_id: message_id,
|
29
|
+
routing_key: routing_key,
|
30
|
+
persistent: true,
|
31
|
+
content_type: "application/json",
|
32
|
+
content_encoding: "UTF-8")
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def self.queue_name(routing_key)
|
38
|
+
"#{AMQPClient.instance.config[:app]}.#{routing_key}"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -2,7 +2,9 @@
|
|
2
2
|
|
3
3
|
module AngieCoreApi
|
4
4
|
module Message
|
5
|
-
autoload :
|
5
|
+
autoload :AMQPClient, "angie-core-api/message/amqp_client"
|
6
|
+
autoload :StompClient, "angie-core-api/message/stomp_client"
|
6
7
|
autoload :Queue, "angie-core-api/message/queue"
|
8
|
+
autoload :Topic, "angie-core-api/message/topic"
|
7
9
|
end
|
8
10
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: angie-core-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Angie Hospitality
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-10-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actioncable
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 0.
|
61
|
+
version: 0.20.0
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 0.
|
68
|
+
version: 0.20.0
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: stomp
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '1.4'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: bunny
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '2.17'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '2.17'
|
83
97
|
description: Angie CoreAPI Ruby gem
|
84
98
|
email:
|
85
99
|
- rubygems@angie.ai
|
@@ -94,8 +108,10 @@ files:
|
|
94
108
|
- lib/angie-core-api/flight.rb
|
95
109
|
- lib/angie-core-api/map.rb
|
96
110
|
- lib/angie-core-api/message.rb
|
97
|
-
- lib/angie-core-api/message/
|
111
|
+
- lib/angie-core-api/message/amqp_client.rb
|
98
112
|
- lib/angie-core-api/message/queue.rb
|
113
|
+
- lib/angie-core-api/message/stomp_client.rb
|
114
|
+
- lib/angie-core-api/message/topic.rb
|
99
115
|
- lib/angie-core-api/notification.rb
|
100
116
|
- lib/angie-core-api/railtie.rb
|
101
117
|
- lib/angie-core-api/tv.rb
|