messaging 3.5.6 → 3.6.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9af5bcee24c4ab1eebcfb97e77a4793431b149e9a00ffd7cfe8d6dfb3985aa02
4
- data.tar.gz: bc2f7fc37a5b759691c9ea31398304ca0515a5d6e7ee0db7a3eccf4c79e3c534
3
+ metadata.gz: '049d3a3eac021195a546e67f3ce5351fa93a105a86a7bddc10b6fcb140533e43'
4
+ data.tar.gz: bce77446512ba9f31d3b21739ef2af2c59ac8bd89c2ff7d15006459aff3cd387
5
5
  SHA512:
6
- metadata.gz: 278f0251732828f67528b8ce72e7455df587ce18b8a1e68a26f25a43d33516b36f4b0a3e008e3fc785a7f97d73b58946a89b946ff0f34edc8c3c6b5189fe27d4
7
- data.tar.gz: 5cc743e11eac703f43783db84a2db14e88ddd6cf5a4e4f4d124589894c37edd3f1eb9ab2e07dcd7bb428a5dc0f4aa343f0037c0905cd83a4987f800b7c8be333
6
+ metadata.gz: 2b54e3f6633fa243b6fba4d20e2359c8018cbb37634a7420c75f9e2e8cf6a9da44aa0bebc139ed06ded0b887a35383be72c38c8a58ee6f3e6d288d5527b73e28
7
+ data.tar.gz: f45a5fb8cee52d26d0ef769a5557ac2fcabebc0b27bc5374a2bd5b25c930a3731b80238efc22429290bfdb0be14b915e2fc995af299d2580b1a6f2160462512f
data/.circleci/config.yml CHANGED
@@ -6,14 +6,14 @@ version: 2
6
6
  jobs:
7
7
  build:
8
8
  docker:
9
- # specify the version you desire here
10
- - image: circleci/ruby:2.4.1-node-browsers
11
- environment:
12
- CC_TEST_REPORTER_ID: 94ada9b95ee3f232a6e984809d37917cfee90ac47805429e8c49742b2e8d2276
13
- RAILS_ENV: test
14
- - image: circleci/postgres:9.6.6-alpine
15
- environment:
16
- POSTGRES_USER: postgres
9
+ - image: circleci/ruby:2.4.1-node-browsers
10
+ environment:
11
+ - CC_TEST_REPORTER_ID: 94ada9b95ee3f232a6e984809d37917cfee90ac47805429e8c49742b2e8d2276
12
+ - RAILS_ENV: test
13
+ - image: circleci/postgres:12.5-ram
14
+ environment:
15
+ - POSTGRES_HOST_AUTH_METHOD: trust
16
+ - POSTGRES_PASSWORD: password
17
17
 
18
18
  working_directory: ~/repo
19
19
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- messaging (3.5.5)
4
+ messaging (3.5.7)
5
5
  activerecord
6
6
  activesupport
7
7
  after_transaction
@@ -44,7 +44,7 @@ module Messaging
44
44
  end
45
45
 
46
46
  def create_producer
47
- kafka.client.async_producer(Config.kafka.producer.to_hash)
47
+ kafka.client.async_producer(Config.kafka.producer.to_h)
48
48
  end
49
49
  end
50
50
  end
@@ -5,21 +5,69 @@ module Messaging
5
5
  include Enumerable
6
6
 
7
7
  def each
8
- return enum_for(:each) unless block_given?
9
-
10
8
  all_categories.each do |name|
11
9
  yield Category.new(name)
12
10
  end
13
11
  end
14
12
 
13
+ # Get a category by name
14
+ #
15
+ # @param name [String] the name of the category
16
+ # @return [nil] if no category exists with the given name
17
+ # @return [Category]
15
18
  def [](name)
19
+ category = all_categories.select { |c| c == name }
20
+ return unless category
21
+
22
+ Category.new(category)
23
+ end
24
+
25
+ # Creates a table partition for the given category
26
+ #
27
+ # @param name [String] the name of the category
28
+ # @return [Category]
29
+ def create(name)
30
+ table_name = name.parameterize(separator: '_')
31
+ sql = <<~SQL
32
+ CREATE TABLE messaging.#{table_name}
33
+ PARTITION OF messaging.messages FOR VALUES IN ('#{name}');
34
+ SQL
35
+ connection.execute sql
16
36
  Category.new(name)
17
37
  end
18
38
 
39
+ # Drops the table partition (including all messages) for the given category
40
+ #
41
+ # @param name [String] the name of the category
42
+ def drop(name)
43
+ table_name = name.parameterize(separator: '_')
44
+ sql = <<~SQL
45
+ drop TABLE messaging.#{table_name}
46
+ SQL
47
+ connection.execute sql
48
+ end
49
+
19
50
  private
20
51
 
21
52
  def all_categories
22
- SerializedMessage.distinct.pluck(:stream_category).lazy
53
+ @all_categories ||= fetch_categories
54
+ end
55
+
56
+ def fetch_categories
57
+ sql = <<~SQL
58
+ SELECT child.relname AS category
59
+ FROM pg_inherits
60
+ JOIN pg_class parent ON pg_inherits.inhparent = parent.oid
61
+ JOIN pg_class child ON pg_inherits.inhrelid = child.oid
62
+ JOIN pg_namespace ON pg_namespace.oid = parent.relnamespace
63
+ WHERE pg_namespace.nspname = 'messaging' AND child.relkind in ('r', 'p')
64
+ ORDER BY category
65
+ SQL
66
+ connection.select_values(sql)
67
+ end
68
+
69
+ def connection
70
+ SerializedMessage.connection
23
71
  end
24
72
  end
25
73
  end
@@ -2,7 +2,7 @@ module Messaging
2
2
  module Adapters
3
3
  class Postgres
4
4
  class SerializedMessage < ActiveRecord::Base
5
- self.table_name = :messaging_messages
5
+ self.table_name = 'messaging.messages'
6
6
 
7
7
  attr_accessor :expected_version
8
8
 
@@ -22,16 +22,11 @@ module Messaging
22
22
  # @see Streams
23
23
  attr_reader :streams
24
24
 
25
- # @return [Categories] all the stream categories in the store
26
- # @see Categories
27
- attr_reader :categories
28
-
29
25
  # Should not be used directly. Access the store though
30
26
  # Messaging.message_store or Messaging::Adapters::Store[:postgres]
31
27
  # @api private
32
28
  def initialize
33
29
  @streams = Streams.new
34
- @categories = Categories.new
35
30
  end
36
31
 
37
32
  # Get a specific stream by name
@@ -41,8 +36,14 @@ module Messaging
41
36
  streams[name]
42
37
  end
43
38
 
39
+ # @return [Categories] all the stream categories in the store
40
+ # @see Categories
41
+ def categories
42
+ Categories.new
43
+ end
44
+
44
45
  # Get a specific category by name
45
- # @return [Stream]
46
+ # @return [Category]
46
47
  # @see Messaging.category
47
48
  def category(name)
48
49
  categories[name]
@@ -5,6 +5,12 @@ module Messaging
5
5
  # @return [String] the name of the stream
6
6
  attr_reader :name
7
7
 
8
+ # @return [String] the stream category
9
+ attr_reader :category
10
+
11
+ # @return [String] the stream id
12
+ attr_reader :id
13
+
8
14
  # Should not be used directly.
9
15
  # Use {Messaging.stream} or {Store#stream}
10
16
  # @api private
@@ -12,12 +18,13 @@ module Messaging
12
18
  # @see Store.stream
13
19
  def initialize(name)
14
20
  @name = name
21
+ @category, @id = name.split('$')
15
22
  end
16
23
 
17
24
  # Access to all messages in the stream sorted by stream_position
18
25
  # @return [ActiveRecord::Relation]
19
26
  def messages
20
- SerializedMessage.where(stream: name).order(:stream_position)
27
+ SerializedMessage.where(stream_category: category, stream_id: id).order(:stream_position)
21
28
  end
22
29
 
23
30
  # The current position of the last message in the stream
@@ -18,6 +18,38 @@ module Messaging
18
18
  private_class_method :register!
19
19
 
20
20
  register!
21
+
22
+ def create_messages_table
23
+ sql = <<~SQL
24
+ CREATE SCHEMA IF NOT EXISTS messaging;
25
+ CREATE SEQUENCE IF NOT EXISTS messaging.messages_id_seq;
26
+
27
+ CREATE TABLE messaging.messages (
28
+ id bigint DEFAULT nextval('messaging.messages_id_seq'::regclass) NOT NULL,
29
+ uuid uuid NOT NULL,
30
+ stream character varying NOT NULL,
31
+ stream_position bigint NOT NULL,
32
+ message_type character varying NOT NULL,
33
+ data jsonb,
34
+ created_at timestamp without time zone NOT NULL,
35
+ updated_at timestamp without time zone NOT NULL,
36
+ stream_category character varying,
37
+ stream_id character varying
38
+ )
39
+ PARTITION BY LIST (stream_category);
40
+
41
+ CREATE INDEX messages_id_idx ON ONLY messaging.messages USING btree (id);
42
+ CREATE INDEX messages_stream_category_id_idx ON ONLY messaging.messages USING btree (stream_category, id);
43
+ CREATE INDEX messages_stream_category_stream_id_stream_position_idx ON ONLY messaging.messages USING btree (stream_category, stream_id, stream_position);
44
+ SQL
45
+ connection.execute sql
46
+ end
47
+
48
+ private
49
+
50
+ def connection
51
+ ActiveRecord::Base.connection
52
+ end
21
53
  end
22
54
  end
23
55
  end
@@ -1,3 +1,3 @@
1
1
  module Messaging
2
- VERSION = '3.5.6'.freeze
2
+ VERSION = '3.6.2'.freeze
3
3
  end
data/lib/messaging.rb CHANGED
@@ -67,6 +67,17 @@ module Messaging
67
67
  result
68
68
  end
69
69
 
70
+ # Access the stream categories in the current message store
71
+ #
72
+ # @example Creating a new category
73
+ # Messaging.categories.create('customer')
74
+ #
75
+ # @return [Messaging::Adapters::Test::Categories] when using the test adapter
76
+ # @return [Messaging::Adapters::Postgres::Categories] when using the postgres adapter
77
+ def self.categories
78
+ message_store.categories
79
+ end
80
+
70
81
  def self.category(name)
71
82
  message_store.category(name)
72
83
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: messaging
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.5.6
4
+ version: 3.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bukowskis
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-01-21 00:00:00.000000000 Z
11
+ date: 2022-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -273,7 +273,6 @@ files:
273
273
  - ".circleci/config.yml"
274
274
  - ".gitignore"
275
275
  - ".rspec"
276
- - ".ruby-version"
277
276
  - Gemfile
278
277
  - Gemfile.lock
279
278
  - README.md
@@ -351,7 +350,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
351
350
  - !ruby/object:Gem::Version
352
351
  version: '0'
353
352
  requirements: []
354
- rubygems_version: 3.1.4
353
+ rubygems_version: 3.0.3.1
355
354
  signing_key:
356
355
  specification_version: 4
357
356
  summary: A library for decoupling applications by using messaging to communicate between
data/.ruby-version DELETED
@@ -1 +0,0 @@
1
- 2.3.1