eventq_base 1.15.0-java

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 3e775e37e2b345a940c9c1c639661ed173a077b787dc28efb4245448a218083c
4
+ data.tar.gz: 5ee3ac3fb1810b18c8f4510cdaa17d98f4d01eac46cdbf960df1da0cd174d765
5
+ SHA512:
6
+ metadata.gz: 879bccd09f01df061bd0e2ad3ba2e110f38da121358f9ab8ee05f9b41f101dc1df655676546a82dfd64c1abaabe8c7922811d173e539b1ecd22e90943728da3a
7
+ data.tar.gz: 85d1945fda553fe7d61a272eec97e3443ef247f4f69c7f567e1c1568b9fb79a449811da475f19d7d1aef7e2e5499ba67b75013db4843e2f34f35f383b662429e
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "eventq_base"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,33 @@
1
+ module EventQ
2
+ class Configuration
3
+
4
+ def self.serialization_provider=(value)
5
+ @serialization_provider = value
6
+ end
7
+
8
+ def self.serialization_provider
9
+ if RUBY_PLATFORM =~ /java/
10
+ @serialization_provider ||= EventQ::SerializationProviders::JSON_PROVIDER
11
+ else
12
+ @serialization_provider ||= EventQ::SerializationProviders::OJ_PROVIDER
13
+ end
14
+ end
15
+
16
+ def self.signature_provider=(value)
17
+ @signature_provider = value
18
+ end
19
+
20
+ def self.signature_provider
21
+ @signature_provider ||= EventQ::SignatureProviders::SHA256
22
+ end
23
+
24
+ def self.signature_secret=(value)
25
+ @signature_secret = value
26
+ end
27
+
28
+ def self.signature_secret
29
+ @signature_secret
30
+ end
31
+
32
+ end
33
+ end
@@ -0,0 +1,7 @@
1
+ module EventQ
2
+ class EventRaisedExchange < Exchange
3
+ def initialize
4
+ @name = 'eventq.eventraised.ex'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module EventQ
2
+ class EventRaisedQueue < Queue
3
+ def initialize
4
+ @name = 'eventq.eventraised'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ module EventQ
2
+ class EventQClientContract
3
+
4
+ def raise_event(event_type, event)
5
+
6
+ end
7
+
8
+ end
9
+ end
@@ -0,0 +1,28 @@
1
+ require 'logger'
2
+
3
+ module EventQ
4
+
5
+ def self.logger
6
+ return @@logger
7
+ end
8
+
9
+ def self.set_logger(logger)
10
+ @@logger = logger
11
+ end
12
+
13
+ def self.log(type, message)
14
+ case type
15
+ when :info
16
+ logger.info(message)
17
+ when :debug
18
+ logger.debug(message)
19
+ when :error
20
+ logger.error(message)
21
+ end
22
+ rescue
23
+ #do nothing
24
+ end
25
+
26
+ EventQ.set_logger(Logger.new(STDOUT))
27
+
28
+ end
@@ -0,0 +1,9 @@
1
+ module EventQ
2
+ module Exceptions
3
+ class InvalidSignatureException < StandardError
4
+ def initialize(message = "Invalid message signature.")
5
+ super(message)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1 @@
1
+ require_relative 'exceptions/invalid_signature_exception'
@@ -0,0 +1,5 @@
1
+ module EventQ
2
+ class Exchange
3
+ attr_accessor :name
4
+ end
5
+ end
@@ -0,0 +1,19 @@
1
+ module EventQ
2
+ class MessageArgs
3
+ attr_reader :type
4
+ attr_reader :content_type
5
+ attr_reader :retry_attempts
6
+ attr_accessor :abort
7
+ attr_accessor :drop
8
+ attr_reader :context
9
+
10
+ def initialize(type:, retry_attempts:, context: {}, content_type:)
11
+ @type = type
12
+ @retry_attempts = retry_attempts
13
+ @abort = false
14
+ @drop = false
15
+ @context = context
16
+ @content_type = content_type
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,57 @@
1
+ module EventQ
2
+ class NonceManager
3
+
4
+ def self.configure(server:,timeout:10000,lifespan:3600000)
5
+ @server_url = server
6
+ @timeout = timeout
7
+ @lifespan = lifespan
8
+ end
9
+
10
+ def self.server_url
11
+ @server_url
12
+ end
13
+
14
+ def self.timeout
15
+ @timeout
16
+ end
17
+
18
+ def self.lifespan
19
+ @lifespan
20
+ end
21
+
22
+ def self.is_allowed?(nonce)
23
+ if @server_url == nil
24
+ return true
25
+ end
26
+
27
+ require 'redlock'
28
+ lock = Redlock::Client.new([ @server_url ]).lock(nonce, @timeout)
29
+ if lock == false
30
+ EventQ.log(:info, "[#{self.class}] - Message has already been processed: #{nonce}")
31
+ return false
32
+ end
33
+
34
+ return true
35
+ end
36
+
37
+ def self.complete(nonce)
38
+ if @server_url != nil
39
+ Redis.new(url: @server_url).expire(nonce, @lifespan)
40
+ end
41
+ return true
42
+ end
43
+
44
+ def self.failed(nonce)
45
+ if @server_url != nil
46
+ Redis.new(url: @server_url).del(nonce)
47
+ end
48
+ return true
49
+ end
50
+
51
+ def self.reset
52
+ @server_url = nil
53
+ @timeout = nil
54
+ @lifespan = nil
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,23 @@
1
+ module EventQ
2
+ class Queue
3
+ attr_accessor :name
4
+ attr_accessor :allow_retry
5
+ attr_accessor :retry_delay
6
+ attr_accessor :max_retry_attempts
7
+ attr_accessor :allow_retry_back_off
8
+ attr_accessor :max_retry_delay
9
+ attr_accessor :require_signature
10
+
11
+ def initialize
12
+ @allow_retry = false
13
+ #default retry delay is 30 seconds
14
+ @retry_delay = 30000
15
+ #default max retry attempts is 5
16
+ @max_retry_attempts = 5
17
+ #default retry back off settings
18
+ @allow_retry_back_off = false
19
+ #default require signature to false
20
+ @require_signature = false
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,31 @@
1
+ module EventQ
2
+ class QueueMessage
3
+ extend ClassKit
4
+
5
+ attr_accessor_type :id, type: String
6
+ attr_accessor_type :retry_attempts, type: Integer
7
+ attr_accessor_type :type, type: String
8
+ attr_accessor_type :content
9
+ attr_accessor_type :content_type, type: String
10
+ attr_accessor_type :created, type: Time
11
+ attr_accessor_type :signature, type: String
12
+ attr_accessor_type :context, type: Hash
13
+
14
+ def initialize
15
+ @retry_attempts = 0
16
+ @created = Time.now.to_i
17
+ @id = SecureRandom.uuid
18
+ @context = {}
19
+ end
20
+
21
+ # Creates a signature for the message
22
+ #
23
+ # @param provider [EventQ::SignatureProviders::Sha256SignatureProvider] Signature provider that implements
24
+ # a write method
25
+ def sign(provider)
26
+ return unless EventQ::Configuration.signature_secret
27
+
28
+ self.signature = provider.write(message: self, secret: EventQ::Configuration.signature_secret)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,23 @@
1
+ module EventQ
2
+ # Contract class for queue workers
3
+ class QueueWorkerContract
4
+
5
+ def start(queue, options = {}, &block)
6
+
7
+ end
8
+
9
+ def stop
10
+
11
+ end
12
+
13
+ def on_retry_exceeded(&block)
14
+
15
+ end
16
+
17
+ def running?
18
+
19
+ end
20
+
21
+ end
22
+ end
23
+
@@ -0,0 +1,15 @@
1
+ module EventQ
2
+ module SerializationProviders
3
+ class BinarySerializationProvider
4
+
5
+ def serialize(object)
6
+ Marshal::dump(object)
7
+ end
8
+
9
+ def deserialize(msg)
10
+ Marshal::load(msg)
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,28 @@
1
+ module EventQ
2
+ module SerializationProviders
3
+ class JsonSerializationProvider
4
+
5
+ def initialize
6
+ require 'class_kit'
7
+ require 'hash_kit'
8
+ @class_kit_helper = ClassKit::Helper.new
9
+ @hash_helper = HashKit::Helper.new
10
+ end
11
+
12
+ def serialize(object)
13
+ JSON.dump(object_to_hash(object))
14
+ end
15
+
16
+ def deserialize(json)
17
+ return @class_kit_helper.from_json(json: json, klass: EventQ::QueueMessage)
18
+ end
19
+
20
+ private
21
+
22
+ def object_to_hash(object)
23
+ return object if object.is_a?(Hash)
24
+ @hash_helper.to_hash(object)
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,24 @@
1
+ module EventQ
2
+ module SerializationProviders
3
+ class OjSerializationProvider
4
+
5
+ def initialize
6
+ require 'oj'
7
+ @json_serializer = EventQ::SerializationProviders::JsonSerializationProvider.new
8
+ end
9
+
10
+ def serialize(object)
11
+ return Oj.dump(object, mode: :object)
12
+ end
13
+
14
+ def deserialize(json)
15
+ begin
16
+ return Oj.load(json)
17
+ rescue Oj::ParseError
18
+ EventQ.log(:debug, "[#{self.class}] - Failed to deserialize using Oj, falling back to JsonSerializationProvider.")
19
+ return @json_serializer.deserialize(json)
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,33 @@
1
+ require_relative 'serialization_providers/json_serialization_provider'
2
+ unless RUBY_PLATFORM =~ /java/
3
+ require_relative 'serialization_providers/oj_serialization_provider'
4
+ end
5
+ require_relative 'serialization_providers/binary_serialization_provider'
6
+
7
+ module EventQ
8
+ module SerializationProviders
9
+
10
+ OJ_PROVIDER = 'oj'.freeze
11
+ JSON_PROVIDER = 'json'.freeze
12
+ BINARY_PROVIDER = 'binary'.freeze
13
+
14
+ class Manager
15
+ def initialize
16
+ @providers = {}
17
+ unless RUBY_PLATFORM =~ /java/
18
+ @providers[OJ_PROVIDER] = EventQ::SerializationProviders::OjSerializationProvider
19
+ end
20
+ @providers[JSON_PROVIDER] = EventQ::SerializationProviders::JsonSerializationProvider
21
+ @providers[BINARY_PROVIDER] = EventQ::SerializationProviders::BinarySerializationProvider
22
+ end
23
+
24
+ def get_provider(provider_type)
25
+ provider = @providers[provider_type]
26
+ if provider == nil
27
+ raise "Invalid provider type specified: #{provider_type}"
28
+ end
29
+ return provider.new
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,31 @@
1
+ module EventQ
2
+ module SignatureProviders
3
+ class Sha256SignatureProvider
4
+
5
+ def initialize
6
+ require 'openssl'
7
+ require 'base64'
8
+ @serializer = serialization_provider_manager.get_provider(EventQ::Configuration.serialization_provider)
9
+ end
10
+
11
+ #This method is called to create a signature for a message
12
+ def write(message:, secret:)
13
+ json = @serializer.serialize(message.content)
14
+ hash = OpenSSL::HMAC.digest('sha256', secret, json)
15
+ Base64.encode64(hash)
16
+ end
17
+
18
+ #This method is called to validate a message signature
19
+ def valid?(message:, secret:)
20
+ signature = write(message: message, secret: secret)
21
+ message.signature == signature
22
+ end
23
+
24
+ private
25
+
26
+ def serialization_provider_manager
27
+ EventQ::SerializationProviders::Manager.new
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,44 @@
1
+ require_relative 'signature_providers/sha256_signature_provider'
2
+
3
+ module EventQ
4
+ module SignatureProviders
5
+
6
+ SHA256 = 'sha256'.freeze
7
+
8
+ class Manager
9
+ def initialize
10
+ @providers = {}
11
+ @providers[SHA256] = EventQ::SignatureProviders::Sha256SignatureProvider
12
+ end
13
+
14
+ #This method is called to get a signature provider
15
+ def get_provider(provider_type)
16
+ provider = @providers[provider_type]
17
+ if provider == nil
18
+ raise "Invalid provider type specified: #{provider_type}"
19
+ end
20
+ return provider.new
21
+ end
22
+
23
+ #This method is called to validate a queue message's signature
24
+ def validate_signature(message:, queue:)
25
+ valid = true
26
+
27
+ if queue.require_signature == true && message.signature == nil
28
+ valid = false
29
+ elsif message.signature != nil
30
+ provider = get_provider(EventQ::Configuration.signature_provider)
31
+ valid = provider.valid?(message: message, secret: EventQ::Configuration.signature_secret)
32
+ end
33
+
34
+ if !valid
35
+ raise EventQ::Exceptions::InvalidSignatureException.new
36
+ end
37
+
38
+ true
39
+
40
+ end
41
+
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,13 @@
1
+ module EventQ
2
+ class SubscriptionManagerContract
3
+
4
+ def subscribe(event_type, queue)
5
+
6
+ end
7
+
8
+ def unsubscribe(queue)
9
+
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module EventqBase
2
+ VERSION = "1.15.0"
3
+ end
@@ -0,0 +1,20 @@
1
+ module EventQ
2
+ # Module to be used by concrete worker classes to tag each thread working on a message
3
+ # Allows to be used in custom logging to track group of log messages per queue message processing.
4
+ module WorkerId
5
+ def tag_processing_thread
6
+ Thread.current[key_name] = SecureRandom.uuid
7
+ end
8
+
9
+ def untag_processing_thread
10
+ Thread.current[key_name] = nil
11
+ end
12
+
13
+ private
14
+
15
+ def key_name
16
+ 'worker_id'.freeze
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,26 @@
1
+ require 'securerandom'
2
+ require 'redlock'
3
+ require 'class_kit'
4
+ require 'hash_kit'
5
+
6
+
7
+ require_relative 'eventq_base/version'
8
+ require_relative 'eventq_base/eventq_logger'
9
+ require_relative 'eventq_base/queue'
10
+ require_relative 'eventq_base/exchange'
11
+ require_relative 'eventq_base/queue_message'
12
+ require_relative 'eventq_base/message_args'
13
+ require_relative 'eventq_base/queue_worker_contract'
14
+ require_relative 'eventq_base/event_raised_exchange'
15
+ require_relative 'eventq_base/event_raised_queue'
16
+ require_relative 'eventq_base/subscription_manager_contract'
17
+ require_relative 'eventq_base/eventq_client_contract'
18
+ require_relative 'eventq_base/configuration'
19
+ require_relative 'eventq_base/serialization_providers'
20
+ require_relative 'eventq_base/worker_id'
21
+ require_relative 'eventq_base/nonce_manager'
22
+ require_relative 'eventq_base/signature_providers'
23
+ require_relative 'eventq_base/exceptions'
24
+
25
+
26
+
metadata ADDED
@@ -0,0 +1,154 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: eventq_base
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.15.0
5
+ platform: java
6
+ authors:
7
+ - vaughanbrittonsage
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-06-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '1.11'
19
+ name: bundler
20
+ prerelease: false
21
+ type: :development
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '10.0'
33
+ name: rake
34
+ prerelease: false
35
+ type: :development
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ name: rspec
48
+ prerelease: false
49
+ type: :development
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ name: class_kit
62
+ prerelease: false
63
+ type: :runtime
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ name: redlock
76
+ prerelease: false
77
+ type: :runtime
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ requirement: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ name: jruby-openssl
90
+ prerelease: false
91
+ type: :runtime
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: This gem contains the base classes and contracts required by any eventq
98
+ implementations.
99
+ email:
100
+ - vaughanbritton@gmail.com
101
+ executables: []
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - bin/console
106
+ - bin/setup
107
+ - lib/eventq_base.rb
108
+ - lib/eventq_base/configuration.rb
109
+ - lib/eventq_base/event_raised_exchange.rb
110
+ - lib/eventq_base/event_raised_queue.rb
111
+ - lib/eventq_base/eventq_client_contract.rb
112
+ - lib/eventq_base/eventq_logger.rb
113
+ - lib/eventq_base/exceptions.rb
114
+ - lib/eventq_base/exceptions/invalid_signature_exception.rb
115
+ - lib/eventq_base/exchange.rb
116
+ - lib/eventq_base/message_args.rb
117
+ - lib/eventq_base/nonce_manager.rb
118
+ - lib/eventq_base/queue.rb
119
+ - lib/eventq_base/queue_message.rb
120
+ - lib/eventq_base/queue_worker_contract.rb
121
+ - lib/eventq_base/serialization_providers.rb
122
+ - lib/eventq_base/serialization_providers/binary_serialization_provider.rb
123
+ - lib/eventq_base/serialization_providers/json_serialization_provider.rb
124
+ - lib/eventq_base/serialization_providers/oj_serialization_provider.rb
125
+ - lib/eventq_base/signature_providers.rb
126
+ - lib/eventq_base/signature_providers/sha256_signature_provider.rb
127
+ - lib/eventq_base/subscription_manager_contract.rb
128
+ - lib/eventq_base/version.rb
129
+ - lib/eventq_base/worker_id.rb
130
+ homepage: https://github.com/vaughanbrittonsage/eventq
131
+ licenses:
132
+ - MIT
133
+ metadata: {}
134
+ post_install_message:
135
+ rdoc_options: []
136
+ require_paths:
137
+ - lib
138
+ required_ruby_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ required_rubygems_version: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - ">="
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ requirements: []
149
+ rubyforge_project:
150
+ rubygems_version: 2.6.11
151
+ signing_key:
152
+ specification_version: 4
153
+ summary: This gem contains the base classes and contracts required by any eventq implementations.
154
+ test_files: []