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
63 changes: 0 additions & 63 deletions .circleci/config.yml

This file was deleted.

96 changes: 96 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
name: Ruby Compatibility Matrix

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build_and_test:
name: test-${{ matrix.docker_image }}
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
docker_image:
- "ruby:3.1"
- "ruby:3.4"
- "jruby:9.4"
- "jruby:10.0"

container:
image: ${{ matrix.docker_image }}
env:
JRUBY_OPTS: "-J-Xmx1024m"
RAILS_ENV: test
# Use the service name 'rabbitmq' as the host, not localhost
RABBITMQ_URL: "amqp://demo:demo@rabbitmq:5672"
RABBITMQ_HOST: rabbitmq
RABBITMQ_MANAGEMENT_URL: "http://demo:demo@rabbitmq:15672"

services:
rabbitmq:
image: rabbitmq:3.12-management
env:
RABBITMQ_DEFAULT_USER: demo
RABBITMQ_DEFAULT_PASS: demo
# Note: Health checks here ensure the container is up before steps start
options: >-
--health-cmd "rabbitmq-diagnostics -q check_running"
--health-interval 10s
--health-timeout 5s
--health-retries 5

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install System Dependencies
run: |
if [ "$(id -u)" = "0" ]; then
apt-get update && apt-get install -y build-essential git netcat-openbsd docker-ce-cli
else
sudo apt-get update && sudo apt-get install -y build-essential git netcat-openbsd docker-ce-cli
fi

- name: Cache Ruby Gems
uses: actions/cache@v4
with:
path: vendor/bundle
key: v1-gems-${{ matrix.docker_image }}-${{ hashFiles('Gemfile.lock') }}
restore-keys: |
v1-gems-${{ matrix.docker_image }}-

- name: Install Ruby Dependencies
run: |
gem install bundler
bundle config set --local path 'vendor/bundle'
bundle install --jobs=4 --retry=3

- name: Wait for RabbitMQ
run: |
echo "Waiting for RabbitMQ to start at hostname 'rabbitmq'..."
for i in {1..30}; do
if nc -z rabbitmq 5672; then
echo "RabbitMQ is ready!"
exit 0
fi
echo "Waiting... ($i/30)"
sleep 1
done
echo "RabbitMQ failed to start"
exit 1

- name: Configure RabbitMQ Management user "demo"
run: |
docker exec ${{ job.services.rabbitmq.id }} rabbitmqctl set_user_tags "demo" administrator
docker exec ${{ job.services.rabbitmq.id }} rabbitmqctl set_permissions -p / "demo" ".*" ".*" ".*"

- name: Run Tests
run : |
git config --global --add safe.directory /__w/action_subscriber/action_subscriber
cp ./config/action_subscriber.yml.sample ./config/action_subscriber.yml
echo $(env)
bundle exec rspec
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ Gemfile.lock
.yardoc
_yardoc
doc/

config/active_publisher.yml
config/action_subscriber.yml
14 changes: 8 additions & 6 deletions action_subscriber.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,26 @@ Gem::Specification.new do |spec|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ["lib"]

spec.add_dependency "activesupport", ">= 3.2"
spec.add_dependency "activesupport", ">= 6.0"

if ENV["PLATFORM"] == "java" || ::RUBY_PLATFORM == "java"
spec.platform = "java"
spec.add_dependency "march_hare", "~> 4.4"
else
spec.add_dependency "bunny", ">= 1.5.0"
spec.add_dependency "bunny", ">= 2.24.0"
end
spec.add_dependency "concurrent-ruby"
spec.add_dependency "middleware"
spec.add_dependency "thor"

spec.add_development_dependency "active_publisher", "~> 0.1.5"
spec.add_development_dependency "activerecord", ">= 3.2"
spec.add_development_dependency "bundler", ">= 1.6"
spec.required_ruby_version = '>= 3.1.0'

spec.add_development_dependency "active_publisher", "1.6.0.pre1"
spec.add_development_dependency "activerecord", ">= 6.0"
spec.add_development_dependency "bundler"
spec.add_development_dependency "pry-nav"
spec.add_development_dependency "rabbitmq_http_api_client", "~> 1.15.0"
spec.add_development_dependency "rspec", "~> 3.0"
spec.add_development_dependency "rspec"
spec.add_development_dependency "rake"
spec.add_development_dependency "simplecov"
end
12 changes: 12 additions & 0 deletions config/action_subscriber.yml.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
defaults: &defaults
heartbeat: 15
host: rabbitmq
network_recovery_interval: 5
port: 5672
username: demo
password: demo

production: *defaults
development: *defaults
test: *defaults
10 changes: 7 additions & 3 deletions lib/action_subscriber/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Configuration
:host => 'localhost',
:hosts => [],
:network_recovery_interval => NETWORK_RECOVERY_INTERVAL,
:password => "guest",
:password => 'guest',
:port => 5672,
:prefetch => 2,
:resubscribe_on_consumer_cancellation => true,
Expand All @@ -51,7 +51,7 @@ class Configuration
:tls_ca_certificates => [],
:tls_cert => nil,
:tls_key => nil,
:username => "guest",
:username => 'guest',
:verify_peer => true,
:virtual_host => "/"
}
Expand All @@ -67,11 +67,15 @@ def self.configure_from_yaml_and_cli(cli_options = {}, reload = false)

yaml_config = {}
absolute_config_path = ::File.expand_path(::File.join("config", "action_subscriber.yml"))
if ::File.exists?(absolute_config_path)
puts "Trying to look for config file at #{absolute_config_path}"
if ::File.exist?(absolute_config_path)
puts "config file exists, loading"
erb_yaml = ::ERB.new(::File.read(absolute_config_path)).result
# Defined in Psych 3.2+ and the new canonical way to load trusted documents:
# https://github.com/ruby/psych/issues/533#issuecomment-1019363688
yaml_config = ::YAML.respond_to?(:unsafe_load) ? ::YAML.unsafe_load(erb_yaml)[env] : ::YAML.load(erb_yaml)[env]
else
puts "config file does not exist"
end

::ActionSubscriber::Configuration::DEFAULTS.each_pair do |key, value|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def self.start_timed_task!
:execution_interval => ::ActionSubscriber.config.connection_reaping_interval,
:timeout_interval => ::ActionSubscriber.config.connection_reaping_timeout_interval) do

::ActiveRecord::Base.clear_active_connections!
::ActiveRecord::Base.connection_handler.clear_active_connections!
end

timed_task.execute
Expand Down
9 changes: 8 additions & 1 deletion lib/action_subscriber/rabbit_connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ def self.create_connection
options[:executor_factory] = ::Proc.new do
::MarchHare::ThreadPools.fixed_of_size(options[:threadpool_size])
end
connection = ::MarchHare.connect(options)

puts "march_hare new connection = #{options}"


connection = ::MarchHare.connect(**options)
connection.on_blocked do |reason|
on_blocked(reason)
end
Expand All @@ -39,6 +43,9 @@ def self.create_connection
connection
else
connection = ::Bunny.new(options)

puts "bunny new connection = #{options}"

connection.start
connection.on_blocked do |blocked_message|
on_blocked(blocked_message.reason)
Expand Down
2 changes: 1 addition & 1 deletion lib/action_subscriber/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module ActionSubscriber
VERSION = "5.3.3"
VERSION = "5.4.0"
end
5 changes: 4 additions & 1 deletion spec/integration/automatic_reconnect_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ def spoke
default_routes_for GusSubscriber
end
end
let(:http_client) { RabbitMQ::HTTP::Client.new("http://127.0.0.1:15672") }
let(:rabbitmq_management_url) {
ENV["RABBITMQ_MANAGEMENT_URL"] || "http://127.0.0.1:15672"
}
let(:http_client) { RabbitMQ::HTTP::Client.new(rabbitmq_management_url) }
let(:subscriber) { GusSubscriber }

it "reconnects when a connection drops" do
Expand Down
6 changes: 5 additions & 1 deletion spec/integration/consumer_cancellation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ def created
default_routes_for ::YoloSubscriber
end
end
let(:http_client) { ::RabbitMQ::HTTP::Client.new("http://127.0.0.1:15672") }

let(:rabbitmq_management_url) {
ENV["RABBITMQ_MANAGEMENT_URL"] || "http://127.0.0.1:15672"
}
let(:http_client) { RabbitMQ::HTTP::Client.new(rabbitmq_management_url) }
let(:subscriber) { ::YoloSubscriber }

it "resubscribes on cancellation" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
before {
pool = double("pool")
allow(pool).to receive(:with_connection).and_yield
allow(ActiveRecord::Base).to receive(:clear_active_connections!)
allow(ActiveRecord::Base.connection_handler).to receive(:clear_active_connections!)
allow(ActiveRecord::Base).to receive(:connection_pool).and_return(pool)
}

Expand Down
3 changes: 2 additions & 1 deletion spec/lib/action_subscriber/middleware/runner_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
describe ActionSubscriber::Middleware::Runner do
# TODO: Figure out at way to test this...
it "adds the router to the top of the stack"
it "adds the router to the top of the stack" do
end
end
4 changes: 4 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
::ActionSubscriber::Logging.initialize_logger(nil)
::ActionSubscriber.setup_default_threadpool!

# load from action_subscriber.yml for both ActivePublisher and ActionSubscriber
::ActivePublisher::Configuration.configure_from_yaml_and_cli
::ActionSubscriber::Configuration.configure_from_yaml_and_cli

RSpec.configure do |config|
config.mock_with :rspec do |mocks|
mocks.verify_partial_doubles = true
Expand Down
18 changes: 11 additions & 7 deletions spec/support/sample_config.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
development:
password: <%= "WAT" %>
---
defaults: &defaults
heartbeat: 15
host: localhost
network_recovery_interval: 5
port: 5672
username: WAT
password: WAT

test:
password: <%= "WAT" %>

production:
password: <%= "WAT" %>
production: *defaults
development: *defaults
test: *defaults
Loading