Skip to content

Commit

Permalink
Assorted fixes for JRuby
Browse files Browse the repository at this point in the history
 * amq-protocol is not used on JRuby
 * All connections must be closed on JRuby since Hutch/MarchHare
   do not instruct RabbitMQ Java client to use daemon threads.
   Not doing so will result in hanging test suites since the JVM
   won't terminate with live non-daemon threads.

References #302, #305.
  • Loading branch information
michaelklishin committed Jan 17, 2018
1 parent ddf310a commit 61f3357
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
20 changes: 19 additions & 1 deletion lib/hutch/broker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,24 @@ class Broker

attr_accessor :connection, :channel, :exchange, :api_client


DEFAULT_AMQP_PORT =
case RUBY_ENGINE
when "jruby" then
com.rabbitmq.client.ConnectionFactory::DEFAULT_AMQP_PORT
when "ruby" then
AMQ::Protocol::DEFAULT_PORT
end

DEFAULT_AMQPS_PORT =
case RUBY_ENGINE
when "jruby" then
com.rabbitmq.client.ConnectionFactory::DEFAULT_AMQP_OVER_SSL_PORT
when "ruby" then
AMQ::Protocol::TLS_PORT
end


# @param config [nil,Hash] Configuration override
def initialize(config = nil)
@config = config || Hutch::Config
Expand Down Expand Up @@ -301,7 +319,7 @@ def parse_uri
end

def default_mq_port
@config[:mq_tls] ? AMQ::Protocol::TLS_PORT : AMQ::Protocol::DEFAULT_PORT
@config[:mq_tls] ? DEFAULT_AMQPS_PORT : DEFAULT_AMQP_PORT
end

def sanitized_uri
Expand Down
8 changes: 6 additions & 2 deletions spec/hutch/broker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,19 @@
before { config[:uri] = 'amqp://guest:guest@127.0.0.1:5672/' }

it 'successfully connects' do
expect { broker.open_connection }.not_to raise_error
c = broker.open_connection
expect(c).to be_open
c.close
end
end

context 'which does not specify port and uses the amqp scheme' do
before { config[:uri] = 'amqp://guest:guest@127.0.0.1/' }

it 'successfully connects' do
expect { broker.open_connection }.not_to raise_error
c = broker.open_connection
expect(c).to be_open
c.close
end
end

Expand Down

0 comments on commit 61f3357

Please sign in to comment.