Skip to content

Commit 2b246c6

Browse files
author
vadim.kar
committed
use kwargs in publish and message
1 parent 762db51 commit 2b246c6

File tree

8 files changed

+47
-22
lines changed

8 files changed

+47
-22
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Changelog
22
All notable changes to this project will be documented in this file.
33

4-
## [1.6.4] - 2025-08-19
4+
## [1.7.0] - 2025-08-19
55
### Added
66
- Ability to specify a custom job class for publishing via `publishing_job_class_callable` config.
77
- Ability to specify a default queue for publishing jobs via `default_publishing_job_queue` config.

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ GIT
88
PATH
99
remote: .
1010
specs:
11-
rabbit_messaging (1.6.4)
11+
rabbit_messaging (1.7.0)
1212
bunny (~> 2.0)
1313
kicks
1414

lib/rabbit.rb

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,27 @@ def configure
169169
config.validate!
170170
end
171171

172-
def publish(message_options, custom_queue_name: nil)
173-
# Extract custom_queue_name from message_options for backward compatibility
174-
custom_queue_name ||= message_options[:custom_queue_name]
175-
176-
message = Publishing::Message.new(message_options)
172+
def publish(
173+
routing_key: nil,
174+
event: nil,
175+
data: {},
176+
exchange_name: [],
177+
confirm_select: true,
178+
realtime: false,
179+
headers: {},
180+
message_id: nil,
181+
custom_queue_name: nil
182+
)
183+
message = Publishing::Message.new(
184+
routing_key: routing_key,
185+
event: event,
186+
data: data,
187+
exchange_name: exchange_name,
188+
confirm_select: confirm_select,
189+
realtime: realtime,
190+
headers: headers,
191+
message_id: message_id,
192+
)
177193
publish_job_callable = config.publishing_job_class_callable || Publishing::Job
178194
queue_name = custom_queue_name || default_queue_name
179195

lib/rabbit/publishing/job.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
module Rabbit::Publishing
66
class Job < ActiveJob::Base
77
def perform(message)
8-
Rabbit::Publishing.publish(Message.new(message))
8+
Rabbit::Publishing.publish(Message.new(**message))
99
end
1010
end
1111
end

lib/rabbit/publishing/message.rb

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,24 @@ class Message
99
alias_method :confirm_select?, :confirm_select
1010
alias_method :realtime?, :realtime
1111

12-
def initialize(attributes = {})
13-
self.routing_key = attributes[:routing_key]
14-
self.event = attributes[:event]&.to_s
15-
self.data = attributes.fetch(:data, {})
16-
self.exchange_name = Array(attributes.fetch(:exchange_name, []))
17-
self.confirm_select = attributes.fetch(:confirm_select, true)
18-
self.realtime = attributes.fetch(:realtime, false)
19-
self.headers = attributes.fetch(:headers, {})
20-
self.message_id = attributes[:message_id]
12+
def initialize(
13+
routing_key: nil,
14+
event: nil,
15+
data: {},
16+
exchange_name: [],
17+
confirm_select: true,
18+
realtime: false,
19+
headers: {},
20+
message_id: nil
21+
)
22+
self.routing_key = routing_key
23+
self.event = event&.to_s
24+
self.data = data
25+
self.exchange_name = Array(exchange_name)
26+
self.confirm_select = confirm_select
27+
self.realtime = realtime
28+
self.headers = headers
29+
self.message_id = message_id
2130
end
2231

2332
def to_hash

lib/rabbit/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module Rabbit
4-
VERSION = "1.6.4"
4+
VERSION = "1.7.0"
55
end

spec/units/rabbit/publishing/message_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
describe Rabbit::Publishing::Message do
44
describe "basic_publish_args" do
5-
subject(:message) { described_class.new(attributes) }
5+
subject(:message) { described_class.new(**attributes) }
66

77
context "rounting key not specified" do
88
let(:attributes) { Hash[event: :ping] }

spec/units/rabbit_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
test_group_id.test_project_id.some_exchange / some_queue / {"foo":"bar"} / some_event / \
8181
confirm: ...world"}
8282
MSG
83-
described_class.publish(message_options, **additional_params)
83+
described_class.publish(**message_options, **additional_params)
8484
end
8585

8686
after do
@@ -134,13 +134,13 @@
134134
confirm: {"hello":"world"}
135135
MSG
136136

137-
expect { described_class.publish(message_options) }.not_to raise_error
137+
expect { described_class.publish(**message_options) }.not_to raise_error
138138
end
139139

140140
it "raises the last exception after max retries" do
141141
allow(channel).to receive(:basic_publish).and_raise(Bunny::ConnectionClosedError.new(""))
142142

143-
expect { described_class.publish(message_options) }
143+
expect { described_class.publish(**message_options) }
144144
.to raise_error(Bunny::ConnectionClosedError)
145145
end
146146
end

0 commit comments

Comments
 (0)