angie-core-api 0.4.0 → 0.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6b4884c3195b5668cb61d7ed20fd97fa0c08209bc2b129ab45f9c776a5ce2ba0
4
- data.tar.gz: ecb5fdcbfc17ddb640a9105f33802ba7ad49bc5341e1f815a9484ea06d085159
3
+ metadata.gz: 165d3139d17e5cbbe90d75bd204e4107919a8ec837ff5ffeaa945885f3a2ecc7
4
+ data.tar.gz: 1a2eb2d0eac4be055898717168d5e60f0e5131a96395dc56f02e7b987463ec6c
5
5
  SHA512:
6
- metadata.gz: 0bb6bc79455a2b6c82bdad9e375e1507762267d1d81a6e2d22faf51d950d6b49170d1161dcb0527c918ada83aadcdae4adb0de4053279682672fb5f96f6c9097
7
- data.tar.gz: 2efd6d4c9a2de953368ab1a252c439e247dc0041b4cd5a74792e175656cdf12dc28c46f2f3beccb940e9c9f1ab59294433c6090f2d2600c347978ea113fdbd52
6
+ metadata.gz: 83be6528c7c5a7d8367fa5dc3182ecb9348c830c7f59c69564ead71e6d005eca8852e8ab4fb2a405e500a4c326ea0b9e84dd5196f9c39324322fed843c848dc1
7
+ data.tar.gz: 6aa2b795b7aff71eade956bb5e4bf5555f2692bb12a32acc1d282178a2b5b7a49fe30898b76259a2905d3dd5992827761574c38c5029ebc5b3e026d376a60cc8
@@ -2,7 +2,7 @@
2
2
 
3
3
  module AngieCoreApi
4
4
  autoload :Configuration, "angie-core-api/configuration"
5
- autoload :Client, "angie-core-api/client"
5
+ autoload :StompClient, "angie-core-api/client"
6
6
  autoload :Flight, "angie-core-api/flight"
7
7
  autoload :Map, "angie-core-api/map"
8
8
  autoload :Notification, "angie-core-api/notification"
@@ -6,6 +6,6 @@ module AngieCoreApi
6
6
 
7
7
  config_accessor(:url)
8
8
  config_accessor(:token)
9
- config_accessor(:activemq)
9
+ config_accessor(:rabbitmq)
10
10
  end
11
11
  end
@@ -2,7 +2,9 @@
2
2
 
3
3
  module AngieCoreApi
4
4
  module Message
5
- autoload :Client, "angie-core-api/message/client"
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
@@ -0,0 +1,59 @@
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 amqp_url
55
+ @config[:url].sub(/\/\/.*@/, "//")
56
+ end
57
+ end
58
+ end
59
+ end
@@ -17,11 +17,11 @@ module AngieCoreApi
17
17
  end
18
18
 
19
19
  def self.publish(message)
20
- Client.new.async.publish(queue, message)
20
+ StompClient.new.async.publish(queue, message)
21
21
  end
22
22
 
23
23
  def self.subscribe
24
- Client.new.async.subscribe(queue) do |message|
24
+ StompClient.new.async.subscribe(queue) do |message|
25
25
  self.new.receive(message)
26
26
  end
27
27
  end
@@ -4,7 +4,7 @@ require "stomp"
4
4
 
5
5
  module AngieCoreApi
6
6
  module Message
7
- class Client
7
+ class StompClient
8
8
  include Concurrent::Async
9
9
 
10
10
  def initialize
@@ -0,0 +1,40 @@
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
+ end
23
+
24
+ def self.publish(routing_key, message_id, payload)
25
+ exchange.publish(payload,
26
+ message_id: message_id,
27
+ routing_key: routing_key,
28
+ persistent: true,
29
+ content_type: "application/json",
30
+ content_encoding: "UTF-8")
31
+ end
32
+
33
+ private
34
+
35
+ def self.queue_name(routing_key)
36
+ "#{AMQPClient.instance.config[:app]}.#{routing_key}"
37
+ end
38
+ end
39
+ end
40
+ 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.0
4
+ version: 0.5.0
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-03-18 00:00:00.000000000 Z
11
+ date: 2021-05-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actioncable
@@ -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/client.rb
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