megaphone-client 0.3.0 → 1.0.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 +4 -4
- data/CHANGELOG.md +6 -2
- data/README.md +33 -11
- data/lib/megaphone/client.rb +3 -2
- data/lib/megaphone/client/logger.rb +4 -6
- data/lib/megaphone/client/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea3788fe007c5771e476cbc5adfde59a540f4f43
|
4
|
+
data.tar.gz: c3e00fbf0225d7c439684c84da295af81f5ab51e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1ed95ea4cee223e4f658badb1f29e99f7ae82610359fba6489d5cdbe656cd2f52b1c82a019dd1f5d60f8bf08b088b3add9c38f9c36fef52c876f7a2d40e80e65
|
7
|
+
data.tar.gz: a2aaa416a658986540e7e1d6062c971101287c6913e91840bb0a8e735bc97779ed9094486cab054b7e3440d40035a88709ddb54762660a82ca805efceec7d770
|
data/CHANGELOG.md
CHANGED
@@ -3,10 +3,13 @@
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
|
5
5
|
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and
|
6
|
-
this project
|
6
|
+
this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
7
7
|
|
8
|
-
|
8
|
+
## [1.0.0] - 2017-08-18
|
9
9
|
|
10
|
+
### Changed
|
11
|
+
|
12
|
+
- The `Megaphone::Client` API is now stable!
|
10
13
|
|
11
14
|
## [0.3.0] - 2017-08-17
|
12
15
|
|
@@ -38,5 +41,6 @@ This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html
|
|
38
41
|
|
39
42
|
- Initial implementation of the `Megaphone::Client.publish!` method
|
40
43
|
|
44
|
+
[1.0.0]: https://github.com/redbubble/megaphone-client-ruby/compare/v0.1.2...v1.0.0
|
41
45
|
[0.1.2]: https://github.com/redbubble/megaphone-client-ruby/compare/v0.1.1...v0.1.2
|
42
46
|
[0.1.1]: https://github.com/redbubble/megaphone-client-ruby/compare/v0.1.0...v0.1.1
|
data/README.md
CHANGED
@@ -2,6 +2,7 @@ Megaphone::Client
|
|
2
2
|
=================
|
3
3
|
|
4
4
|
[](https://buildkite.com/redbubble/megaphone-client-ruby)
|
5
|
+
[](https://badge.fury.io/rb/megaphone-client)
|
5
6
|
|
6
7
|
Send events to Megaphone.
|
7
8
|
|
@@ -13,24 +14,45 @@ Add the gem to your `Gemfile`:
|
|
13
14
|
```ruby
|
14
15
|
# Gemfile
|
15
16
|
|
16
|
-
gem 'megaphone-client', '~>
|
17
|
+
gem 'megaphone-client', '~> 1.0' # see semver.org
|
17
18
|
```
|
18
19
|
|
19
20
|
Usage
|
20
21
|
-----
|
21
|
-
The client will append events to local files unless the fluentd host and port values are passed as arguments to the client's constructor or the `MEGAPHONE_FLUENT_HOST` and `MEGAPHONE_FLUENT_PORT` environment variables are set.
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
In order to be as unobstrusive as possible, this client will append events to local files (e.g. `./work-updates.stream`) unless:
|
24
|
+
|
25
|
+
- the `MEGAPHONE_FLUENT_HOST` and `MEGAPHONE_FLUENT_PORT` environment variables are set.
|
26
|
+
- **or** the Fluentd host and port values are passed as arguments to the client's constructor
|
27
|
+
|
28
|
+
That behaviour ensures that unless you want to send events to the Megaphone [streams][stream], you do not need to [start Fluentd][megaphone-fluentd] at all.
|
29
|
+
|
30
|
+
[stream]: https://github.com/redbubble/com/megaphone#stream
|
31
|
+
[megaphone-fluentd]: https://github.com/redbubble/megaphone-fluentd-container
|
26
32
|
|
27
|
-
|
28
|
-
subtopic = :product_pages
|
29
|
-
schema = 'http://www.github.com/redbuble/megaphone-event-type-registry/topics/cats'
|
30
|
-
partition_key = '1357924680'
|
31
|
-
payload = { url: 'https://www.redbubble.com/people/wytrab8/works/26039653-toadally-rad?grid_pos=1&p=mens-graphic-t-shirt&rbs=29c497ad-a976-42b8-aa40-0e218903c558&ref=shop_grid&style=mens' }
|
33
|
+
### Publishing events
|
32
34
|
|
33
|
-
|
35
|
+
1. Start Fluentd, the easiest way to do so is using a [`redbubble/megaphone-fluentd`][megaphone-fluentd] container
|
36
|
+
|
37
|
+
1. Create your event and publish it:
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
# Configure a Megaphone client for your awesome service
|
41
|
+
client = Megaphone::Client.new({
|
42
|
+
origin: 'my-awesome-service',
|
43
|
+
host: 'localhost',
|
44
|
+
port: '24224'
|
45
|
+
})
|
46
|
+
|
47
|
+
# Create an event
|
48
|
+
topic = 'work-updates'
|
49
|
+
subtopic = 'work-metadata-updated'
|
50
|
+
schema = 'https://github.com/redbubble/megaphone-event-type-registry/blob/master/streams/work-updates-schema-1.0.0.json'
|
51
|
+
partition_key = '1357924680' # the Work ID in this case
|
52
|
+
payload = { url: 'https://www.redbubble.com/people/wytrab8/works/26039653-toadally-rad' }
|
53
|
+
|
54
|
+
# Publish your event
|
55
|
+
client.publish!(topic, subtopic, schema, partition_key, payload)
|
34
56
|
```
|
35
57
|
|
36
58
|
Credits
|
data/lib/megaphone/client.rb
CHANGED
@@ -10,8 +10,9 @@ module Megaphone
|
|
10
10
|
|
11
11
|
def initialize(config)
|
12
12
|
@origin = config.fetch(:origin)
|
13
|
-
|
14
|
-
|
13
|
+
host = config.fetch(:host, ENV['MEGAPHONE_FLUENT_HOST'])
|
14
|
+
port = config.fetch(:port, ENV['MEGAPHONE_FLUENT_PORT'])
|
15
|
+
@logger = Megaphone::Client::Logger.create(host, port)
|
15
16
|
end
|
16
17
|
|
17
18
|
def publish!(topic, subtopic, schema, partition_key, payload)
|
@@ -5,13 +5,11 @@ module Megaphone
|
|
5
5
|
class Client
|
6
6
|
class Logger
|
7
7
|
def self.create(host = nil, port = nil)
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
!fluentd_host.nil? && !fluentd_host.empty?
|
12
|
-
return Megaphone::Client::FluentLogger.new(fluentd_host, fluentd_port)
|
8
|
+
if !port.nil? && !port.empty? &&
|
9
|
+
!host.nil? && !host.empty?
|
10
|
+
return FluentLogger.new(host, port)
|
13
11
|
end
|
14
|
-
|
12
|
+
FileLogger.new
|
15
13
|
end
|
16
14
|
end
|
17
15
|
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: 0.
|
4
|
+
version: 1.0.0
|
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: 2017-08-
|
13
|
+
date: 2017-08-18 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.
|
97
|
+
rubygems_version: 2.6.12
|
98
98
|
signing_key:
|
99
99
|
specification_version: 4
|
100
100
|
summary: Send events to Megaphone.
|