deimos-ruby 1.8.1.pre.beta9 → 1.8.2.pre.beta1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 18ef8f674c86fcdba3fc7a2556162b1104084fd38c6ee8046ed773e9352633bd
4
- data.tar.gz: 60f5a05874a0cd2cd6abceb7cfc5af1a01068a2a3cc4cc4e65dd59d42783468a
3
+ metadata.gz: ce4c0e112957a2a8983372b2eda22b139e1eadac18945d4cbd9945c31e181b9d
4
+ data.tar.gz: 43df5dcfd68305868cc2ac19f33c070bfc2d6b3c3679fc85116d81939e3a5ce2
5
5
  SHA512:
6
- metadata.gz: '0963acc646195fac41c3aaa71c67bbdc253bf26fa650c6132096a7912b665bb1956e3511f41db08309fbc9db35a6717c7a48f17a340039732bced4c5b6bd8b7a'
7
- data.tar.gz: 0c642071d49e099d8516ed05c5856b1bba00a432c30567b3c79491654b0e1b1cc43e51a4c20f9765e0f2cbcd4af6550fbaa7620b1693d9ed342202609e496914
6
+ metadata.gz: ffdbf97e2ad36eafd643cf958b44990a16315da4d346e8b5aaa8dacbdf8d0caecfd493063305b888e240091ab26f5a39bf044b8c3919419f2a6c35c460d774f8
7
+ data.tar.gz: cb200f4a2d47519f2cb3f0f577a0295690842eb7a8367867749a3cc75236d7205eddb413cc22c28efba7b44b6c8d8a4a98744cd4d3adacedfbc2d64d690397d7
@@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## UNRELEASED
9
9
 
10
+ ## 1.8.2-beta1 - 2020-09-09
11
+
12
+ ### Features :star:
13
+
14
+ - Added the ability to specify the topic for `publish`
15
+ and `publish_list` in a producer
16
+
10
17
  ## 1.8.1-beta9 - 2020-08-27
11
18
 
12
19
  ### Fixes :wrench:
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- deimos-ruby (1.8.1.pre.beta8)
4
+ deimos-ruby (1.8.2.pre.beta1)
5
5
  avro_turf (~> 0.11)
6
6
  phobos (~> 1.9)
7
7
  ruby-kafka (~> 0.7)
data/README.md CHANGED
@@ -108,6 +108,7 @@ class MyProducer < Deimos::Producer
108
108
  'some-key2' => an_object.bar
109
109
  }
110
110
  # You can also publish an array with self.publish_list(payloads)
111
+ # You may specify the topic here with self.publish(payload, topic: 'my-topic')
111
112
  self.publish(payload)
112
113
  end
113
114
 
@@ -87,8 +87,9 @@ module Deimos
87
87
 
88
88
  # Publish the payload to the topic.
89
89
  # @param payload [Hash] with an optional payload_key hash key.
90
- def publish(payload)
91
- publish_list([payload])
90
+ # @param topic [String] if specifying the topic
91
+ def publish(payload, topic: self.topic)
92
+ publish_list([payload], topic: topic)
92
93
  end
93
94
 
94
95
  # Publish a list of messages.
@@ -97,7 +98,8 @@ module Deimos
97
98
  # whether to publish synchronously.
98
99
  # @param force_send [Boolean] if true, ignore the configured backend
99
100
  # and send immediately to Kafka.
100
- def publish_list(payloads, sync: nil, force_send: false)
101
+ # @param topic [String] if specifying the topic
102
+ def publish_list(payloads, sync: nil, force_send: false, topic: self.topic)
101
103
  return if Deimos.config.kafka.seed_brokers.blank? ||
102
104
  Deimos.config.producers.disabled ||
103
105
  Deimos.producers_disabled?(self)
@@ -110,7 +112,7 @@ module Deimos
110
112
  payloads: payloads
111
113
  ) do
112
114
  messages = Array(payloads).map { |p| Deimos::Message.new(p, self) }
113
- messages.each(&method(:_process_message))
115
+ messages.each { |m| _process_message(m, topic) }
114
116
  messages.in_groups_of(MAX_BATCH_SIZE, false) do |batch|
115
117
  self.produce_batch(backend_class, batch)
116
118
  end
@@ -163,7 +165,8 @@ module Deimos
163
165
  private
164
166
 
165
167
  # @param message [Message]
166
- def _process_message(message)
168
+ # @param topic [String]
169
+ def _process_message(message, topic)
167
170
  # this violates the Law of Demeter but it has to happen in a very
168
171
  # specific order and requires a bunch of methods on the producer
169
172
  # to work correctly.
@@ -175,7 +178,7 @@ module Deimos
175
178
  message.payload = nil if message.payload.blank?
176
179
  message.coerce_fields(encoder)
177
180
  message.encoded_key = _encode_key(message.key)
178
- message.topic = self.topic
181
+ message.topic = topic
179
182
  message.encoded_payload = if message.payload.nil?
180
183
  nil
181
184
  else
@@ -19,7 +19,7 @@ module Deimos
19
19
  offset = last_offset - num_messages
20
20
  if offset.positive?
21
21
  Deimos.config.logger.info("Seeking to #{offset}")
22
- @consumer.seek(topic, 0, offset)
22
+ @consumer.seek(topic, 1, offset)
23
23
  end
24
24
  rescue StandardError => e
25
25
  "Could not seek to offset: #{e.message}"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Deimos
4
- VERSION = '1.8.1-beta9'
4
+ VERSION = '1.8.2-beta1'
5
5
  end
@@ -102,6 +102,33 @@ module ProducerTest
102
102
  expect('my-topic').not_to have_sent('test_id' => 'foo2', 'some_int' => 123)
103
103
  end
104
104
 
105
+ it 'should allow setting the topic from publish_list' do
106
+ expect(described_class).to receive(:produce_batch).once.with(
107
+ Deimos::Backends::Test,
108
+ [
109
+ Deimos::Message.new({ 'test_id' => 'foo', 'some_int' => 123 },
110
+ MyProducer,
111
+ topic: 'a-new-topic',
112
+ partition_key: 'foo',
113
+ key: 'foo'),
114
+ Deimos::Message.new({ 'test_id' => 'bar', 'some_int' => 124 },
115
+ MyProducer,
116
+ topic: 'a-new-topic',
117
+ partition_key: 'bar',
118
+ key: 'bar')
119
+ ]
120
+ ).and_call_original
121
+
122
+ MyProducer.publish_list(
123
+ [{ 'test_id' => 'foo', 'some_int' => 123 },
124
+ { 'test_id' => 'bar', 'some_int' => 124 }],
125
+ topic: 'a-new-topic'
126
+ )
127
+ expect('a-new-topic').to have_sent('test_id' => 'foo', 'some_int' => 123)
128
+ expect('my-topic').not_to have_sent('test_id' => 'foo', 'some_int' => 123)
129
+ expect('my-topic').not_to have_sent('test_id' => 'foo2', 'some_int' => 123)
130
+ end
131
+
105
132
  it 'should add a message ID' do
106
133
  payload = { 'test_id' => 'foo',
107
134
  'some_int' => 123,
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deimos-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.1.pre.beta9
4
+ version: 1.8.2.pre.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Orner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-27 00:00:00.000000000 Z
11
+ date: 2020-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: avro_turf