angie-core-api 0.6.3 → 0.7.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6ea3063768ff0118db6784ddd38b7e52dd869c44b477d0029dcd6af81a66b44f
4
- data.tar.gz: 4c5267be414bf1ac4c2ee1d7a03918d4e4b38e187880ec356a9335e151096fc7
3
+ metadata.gz: 6e29f2ff5be3eda44a58b4bed2924dfc1178017c60a4a5de05ed7730d03e26c5
4
+ data.tar.gz: 1ddeff04ad553d403df11213624337e9e92d28f08781a4917c3d249acbaefa12
5
5
  SHA512:
6
- metadata.gz: 1d6becb990c27a6a2eeb6a8a57cf2e2bdd9c4b88b70f2a35d4a70170df4858d8664eb48f7a963e1e5886b69d9989100ec8de3c23324a4bad95f88892b74641ca
7
- data.tar.gz: 163f269738c85b2ef69951d1aeb3fc0e69513f4578a597f720a0ba6b11a4a48d5c3a8295e77b26c823d78c905d33f0f17959d0bdd9e2c06b2db23a42e26f7cf3
6
+ metadata.gz: 0faa69a92791402a85ef41a079b7b8ba6572ceb2d4bdf07ae419ffb816741299247bd5227cfde8a14d671c870648a000b9d7604e4b66b1450fb0400f06753c69
7
+ data.tar.gz: b6674e47f7f0c2189ba614d03b53bf236adf20c2fd4d0fd602f20b28a393d0f2c76be73b2fb8c820d42a95a0dbca657225d92bfbe172c23f2cf744f737b9b62a
@@ -3,7 +3,7 @@
3
3
  require "bunny"
4
4
 
5
5
  module AngieCoreApi
6
- module Message
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
- @rabbitmq_config = AngieCoreApi.configuration.rabbitmq
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/topics/*.rb"].
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
- def self.reconnect!
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
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AngieCoreApi
4
+ module Messaging
5
+ autoload :AMQPClient, "angie-core-api/messaging/amqp_client"
6
+ autoload :Exchange, "angie-core-api/messaging/exchange"
7
+ end
8
+ 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
@@ -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 :Message, "angie-core-api/message"
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.6.3
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nomadix
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-17 00:00:00.000000000 Z
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: httparty
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: '1.4'
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: '1.4'
68
+ version: '2.20'
83
69
  - !ruby/object:Gem::Dependency
84
- name: bunny
70
+ name: httparty
85
71
  requirement: !ruby/object:Gem::Requirement
86
72
  requirements:
87
- - - "~>"
73
+ - - ">="
88
74
  - !ruby/object:Gem::Version
89
- version: '2.17'
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: '2.17'
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/message.rb
111
- - lib/angie-core-api/message/amqp_client.rb
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
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.1.4
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