citrus-event-bus 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1e01c431a1501e60cdc32dbbf8ca61706beb7b83
4
+ data.tar.gz: 2c1b60f32026c744cc10d2c3d1cf07bb63d25a0d
5
+ SHA512:
6
+ metadata.gz: 0fb12b7d895d630595d78376792e8149ca49943fea5e368a66b746e0c1d6b8170503e3977584d5fd9cd5bac6b851f30f5ee8bf75f36879ede2d7884eed009860
7
+ data.tar.gz: bebdd55d12518e58e02f4b3dddccdc11af3a21b73a47699a733e7bbb08b11843bf9e150016d3310be3ba807e7b61df8648e6e19f8c6a1a256b0cdad99e5c6ade
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Paweł Pacana
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # Citrus::Event::Bus
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'citrus-event-bus'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install citrus-event-bus
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( http://github.com/<my-github-username>/citrus-event-bus/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'citrus/event_bus/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "citrus-event-bus"
8
+ spec.version = Citrus::EventBus::VERSION
9
+ spec.authors = ["Paweł Pacana"]
10
+ spec.email = ["pawel.pacana@gmail.com"]
11
+ spec.summary = %q{Event bus adapter for Citrus.}
12
+ spec.homepage = ""
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.5"
21
+ spec.add_development_dependency "rake"
22
+
23
+ spec.add_dependency "poseidon", "0.0.4"
24
+ end
@@ -0,0 +1,6 @@
1
+ require 'citrus/event_bus/version'
2
+ require 'citrus/event_bus/event'
3
+ require 'citrus/event_bus/serializer'
4
+ require 'citrus/event_bus/publisher'
5
+ require 'citrus/event_bus/subscriber'
6
+ require 'citrus/event_bus/configuration'
@@ -0,0 +1,21 @@
1
+ require 'citrus/event_bus/serializer'
2
+
3
+ module Citrus
4
+ module EventBus
5
+ class Configuration
6
+ attr_reader :event_serializer, :host, :port, :topic
7
+
8
+ def initialize
9
+ @event_serializer = Serializer.new
10
+ @topic = 'citrus_stream'
11
+ @host = 'localhost'
12
+ @port = 9092
13
+ end
14
+
15
+ def connection_string
16
+ "#{host}:#{port}"
17
+ end
18
+
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,13 @@
1
+ require 'securerandom'
2
+
3
+ module Citrus
4
+ module EventBus
5
+ class Event < Struct.new(:id, :timestamp, :type, :body)
6
+
7
+ def self.for_type(type, body = nil)
8
+ self.new(SecureRandom.uuid, Time.now.to_i, type.to_s, Hash(body))
9
+ end
10
+
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,24 @@
1
+ require 'poseidon'
2
+ require 'securerandom'
3
+ require 'citrus/event_bus/configuration'
4
+
5
+ module Citrus
6
+ module EventBus
7
+ class Publisher
8
+
9
+ def initialize(configuration = Configuration.new)
10
+ @configuration = configuration
11
+ @producer = Poseidon::Producer.new([@configuration.connection_string], SecureRandom.uuid)
12
+ end
13
+
14
+ def call(event)
15
+ message = Poseidon::MessageToSend.new(
16
+ @configuration.topic,
17
+ @configuration.event_serializer.dump(event)
18
+ )
19
+ @producer.send_messages([message])
20
+ end
21
+
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,19 @@
1
+ require 'json'
2
+ require 'citrus/event_bus/event'
3
+
4
+ module Citrus
5
+ module EventBus
6
+ class Serializer
7
+
8
+ def load(event_data)
9
+ event_hash = JSON.load(event_data)
10
+ event_hash.each_with_object(Event.new) { |(key, value), event| event.send("#{key}=", value) }
11
+ end
12
+
13
+ def dump(event)
14
+ JSON.dump(event.to_h)
15
+ end
16
+
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,37 @@
1
+ require 'poseidon'
2
+ require 'securerandom'
3
+ require 'citrus/event_bus/configuration'
4
+
5
+ module Citrus
6
+ module EventBus
7
+ class Subscriber
8
+
9
+ def initialize(configuration = Configuration.new)
10
+ @configuration = configuration
11
+ @consumer = Poseidon::PartitionConsumer.new(
12
+ SecureRandom.uuid,
13
+ configuration.host,
14
+ configuration.port,
15
+ configuration.topic,
16
+ 0,
17
+ :latest_offset
18
+ )
19
+ @messages_cache = []
20
+ end
21
+
22
+ def call
23
+ @messages_cache += simulate_blocking_io_because_poseidon_is_not_my_application if @messages_cache.empty?
24
+ message = @messages_cache.shift
25
+ @configuration.event_serializer.load(message.value)
26
+ end
27
+
28
+ def simulate_blocking_io_because_poseidon_is_not_my_application
29
+ loop do
30
+ messages = @consumer.fetch(:max_wait => 10_000, :min_bytes => 1)
31
+ break(messages) if messages.any?
32
+ end
33
+ end
34
+
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,5 @@
1
+ module Citrus
2
+ module EventBus
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,17 @@
1
+ require 'test/unit'
2
+ require 'citrus/event_bus'
3
+
4
+ module Citrus
5
+ module EventBus
6
+ class IntegrationTest < Test::Unit::TestCase
7
+
8
+ def test_event_flow_on_defaults
9
+ event = Event.for_type(:dummy)
10
+ Thread.new { Publisher.new.(event) }
11
+ received_event = Subscriber.new.()
12
+ assert_equal event, received_event
13
+ end
14
+
15
+ end
16
+ end
17
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: citrus-event-bus
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Paweł Pacana
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: poseidon
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 0.0.4
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 0.0.4
55
+ description:
56
+ email:
57
+ - pawel.pacana@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - citrus-event-bus.gemspec
68
+ - lib/citrus/event_bus.rb
69
+ - lib/citrus/event_bus/configuration.rb
70
+ - lib/citrus/event_bus/event.rb
71
+ - lib/citrus/event_bus/publisher.rb
72
+ - lib/citrus/event_bus/serializer.rb
73
+ - lib/citrus/event_bus/subscriber.rb
74
+ - lib/citrus/event_bus/version.rb
75
+ - test/integration_test.rb
76
+ homepage: ''
77
+ licenses:
78
+ - MIT
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.2.2
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: Event bus adapter for Citrus.
100
+ test_files:
101
+ - test/integration_test.rb