Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions lib/active_publisher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,23 @@ class UnknownMessageClassError < StandardError; end
class ExchangeMismatchError < StandardError; end
class FailedPublisherConfirms < StandardError; end

NETWORK_ERRORS = if ::RUBY_PLATFORM == "java"
[
::MarchHare::NetworkException,
::MarchHare::ConnectionRefused,
::Java::ComRabbitmqClient::AlreadyClosedException,
::Java::JavaIo::IOException
].freeze
else
[
::Bunny::NetworkFailure,
::Bunny::TCPConnectionFailed,
::Bunny::ConnectionTimeout,
::Timeout::Error,
::IOError
].freeze
end

def self.configuration
@configuration ||= ::ActivePublisher::Configuration.new
end
Expand Down Expand Up @@ -81,8 +98,13 @@ def self.publishing_options(route, in_options = {})
end

def self.with_exchange(exchange_name)
connection = ::ActivePublisher::Connection.connection
channel = connection.create_channel
begin
connection = ::ActivePublisher::Connection.connection
channel = connection.create_channel
rescue *NETWORK_ERRORS
::ActivePublisher::Connection.disconnect!
end

begin
channel.confirm_select if configuration.publisher_confirms
exchange = channel.topic(exchange_name)
Expand Down
10 changes: 1 addition & 9 deletions lib/active_publisher/async/in_memory_adapter/consumer_thread.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,6 @@ module InMemoryAdapter
class ConsumerThread
attr_reader :thread, :queue, :sampled_queue_size, :last_tick_at

if ::RUBY_PLATFORM == "java"
NETWORK_ERRORS = [::MarchHare::NetworkException, ::MarchHare::ConnectionRefused,
::Java::ComRabbitmqClient::AlreadyClosedException, ::Java::JavaIo::IOException].freeze
else
NETWORK_ERRORS = [::Bunny::NetworkFailure, ::Bunny::TCPConnectionFailed, ::Bunny::ConnectionTimeout,
::Timeout::Error, ::IOError].freeze
end

if ::RUBY_PLATFORM == "java"
PRECONDITION_ERRORS = [::MarchHare::PreconditionFailed]
else
Expand Down Expand Up @@ -77,7 +69,7 @@ def start_thread
publish_all(@channel, exchange_name, messages)
current_messages -= messages
end
rescue *NETWORK_ERRORS
rescue *ActivePublisher::NETWORK_ERRORS
# Sleep because connection is down
await_network_reconnect
rescue => unknown_error
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/active_publisher/async/in_memory_adapter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
end

context "when network error occurs" do
let(:error) { ActivePublisher::Async::InMemoryAdapter::ConsumerThread::NETWORK_ERRORS.first }
let(:error) { ::ActivePublisher::NETWORK_ERRORS.first }
before { allow(consumer).to receive(:publish_all).and_raise(error) }

it "requeues the message" do
Expand Down