How to run Eventmachine server in a sidekiq worker

Viewed 257

I have Rails 4.1.5 app deployed on a server having IP let's say 1.2.3.4. A third-party client app is continuously sending xml by connecting to my server via telnet throughout the day.

I've used Eventmachine to start server on port 2000. It works fine. The problem is I'm executing this code on terminal. I want this to be in a place that runs automatically and continuously listens to the traffic coming from third-party client.

module NeoConnex
  class XmlParser < EM::Connection

    def post_init
      puts "Initial Server Message"
    end

    def receive_data(data)
      puts "Raw Data: #{data}"
    end

  end
end

EM.run do
  EM.start_server("a.b.c.d", 2000, NeoConnex::XmlParser)
  puts "Listening on port 2000"
end

I tried to use a Sidekiq worker:

class StartServerWorker
include Sidekiq::Worker

  def perfom

  end
end

Now Should I place all the code in the sidekiq perform method? and how to set recurrence of this sidekiq worker so that it can listen continuously on port 2000.

0 Answers
Related