diff --git a/Gemfile b/Gemfile index fc76bca..18113b4 100644 --- a/Gemfile +++ b/Gemfile @@ -29,6 +29,10 @@ gem 'activeadmin' gem 'activeadmin_addons' gem 'devise' +# Взаимодействие с микросервисами +gem 'httparty' +gem 'bunny' + group :development, :test do gem 'bundler-audit' gem 'capybara' diff --git a/Gemfile.lock b/Gemfile.lock index 63e5241..427773d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -95,6 +95,7 @@ GEM uri (>= 0.13.1) addressable (2.8.7) public_suffix (>= 2.0.2, < 7.0) + amq-protocol (2.3.3) arbre (1.7.0) activesupport (>= 3.0.0) ruby2_keywords (>= 0.0.2) @@ -108,6 +109,9 @@ GEM bundler-audit (0.9.2) bundler (>= 1.2.0, < 3) thor (~> 1.0) + bunny (2.23.0) + amq-protocol (~> 2.3, >= 2.3.1) + sorted_set (~> 1, >= 1.0.2) byebug (11.1.3) capybara (3.40.0) addressable @@ -182,6 +186,10 @@ GEM has_scope (0.8.2) actionpack (>= 5.2) activesupport (>= 5.2) + httparty (0.22.0) + csv + mini_mime (>= 1.0.0) + multi_xml (>= 0.5.2) i18n (1.14.5) concurrent-ruby (~> 1.0) inherited_resources (1.14.0) @@ -226,6 +234,8 @@ GEM mini_mime (1.1.5) mini_portile2 (2.8.8) minitest (5.25.1) + multi_xml (0.7.1) + bigdecimal (~> 3.1) net-imap (0.5.6) date net-protocol @@ -313,6 +323,7 @@ GEM activerecord (>= 6.1.5) activesupport (>= 6.1.5) i18n + rbtree (0.4.6) rdoc (6.7.0) psych (>= 4.0.0) redcarpet (3.6.0) @@ -385,6 +396,7 @@ GEM sprockets-rails tilt securerandom (0.3.1) + set (1.1.1) sexp_processor (4.17.2) shoulda-matchers (6.4.0) activesupport (>= 5.2.0) @@ -401,6 +413,9 @@ GEM actionpack (>= 3.1) railties (>= 3.1) slim (>= 3.0, < 6.0, != 5.0.0) + sorted_set (1.0.3) + rbtree + set (~> 1.0) sprockets (4.2.1) concurrent-ruby (~> 1.0) rack (>= 2.2.4, < 4) @@ -449,6 +464,7 @@ DEPENDENCIES activeadmin_addons activerecord-import bundler-audit + bunny capybara config database_consistency @@ -460,6 +476,7 @@ DEPENDENCIES factory_bot_rails fasterer ffaker + httparty parallel pg pry-byebug diff --git a/config/settings.yml b/config/settings.yml index b004f16..55590c4 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -4,3 +4,20 @@ app: archives_folder: <%= ENV.fetch('ARCHIVES_FOLDER') { 'db/data/' } %> sql_dump_path: <%= ENV.fetch('SQL_DUMP_PATH') { 'db/data/development.sql' } %> index_concurrent_processes: <%= ENV.fetch('INDEX_CONCURRENT_PROCESSES') { Parallel.processor_count } %> + +rabbitmq: + hosts: <%= ENV.fetch('RABBITMQ_HOSTS', 'localhost').split(',') %> + port: <%= ENV.fetch('RABBITMQ_PORT', '5672') %> + vhost: <%= ENV.fetch('RABBITMQ_VHOST', '/') %> + user: <%= ENV.fetch('RABBITMQ_USER', 'guest') %> + password: <%= ENV.fetch('RABBITMQ_PASSWORD', 'guest') %> + heartbeat_interval: <%= ENV.fetch('RABBITMQ_HEARTBEAT_INTERVAL') { 60 } %> + exchange: <%= ENV.fetch('RABBITMQ_EXCHANGE', 'services') %> + exchange_type: <%= ENV.fetch('RABBITMQ_EXCHANGE_TYPE', 'topic') %> + +sneakers: + workers: <%= ENV.fetch('SNEAKERS_WORKERS') { 1 } %> + threads: <%= ENV.fetch('SNEAKERS_THREADS') { 1 } %> + queue: <%= ENV.fetch('SNEAKERS_QUEUE') { 'like_in' } %> + health_check_lifetime: 60 + amqp_stub: <%= ENV.fetch('SNEAKERS_AMQP_STUB') { false } %> diff --git a/lib/tasks/like.rake b/lib/tasks/like.rake new file mode 100644 index 0000000..7c30d74 --- /dev/null +++ b/lib/tasks/like.rake @@ -0,0 +1,10 @@ +desc 'Ставим like' +task like: :environment do + json_path = Rails.root.join('spec', 'fixtures', 'like.json').to_path + message = JSON.parse(File.read(json_path)) + connection = Bunny.new(Settings.rabbitmq.to_hash).start + channel = connection.create_channel + exchange = channel.topic('services', durable: true) + exchange.publish(message.to_json, routing_key: Settings.sneakers.queue) + connection.close +end diff --git a/spec/fixtures/like.json b/spec/fixtures/like.json new file mode 100644 index 0000000..de1399f --- /dev/null +++ b/spec/fixtures/like.json @@ -0,0 +1,11 @@ +{ + "id": "d8560533-9d18-44e1-9fdd-4672c6a39e6c", + "from": "rake", + "action": "like", + "params": { + "id": "d8560533-9d18-44e1-9fdd-4672c6a39e6c", + "action": "like", + "folder": "f.fb2-440801-444899.zip", + "book": "440905" + } +} \ No newline at end of file