angie-core-api 0.6.2 → 0.7.0
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/delivery_method.rb +1 -1
- data/lib/angie-core-api/{message → messaging}/amqp_client.rb +5 -16
- data/lib/angie-core-api/messaging/exchange.rb +47 -0
- data/lib/angie-core-api/messaging.rb +8 -0
- data/lib/angie-core-api/railtie.rb +6 -0
- data/lib/angie-core-api.rb +1 -1
- metadata +17 -33
- data/lib/angie-core-api/message/queue.rb +0 -30
- data/lib/angie-core-api/message/stomp_client.rb +0 -25
- data/lib/angie-core-api/message/topic.rb +0 -42
- data/lib/angie-core-api/message.rb +0 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 26c82feb3ecefb930fefc3290a1946987478a92397afaadbbe867b8dbe9a0a74
|
4
|
+
data.tar.gz: 1734d82febd6d09305ccb60680c7e529be1cc9d9c9f8f6f9936f72cfa46bac5b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a147590a98cca90118103f7dec14614bd88ea0504f447e69780b2d3b68676c5139609df6a0d6037a6695cd85e8f7d9dcfc135e2108312a04d63ebcd1f0f6942f
|
7
|
+
data.tar.gz: '044908a11813a91cdc102c0f77930d96f75a463ddd4d2e616885ca7a41b0964b8bf31a4ecfd96cc69768a92a613d5bca7b85d970c0f8f510ebb99be932646d1c'
|
@@ -3,7 +3,7 @@
|
|
3
3
|
require "bunny"
|
4
4
|
|
5
5
|
module AngieCoreApi
|
6
|
-
module
|
6
|
+
module Messaging
|
7
7
|
class AMQPClient
|
8
8
|
include Singleton
|
9
9
|
|
@@ -14,9 +14,7 @@ module AngieCoreApi
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def initialize
|
17
|
-
@
|
18
|
-
@config = HashWithIndifferentAccess.new(@rabbitmq_config)
|
19
|
-
|
17
|
+
@config = AngieCoreApi.configuration.rabbitmq.with_indifferent_access
|
20
18
|
@connection = Bunny.new(config[:url])
|
21
19
|
@connection.start
|
22
20
|
|
@@ -28,33 +26,24 @@ module AngieCoreApi
|
|
28
26
|
end
|
29
27
|
|
30
28
|
def self.classes
|
31
|
-
Dir["app/
|
29
|
+
Dir["app/exchanges/*.rb", "engines/**/app/exchanges/*.rb"].
|
32
30
|
map { |file| File.basename(file, ".rb") }.
|
33
|
-
select { |type| type != "application_topic" }.
|
34
31
|
map(&:camelize).
|
35
32
|
map(&:constantize)
|
36
33
|
end
|
37
34
|
|
38
35
|
def self.connect
|
39
36
|
AMQPClient.instance
|
40
|
-
|
41
37
|
classes.each { |k| k.new }
|
42
38
|
end
|
43
39
|
|
44
40
|
def self.disconnect!
|
45
|
-
amqp_url = AMQPClient.instance.amqp_url
|
46
|
-
|
47
|
-
AMQPClient.instance.channel.close
|
48
41
|
AMQPClient.instance.connection.close
|
49
42
|
@@instance = nil
|
50
|
-
|
51
|
-
puts "Disconnected from #{amqp_url}"
|
43
|
+
puts "Disconnected from #{AMQPClient.instance.amqp_url}"
|
52
44
|
end
|
53
45
|
|
54
|
-
|
55
|
-
disconnect!
|
56
|
-
connect
|
57
|
-
end
|
46
|
+
private
|
58
47
|
|
59
48
|
def amqp_url
|
60
49
|
@config[:url].sub(/\/\/.*@/, "//")
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module AngieCoreApi
|
4
|
+
module Messaging
|
5
|
+
class Exchange
|
6
|
+
def self.exchange(exchange_name, type:, routing_key:, queue: nil, exchange_options: {}, queue_options: {})
|
7
|
+
channel = AMQPClient.instance.channel
|
8
|
+
@exchange_name = exchange_name
|
9
|
+
|
10
|
+
# TODO: implement direct and fanout
|
11
|
+
@exchange, @queue = case type
|
12
|
+
when :topic
|
13
|
+
x = channel.topic(exchange_name, { durable: true }.merge(exchange_options))
|
14
|
+
q = channel.queue(queue, queue_options).bind(x, routing_key:) if queue
|
15
|
+
[x, q]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.subscribe(options = { manual_ack: false })
|
20
|
+
# TODO: show usage?
|
21
|
+
raise "Exchange is not defined" unless @exchange
|
22
|
+
raise "Queue is not defined" unless @queue
|
23
|
+
|
24
|
+
@queue.subscribe({ block: false }.merge(options)) do |delivery_info, properties, payload|
|
25
|
+
r = { delivery_info:, properties:, payload: }
|
26
|
+
yield r
|
27
|
+
AMQPClient.instance.channel.acknowledge(delivery_info.delivery_tag) if options[:manual_ack]
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.publish(payload, options = {})
|
32
|
+
# TODO: show usage?
|
33
|
+
raise "Exchange is not defined" unless @exchange
|
34
|
+
raise "Routing key is not defined" unless options.has_key?(:routing_key)
|
35
|
+
|
36
|
+
@exchange.publish(payload,
|
37
|
+
{
|
38
|
+
routing_key: options[:routing_key],
|
39
|
+
message_id: SecureRandom.uuid,
|
40
|
+
persistent: true,
|
41
|
+
content_type: "application/json",
|
42
|
+
content_encoding: "UTF-8"
|
43
|
+
}.merge(options))
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -7,5 +7,11 @@ module AngieCoreApi
|
|
7
7
|
ActionMailer::Base.add_delivery_method(:angie_core_api, AngieCoreApi::DeliveryMethod)
|
8
8
|
end
|
9
9
|
end
|
10
|
+
|
11
|
+
initializer "angie_core_api.connect_to_messaging" do
|
12
|
+
ActiveSupport.on_load(:active_record) do
|
13
|
+
AngieCoreApi::Messaging::AMQPClient.connect
|
14
|
+
end
|
15
|
+
end
|
10
16
|
end
|
11
17
|
end
|
data/lib/angie-core-api.rb
CHANGED
@@ -10,7 +10,7 @@ module AngieCoreApi
|
|
10
10
|
autoload :TV, "angie-core-api/tv"
|
11
11
|
autoload :Weather, "angie-core-api/weather"
|
12
12
|
autoload :DeliveryMethod, "angie-core-api/delivery_method"
|
13
|
-
autoload :
|
13
|
+
autoload :Messaging, "angie-core-api/messaging"
|
14
14
|
|
15
15
|
def self.configuration
|
16
16
|
@configuration ||= Configuration.new
|
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.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nomadix
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-05-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actioncable
|
@@ -53,47 +53,33 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '6.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: 0.18.0
|
62
|
-
type: :runtime
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: 0.18.0
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: stomp
|
56
|
+
name: bunny
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|
72
58
|
requirements:
|
73
59
|
- - "~>"
|
74
60
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
61
|
+
version: '2.20'
|
76
62
|
type: :runtime
|
77
63
|
prerelease: false
|
78
64
|
version_requirements: !ruby/object:Gem::Requirement
|
79
65
|
requirements:
|
80
66
|
- - "~>"
|
81
67
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
68
|
+
version: '2.20'
|
83
69
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
70
|
+
name: httparty
|
85
71
|
requirement: !ruby/object:Gem::Requirement
|
86
72
|
requirements:
|
87
|
-
- - "
|
73
|
+
- - ">="
|
88
74
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
75
|
+
version: 0.18.0
|
90
76
|
type: :runtime
|
91
77
|
prerelease: false
|
92
78
|
version_requirements: !ruby/object:Gem::Requirement
|
93
79
|
requirements:
|
94
|
-
- - "
|
80
|
+
- - ">="
|
95
81
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
82
|
+
version: 0.18.0
|
97
83
|
description: Nomadix CoreAPI Ruby gem
|
98
84
|
email:
|
99
85
|
- rubygems@nomadix.com
|
@@ -107,11 +93,9 @@ files:
|
|
107
93
|
- lib/angie-core-api/delivery_method.rb
|
108
94
|
- lib/angie-core-api/flight.rb
|
109
95
|
- lib/angie-core-api/map.rb
|
110
|
-
- lib/angie-core-api/
|
111
|
-
- lib/angie-core-api/
|
112
|
-
- lib/angie-core-api/
|
113
|
-
- lib/angie-core-api/message/stomp_client.rb
|
114
|
-
- lib/angie-core-api/message/topic.rb
|
96
|
+
- lib/angie-core-api/messaging.rb
|
97
|
+
- lib/angie-core-api/messaging/amqp_client.rb
|
98
|
+
- lib/angie-core-api/messaging/exchange.rb
|
115
99
|
- lib/angie-core-api/notification.rb
|
116
100
|
- lib/angie-core-api/railtie.rb
|
117
101
|
- lib/angie-core-api/thermostat.rb
|
@@ -121,7 +105,7 @@ homepage: https://nomadix.com
|
|
121
105
|
licenses: []
|
122
106
|
metadata:
|
123
107
|
homepage_uri: https://nomadix.com
|
124
|
-
post_install_message:
|
108
|
+
post_install_message:
|
125
109
|
rdoc_options: []
|
126
110
|
require_paths:
|
127
111
|
- lib
|
@@ -136,8 +120,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
136
120
|
- !ruby/object:Gem::Version
|
137
121
|
version: '0'
|
138
122
|
requirements: []
|
139
|
-
rubygems_version: 3.
|
140
|
-
signing_key:
|
123
|
+
rubygems_version: 3.3.26
|
124
|
+
signing_key:
|
141
125
|
specification_version: 4
|
142
126
|
summary: Nomadix CoreAPI Ruby gem
|
143
127
|
test_files: []
|
@@ -1,30 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module AngieCoreApi
|
4
|
-
module Message
|
5
|
-
class Queue
|
6
|
-
def self.classes
|
7
|
-
Dir["app/queues/*.rb"].
|
8
|
-
map { |file| File.basename(file, ".rb") }.
|
9
|
-
select { |type| type != "application_queue" }.
|
10
|
-
map(&:camelize).
|
11
|
-
map(&:constantize)
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.queue
|
15
|
-
path = name.underscore.sub("_queue", "")
|
16
|
-
"/queue/#{path}"
|
17
|
-
end
|
18
|
-
|
19
|
-
def self.publish(message)
|
20
|
-
StompClient.new.async.publish(queue, message)
|
21
|
-
end
|
22
|
-
|
23
|
-
def self.subscribe
|
24
|
-
StompClient.new.async.subscribe(queue) do |message|
|
25
|
-
self.new.receive(message)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "stomp"
|
4
|
-
|
5
|
-
module AngieCoreApi
|
6
|
-
module Message
|
7
|
-
class StompClient
|
8
|
-
include Concurrent::Async
|
9
|
-
|
10
|
-
def initialize
|
11
|
-
config = HashWithIndifferentAccess.new(AngieCoreApi.configuration.activemq)
|
12
|
-
@client = Stomp::Client.new(config)
|
13
|
-
end
|
14
|
-
|
15
|
-
def publish(queue, data)
|
16
|
-
@client.publish(queue, data.to_json)
|
17
|
-
@client.close
|
18
|
-
end
|
19
|
-
|
20
|
-
def subscribe(queue)
|
21
|
-
@client.subscribe(queue) { |msg| yield JSON.parse(msg.body) }
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
@@ -1,42 +0,0 @@
|
|
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
|
@@ -1,10 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module AngieCoreApi
|
4
|
-
module Message
|
5
|
-
autoload :AMQPClient, "angie-core-api/message/amqp_client"
|
6
|
-
autoload :StompClient, "angie-core-api/message/stomp_client"
|
7
|
-
autoload :Queue, "angie-core-api/message/queue"
|
8
|
-
autoload :Topic, "angie-core-api/message/topic"
|
9
|
-
end
|
10
|
-
end
|