megaphone-client 1.1.0 → 1.1.1

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
- SHA1:
3
- metadata.gz: 15b75d53f469b5b1eb81174951801eb6b131957d
4
- data.tar.gz: 72d170f64c4a6eb00f009411e21700ce238eee82
2
+ SHA256:
3
+ metadata.gz: 2d48043a0df8afb5fba26820a9a09e32c57c6c2658795ae38869c979062b5d67
4
+ data.tar.gz: ebababb0d2f28825df5587fba9a792864360836fe40a1a0843be3837acbd779d
5
5
  SHA512:
6
- metadata.gz: 5510da93aa27aaa55aa0bfb6b4ea68cb11678f9c7424d89cd309cad42e87e220dc62b4a0bd2ba7d5925fe233a34f8fe07c8c2cfd427c8e97645b4f9508fdffcd
7
- data.tar.gz: 2e6f71ac8caa1f13ab0bbf81351d6baf4056322d4e5cd4ffb85e8e3ca86a56d5ab8ba9a901eecc27a22a38d525d2b94bc3d7d219f9308285ae370d81059d7eba
6
+ metadata.gz: f9e5512231b6bcb86b8180851fe0091e3fcc9c03caf87c445121cf7cef2f05abdef37582d97bdc184c9c1cf8c14dfb42114a59859e3fc7296c27762592d20505
7
+ data.tar.gz: 181405d9073d0616d7a2a91db1f852d9c852f63801877f12575f7a9eea5a6f6b34b564cb60d918b2d4bc128064e9d15362d95a5b2e15bab4ea0c4f6d4378f1eb
@@ -5,6 +5,19 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and
6
6
  this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [1.1.1] - 2018-02-09
9
+
10
+ ### Added
11
+
12
+ * A [code of conduct][coc] and [contributing guidelines][contributing].
13
+
14
+ ### Fixed
15
+
16
+ * Validation of events to ensure that Kinesis will accept them.
17
+
18
+ [coc]: ./CODE_OF_CONDUCT.md
19
+ [contributing]: ./CONTRIBUTING.md
20
+
8
21
  ## [1.1.0] - 2018-01-30
9
22
 
10
23
  ### Added
@@ -62,6 +75,7 @@ this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html
62
75
 
63
76
  * Initial implementation of the `Megaphone::Client.publish!` method
64
77
 
78
+ [1.1.1]: https://github.com/redbubble/megaphone-client-ruby/compare/v1.1.0...v1.1.1
65
79
  [1.1.0]: https://github.com/redbubble/megaphone-client-ruby/compare/v1.0.1...v1.1.0
66
80
  [1.0.1]: https://github.com/redbubble/megaphone-client-ruby/compare/v1.0.0...v1.0.1
67
81
  [1.0.0]: https://github.com/redbubble/megaphone-client-ruby/compare/v0.3.0...v1.0.0
data/README.md CHANGED
@@ -1,10 +1,28 @@
1
1
  # Megaphone::Client
2
2
 
3
- [![Build Status](https://badge.buildkite.com/9f4fdb370f5f295ee6bf3d68937b1be2d7cf9bf65b2c7b4213.svg?branch=master)](https://buildkite.com/redbubble/megaphone-client-ruby)
3
+ [![Build Status](https://travis-ci.org/redbubble/megaphone-client-ruby.svg?branch=master)](https://travis-ci.org/redbubble/megaphone-client-ruby)
4
4
  [![Gem Version](https://badge.fury.io/rb/megaphone-client.svg)](https://badge.fury.io/rb/megaphone-client)
5
5
  ![Megaphone](https://img.shields.io/badge/Megaphone-2.0.0-blue.svg)
6
+ ![This is the reference implementation fro Megaphone clients.](https://img.shields.io/badge/megaphone--client-reference%20implementation-blue.svg)
6
7
 
7
- Send events to [Megaphone](https://github.com/redbubble/Megaphone).
8
+ Send events to [Megaphone (private)](https://github.com/redbubble/Megaphone).
9
+
10
+ > **DISCLAIMER**: This is part of a currently private event broadcasting system called Megaphone. Please be aware that some links may lead to private repositories. Questions are welcome, though, and we're happy to help if you find a use for this gem, or get inspired by it!
11
+ >
12
+ > More of Megaphone could become public in the future, but there is currently no clear roadmap for it. -- [GB](https://github.com/gonzalo-bulnes)
13
+
14
+ ## Table of contents
15
+
16
+ 1. [**Getting started**](#getting-started)
17
+ 1. [**Usage**](#usage)
18
+ 1. [Publishing events](#publishing-events)
19
+ 1. [**Error handling**](#error-handling)
20
+ 1. [Exceptions the client will raise](#exceptions-the-client-will-raise)
21
+ 1. [Internal buffering upon error](#internal-buffering-upon-error)
22
+ 1. [Buffer overflow callback handler](#buffer-overflow-callback-handler)
23
+ 1. [Handling time-sensitive events and errors](#handling-time-sensitive-events-and-errors)
24
+ 1. [**Development**](#development)
25
+ 1. [Testing](#testing)
8
26
 
9
27
  ## Getting Started
10
28
 
@@ -61,17 +79,23 @@ client.publish!(topic, subtopic, schema, partition_key, payload)
61
79
 
62
80
  ### Exceptions the client will raise
63
81
 
64
- `publish!` can raise two exceptions if the underlying Fluentd
65
- client library throws an error.
82
+ #### `MegaphoneInvalidEventError`
83
+
84
+ Raised when the message is invalid by Kinesis's standards.
85
+
86
+ #### `MegaphoneMessageDelayWarning`
66
87
 
67
- The most common is `MegaphoneMessageDelayWarning` which indicates
68
- a transient failure occurred, but the message will probably be resent
69
- later. See section on _[Internal buffering](#internal-buffering-upon-error)_ below for more details.
88
+ This indicates a transient failure occurred, but the message will
89
+ probably be re-sent later. See the section on
90
+ _[Internal buffering](#internal-buffering-upon-error)_ below for more
91
+ details.
70
92
 
71
- The second exception is `MegaphoneUnavailableError`, which is thrown
72
- for all other errors. Note that these _may or may not_ also buffer
73
- the message for later transmission. Unfortunately the underlying
74
- client library does not make the distinction.
93
+ #### `MegaphoneUnavailableError`
94
+
95
+ This is raised for all other errors. Note that
96
+ these _may or may not_ also buffer the message for later
97
+ transmission. Unfortunately the underlying client library does not
98
+ make the distinction.
75
99
 
76
100
  ### Internal buffering upon error
77
101
 
@@ -149,6 +173,13 @@ Unfortunately there is no means to do this with the underlying Ruby client
149
173
  for Fluentd. It would require patches to the upstream code to expose a flush
150
174
  method.
151
175
 
176
+ ## Contributing
177
+
178
+ Want to contribute? Amazing! Our [contributing guidelines][contributing], and [code of conduct][coc] are here to get you started and make you feel welcome!
179
+
180
+ [coc]: ./CODE_OF_CONDUCT.md
181
+ [contributing]: ./CONTRIBUTING.md
182
+
152
183
  ## Credits
153
184
 
154
185
  [![](doc/redbubble.png)][redbubble]
@@ -22,11 +22,12 @@ module Megaphone
22
22
 
23
23
  def publish!(topic, subtopic, schema, partition_key, payload)
24
24
  event = Event.new(topic, subtopic, origin, schema, partition_key, payload)
25
+ raise MegaphoneInvalidEventError.new(event.errors.join(', ')) unless event.valid?
25
26
  unless logger.post(topic, event.to_hash)
26
27
  if transient_error?(logger.last_error)
27
- raise MegaphoneMessageDelayWarning.new(logger.last_error.message, event)
28
+ raise MegaphoneMessageDelayWarning.new(logger.last_error.message, event.stream_id)
28
29
  else
29
- raise MegaphoneUnavailableError.new(logger.last_error.message, event)
30
+ raise MegaphoneUnavailableError.new(logger.last_error.message, event.stream_id)
30
31
  end
31
32
  end
32
33
  end
@@ -2,27 +2,23 @@ module Megaphone
2
2
  class Client
3
3
  class MegaphoneUnavailableError < StandardError
4
4
 
5
- def initialize(msg, event)
6
- super(msg)
7
- @msg = msg
8
- @event = event
9
- end
10
-
11
- def to_s
12
- "#{@msg} - An event could not be immediately published, but may be retried: #{@event.stream_id}"
5
+ def initialize(msg, stream_id)
6
+ super("#{msg} - An event could not be immediately published, but may be retried: #{stream_id}")
13
7
  end
14
8
  end
15
9
 
16
10
  class MegaphoneMessageDelayWarning < StandardError
17
11
 
18
- def initialize(msg, event)
19
- super(msg)
20
- @msg = msg
21
- @event = event
12
+ def initialize(msg, stream_id)
13
+ super("#{msg} - Event delayed and will be reattempted: #{stream_id}")
22
14
  end
15
+ end
16
+
17
+ class MegaphoneInvalidEventError < StandardError
23
18
 
24
- def to_s
25
- "#{@msg} - Event delayed and will be reattempted: #{@event.stream_id}"
19
+ def initialize(msg)
20
+ super("Invalid Megaphone event was not sent: #{msg}")
21
+ @msg = msg
26
22
  end
27
23
  end
28
24
  end
@@ -30,6 +30,26 @@ module Megaphone
30
30
  def to_s
31
31
  JSON.dump(to_hash)
32
32
  end
33
+
34
+ def errors
35
+ errors = []
36
+ errors << 'partition_key must not be empty' if missing?(@partition_key)
37
+ errors << 'topic must not be empty' if missing?(@topic)
38
+ errors << 'subtopic must not be empty' if missing?(@subtopic)
39
+ errors << 'payload must not be empty' if missing?(@payload)
40
+ errors << 'origin must not be empty' if missing?(@origin)
41
+ errors
42
+ end
43
+
44
+ def valid?
45
+ errors.empty?
46
+ end
47
+
48
+ private
49
+
50
+ def missing?(field)
51
+ not (field && field.to_s.length > 0)
52
+ end
33
53
  end
34
54
  end
35
55
  end
@@ -1,5 +1,5 @@
1
1
  module Megaphone
2
2
  class Client
3
- VERSION = "1.1.0"
3
+ VERSION = "1.1.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: megaphone-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Redbubble
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2018-01-30 00:00:00.000000000 Z
13
+ date: 2018-02-09 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: fluent-logger
@@ -94,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
94
  version: '0'
95
95
  requirements: []
96
96
  rubyforge_project:
97
- rubygems_version: 2.4.5.1
97
+ rubygems_version: 2.7.5
98
98
  signing_key:
99
99
  specification_version: 4
100
100
  summary: Send events to Megaphone.