简体   繁体   English

如何在不使用docker-compose for rails的情况下配置sidekiq和redis?

[英]How to configure sidekiq&redis without using docker-compose for rails?

I want to implement sidekiq to my rails app. 我想在我的rails应用程序中实现sidekiq。 I successfully create image and container. 我成功创建了图像和容器。 But when i try to execute job container in application can't find redis. 但是当我尝试在应用程序中执行job容器时找不到redis。 How i can connect my-app container (which has it's own IP:port) with redis container (which has it's own IP:port). 我如何连接我的应用程序容器(它有自己的IP:端口)与redis容器(它有自己的IP:端口)。

I think the problem hides in sidekiq.rb. 我认为这个问题隐藏在sidekiq.rb中。 But I'm not sure 但我不确定

sidekiq_config = { url: "<container url>" }

Sidekiq.configure_server do |config|
  config.redis = sidekiq_config
end

Sidekiq.configure_client do |config|
  config.redis = sidekiq_config
end

I want to run 2 containers : my-app & redis . 我想运行2个容器: my-appredis In my-app container sidekiq should know how to ping redis container. my-app容器中,sidekiq应该知道如何ping redis容器。

PS My ̶r̶e̶l̶i̶g̶i̶o̶n̶ mentor do not allow me use docker-compose so it's pretty tricky PS我的̶r̶e̶l̶i̶g̶i̶o̶n̶导师不允许我使用docker-compose所以它非常棘手

Considering your statement: 考虑你的陈述:

...your app (which has its own IP:Port) with Redis container (which has it's own IP:Port). ...你的应用程序(有自己的IP:端口)和Redis容器(它有自己的IP:端口)。

You might want to check how what your "<container url>" looks like. 您可能想要检查"<container url>"外观。 For more insight, this is how I suggest it looks like: 为了更深入了解,我的建议如下:

config/initializers/sidekiq.rb 配置/初始化/ sidekiq.rb

Sidekiq.configure_server do |config|
  config.redis = { url: 'redis://redis.example.com:7372/0' }
end

Sidekiq.configure_client do |config|
  config.redis = { url: 'redis://redis.example.com:7372/0' }
end

Then right in your application.rb define the queue adapter as sidekiq 然后在您的application.rb中将队列适配器定义为sidekiq

config/application.rb 配置/ application.rb中

config.active_job.queue_adapter = :sidekiq

Also, note that sidekiq looks for the configuration file in config/sidekiq.yml and if the file is present it starts with the defined configuration. 另请注意,sidekiq在config/sidekiq.yml sidekiq.yml中查找配置文件,如果文件存在,则以定义的配置启动。 So check if you have config set. 所以检查一下你是否有配置集。 It might be the main issue you have as you didn't give enough clue on what you have done. 这可能是你遇到的主要问题,因为你没有给出你所做的足够的线索。

config/sidekiq.yml 配置/ sidekiq.yml

---
:verbose: false
:concurrency: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
:timeout: 30
:queues:
  - [low_priority, 1]
  - [high_priority, 2] # high priority

For more insight how you use Redis with Sidekiq, kindly check https://github.com/mperham/sidekiq/wiki/Using-Redis 有关如何将Redis与Sidekiq一起使用的更多信息,请查看https://github.com/mperham/sidekiq/wiki/Using-Redis

I found out that we can easily connect 2 containers with docker by using --link 我发现我们可以使用--link轻松地将2个容器与--link连接--link

sudo docker run --name my-application --link my-redis-container:redis

This Link was helpful for me. 这个链接对我有帮助。 And here we don't actually need to use docker-compose 在这里,我们实际上不需要使用docker-compose

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM