title: rails sidekiq background process
body: <p>i'm having an issue configuring the sidekiq server, the process seems to be running in the foreground as soon as i refresh my page. /consumers/fetch i need to put it in the background permanently.</p>
  
  <h1>consumers_controller.rb</h1>
  
  <pre><code>require 'kafka'
  
  class ConsumersController &lt; ApplicationController
  
    def fetch
  
      @consumer = Kafka::Consumer.new( { :host =&gt; ENV["host"],
          :port =&gt; ENV["port"],
          :topic =&gt; ENV["topic"]})
  
      @consumer.loop do |message|
        logger.info "-------------#{message.inspect}--------------"
        logger.info "-------------#{message.first.payload.inspect}--------------"
        unless message.blank?
          ConsumerWorker.perform_async(message.first.payload)
        end
      end
    end
  end
  </code></pre>
  
  <h1>consumer_worker.rb</h1>
  
  <pre><code>class ConsumerWorker
  
    include Sidekiq::Worker
  
    def perform(message)
      payload = message.first["payload"]
      hash = JSON.parse(payload)
      return @message = Message.new(hash) if hash["concern"] == 'order_create' or hash["concern"] == 'first_payment'
    end
  
  end
  </code></pre>
  
  <h1>message.rb</h1>
  
  <pre><code>class Message
  
    attr_reader :bundle_id, :order_id, :order_number, :event
  
    def initialize(message)
      @payload = message["payload"]
      @bundle_id = @payload["bundle_id"]
      @order_id  = @payload["order_id"]
      @order_number = @payload["order_number"]
      @event = message["concern"]
    end
  end
  </code></pre>