Using wamp_client gem in rails
RajatGoyal opened this issue · comments
Hi Eric,
I was trying to integrate this gem into my rails app, the gem works fine indepently but when i load rails environemnt along with the script, i get disconnected just after connecting and verbose:true also dosen't print logs.
Script that works:
require 'wamp_client'
wsuri = 'wss://api.poloniex.com'
options = {
uri: wsuri,
realm: 'realm1',
}
connection = WampClient::Connection.new(options)
connection.on_connect do
puts 'connection established'
end
connection.on_join do |session, details|
puts 'session created'
def got_ticker(args, kwargs, details)
puts args
puts kwargs
puts details
end
session.subscribe('ticker', method(:got_ticker))
end
connection.open
Rake task that does not work:
task :poloniex => :environment do
wsuri = 'wss://api.poloniex.com'
options = {
uri: wsuri,
realm: 'realm1',
verbose: true
}
connection = WampClient::Connection.new(options)
connection.on_connect do
puts 'connection established'
end
connection.on_join do |session, details|
puts 'session created'
def got_ticker(args, kwargs, details)
puts args
puts kwargs
puts details
end
session.subscribe('ticker', method(:got_ticker))
end
connection.open
end
I tried loading the environment manually as well, which also dosen't work:
require File.expand_path('../../config/environment', __FILE__)
require 'wamp_client'
wsuri = 'wss://api.poloniex.com'
options = {
uri: wsuri,
realm: 'realm1',
}
connection = WampClient::Connection.new(options)
connection.on_connect do
puts 'connection established'
end
connection.on_join do |session, details|
puts 'session created'
def got_ticker(args, kwargs, details)
puts args
puts kwargs
puts details
end
session.subscribe('ticker', method(:got_ticker))
end
connection.open
Output that i get from the scripts that do not work:
connection established
Attempting Reconnect... Next attempt in 2 seconds
connection established
Attempting Reconnect... Next attempt in 4 seconds
``
Hey @RajatGoyal. We are getting there. I actually haven't tested this with Rails yet only because I am not sure how well Event Machine plays with Rails. Could you implement "on_disconnect" and print out the "reason" it disconnected?
so the reason is
WAMP Protocol Error (invalid type <type 'NoneType'> for 'authmethods' detail in HELLO)
@RajatGoyal This is the error I just fixed. Please make sure you are using version v0.0.5 of the gem
Gemfile
gem 'wamp_client', '~> 0.0.5'
@ericchapman If I remember correctly, I updated the gem and the above-mentioned working script is also using the same gem. I will take a look again tonight; when I am back home.
@RajatGoyal Did you ever figure this out?
Independent of that error, one thing to note is that this GEM is based on Event Machine which blocks the thread that calls "run". Basically, I am not sure how friendly Rails is with threading so there may be something special that needs to be done to get this running.
I know that Rails 5.0 introduced "Action Cable" which is a competing websocket based interface. One of these days I was going to look at the implementation of that to see what underlying websocket library they used and how they integrated it with Rails. I abstracted the "transport" in this library so I may be able to just get it working the same way they did in Action Cable
Closing since no response and I believe issue was fixed