bps-kafka 0.0.3 → 0.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
2
  SHA256:
3
- metadata.gz: 68826145fba6a103c652c008207089c913a18999a41acdcc35082d526a8979b1
4
- data.tar.gz: f14e9f89c8ff5d968b744483e381abb41f6b1265d6d696688a31439f0fdbf591
3
+ metadata.gz: dc71e376289d57e6341560ddefd86c3c44d77b5fe3963ca658bfa44c4124d31f
4
+ data.tar.gz: 9ac605f652d7ec7a4a2f3f6460e476d6639b705021ad064240ea8cc2ac03f51b
5
5
  SHA512:
6
- metadata.gz: b9b4d9ae93a101c874f0cd2f0a5f07b7b577e6526de8a3ccc978cd346344d768e354202aa6b4652589334e0a1c56d5a556c1053929b2e3c1a1152d9556911571
7
- data.tar.gz: 52d62b30b81d2f18a1098a47eff1314406aef6b371293ca0ef9ae10b17c8fa1a53043e5c21d7490b10717255fbb9408fa1df67879eab36e947cf06fe27782500
6
+ metadata.gz: f7d2cc289e5d7f82ce2dba5538b7f071f5259ee7fd9f9077cf0a2334d157a2bcf00d4b787a86fc733142e1ff17ce7b7f2bfcc1f4db761825de6492d53825eb51
7
+ data.tar.gz: dfdb6747738ed57a359e71cd4455203c3da130d8ec31516ddfaf6b4e93f08e1f1f51d74d304ca8d3dfc99a83906c9acb3be540acb83aacf81a0b2e1eefda5561
@@ -6,13 +6,11 @@ require 'bps/publisher/kafka_async'
6
6
  module BPS
7
7
  module Publisher
8
8
  register('kafka+sync') do |url, **opts|
9
- addrs = CGI.unescape(url.host).split(',')
10
- Kafka.new(addrs, **Kafka.coercer.coerce(opts))
9
+ Kafka.new(url, **Kafka.coercer.coerce(opts))
11
10
  end
12
11
 
13
12
  register('kafka') do |url, **opts|
14
- addrs = CGI.unescape(url.host).split(',')
15
- KafkaAsync.new(addrs, **Kafka.coercer.coerce(opts))
13
+ KafkaAsync.new(url, **Kafka.coercer.coerce(opts))
16
14
  end
17
15
  end
18
16
  end
@@ -76,14 +76,15 @@ module BPS
76
76
  @coercer ||= BPS::Coercer.new(CLIENT_OPTS.merge(PRODUCER_OPTS)).freeze
77
77
  end
78
78
 
79
- # @param [Array<String>] brokers the seed broker addresses.
79
+ # @param [Array<String>,URI] brokers the seed broker addresses.
80
80
  # @param [Hash] opts the options.
81
81
  # @see https://www.rubydoc.info/gems/ruby-kafka/Kafka/Client#initialize-instance_method
82
82
  def initialize(broker_addrs, **opts)
83
83
  super()
84
84
 
85
- @topics = {}
86
- @client = ::Kafka.new(broker_addrs, **opts.slice(*CLIENT_OPTS.keys))
85
+ broker_addrs = parse_url(broker_addrs) if broker_addrs.is_a?(URI)
86
+ @topics = {}
87
+ @client = ::Kafka.new(broker_addrs, **opts.slice(*CLIENT_OPTS.keys))
87
88
  @producer = init_producer(**opts.slice(*PRODUCER_OPTS.keys))
88
89
  end
89
90
 
@@ -98,6 +99,14 @@ module BPS
98
99
 
99
100
  private
100
101
 
102
+ def parse_url(url)
103
+ port = url.port&.to_s || '9092'
104
+ CGI.unescape(url.host).split(',').map do |addr|
105
+ addr << ':' << port unless addr.match(/:\d+$/)
106
+ addr
107
+ end
108
+ end
109
+
101
110
  def init_producer(**opts)
102
111
  @producer = @client.producer(**opts)
103
112
  end
@@ -27,12 +27,44 @@ helper = proc do
27
27
  end
28
28
  end
29
29
 
30
- RSpec.describe 'Kafka', if: run_spec do
31
- context BPS::Publisher::Kafka do
32
- it_behaves_like 'publisher', url: "kafka+sync://#{kafka_addrs.join(',')}/", &helper
30
+ RSpec.describe 'Kafka' do
31
+ context 'resolve addrs' do
32
+ let(:client) { double('Kafka', producer: nil) }
33
+ before { allow(::Kafka).to receive(:new).and_return(client) }
34
+
35
+ it 'should resolve simple URLs' do
36
+ if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.7')
37
+ expect(::Kafka).to receive(:new).with(['test.host:9092'], {}).and_return(client)
38
+ else
39
+ expect(::Kafka).to receive(:new).with(['test.host:9092']).and_return(client)
40
+ end
41
+ BPS::Publisher.resolve(URI.parse('kafka+sync://test.host:9092'))
42
+ end
43
+
44
+ it 'should resolve URLs with multiple hosts' do
45
+ if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.7')
46
+ expect(::Kafka).to receive(:new).with(['foo.host:9092', 'bar.host:9092'], {}).and_return(client)
47
+ else
48
+ expect(::Kafka).to receive(:new).with(['foo.host:9092', 'bar.host:9092']).and_return(client)
49
+ end
50
+ BPS::Publisher.resolve(URI.parse('kafka+sync://foo.host,bar.host:9092'))
51
+ end
52
+
53
+ it 'should resolve URLs with multiple hosts/ports' do
54
+ if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.7')
55
+ expect(::Kafka).to receive(:new).with(['foo.host:9093', 'bar.host:9092'], {}).and_return(client)
56
+ else
57
+ expect(::Kafka).to receive(:new).with(['foo.host:9093', 'bar.host:9092']).and_return(client)
58
+ end
59
+ BPS::Publisher.resolve(URI.parse('kafka+sync://foo.host%3A9093,bar.host'))
60
+ end
61
+ end
62
+
63
+ context BPS::Publisher::Kafka, if: run_spec do
64
+ it_behaves_like 'publisher', url: "kafka+sync://#{CGI.escape(kafka_addrs.join(','))}/", &helper
33
65
  end
34
66
 
35
- context BPS::Publisher::KafkaAsync do
36
- it_behaves_like 'publisher', url: "kafka://#{kafka_addrs.join(',')}/", &helper
67
+ context BPS::Publisher::KafkaAsync, if: run_spec do
68
+ it_behaves_like 'publisher', url: "kafka://#{CGI.escape(kafka_addrs.join(','))}/", &helper
37
69
  end
38
70
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bps-kafka
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Black Square Media
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-08 00:00:00.000000000 Z
11
+ date: 2020-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bps
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 0.0.3
19
+ version: 0.1.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 0.0.3
26
+ version: 0.1.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: ruby-kafka
29
29
  requirement: !ruby/object:Gem::Requirement