-
Notifications
You must be signed in to change notification settings - Fork 137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for WebSockets #167
Comments
thanks ... and what would be the error you've seeing - did you get any advise from the faye guys ? |
Faye requires rack.hjiack implementation. It's certainly the problem. |
I see, for future reference http://blog.phusion.nl/2013/01/23/the-new-rack-socket-hijacking-api/ |
Is it possible to implement it? |
Well, have you tried :) ? ... I think it is (but I did not look closely) although maybe using EE 8 APIs, definitely should be possible to hack into a working state with Tomcat's (Trinidad) API. |
I have a small example that illustrates using WebSockets with Tomcat and JRuby. I thought I would document my journey here. My first attempt was to spin up a rails 5.1.4 application. Naturally I started using action cable. I noticed it didn't work in Trinidad or Tomcat. I switched to Puma. Everything worked. Then I learned about rack hijacking and realized it just plain wasn't supported for JRuby people :-(. So how hard would it be to implement rack hijacking in JRuby? I entertained it briefly, but that did send me away with my tail tucked between my legs. To start consider the following library written in java:
This java library got its start from one of the example applications that ships with tomcat. The file is called ChatAnnotation.java and a quick search in a base Tomcat install (in my case Tomcat 8.5) should reveal it. The only dependencies needed to compile it:
Here is the ruby code that drives it (required in an initializer):
And a broadcast in ruby might look like this:
So how do you wire the code into Tomcat? Suppose the Java library is in railswebsocket.jar...
It doesn't work and I don't understand why :-( Instead, I just took the jar file and dropped it into Tomcat's lib directory next to all its other jars, and I will see the static initializer get chatty. What about Trinidad? In order to get the java import:
to work I had to do this before the import:
With the environment rigged so that the above if statement is executed, this lead me to believe Trinidad doesn't have WebSocket support. I chose to use the system classloader as I assumed JRuby's classloader would be too high up for the Tomcat container to ever see my Java Websocket library (not that it worked). @kares -- Is making this work in Trinidad feasible? So, in short, I have to spin a war and do final testing in Tomcat where I can see my WebSockets work against the server. I hope it helps. Cris |
Hi @cshupp1, Did you test and run on production it on you tomcat? I have the similar issue for WebSocket (ActionCable v5.2.3) on jRuby (ruby 2.5.3p0 (jruby 9.2.8.0)). I've built war file by warbler from rails project, but either Tomcat nor Jetty gave me successful, the app shown me the error:
And I can confirm that the project works fine when I try to run it by Any helpful links or ways to support actioncable on jruby? |
@moskvin What I demonstrated was integrating the Java websocket APIs into JRuby. In other words, you are not using ActionCable. I can certainly help more with that if you want. It seems you want ActionCable though? Yes I can help with that too. All you need to do is not use a J2EE server (No Tomcat or Trinidad for example). None of them support rack hijacking. Switch to something like Puma. When I tried that Action cable worked out of the box exactly as the documentation says it will. When you are using Puma you are no longer using warbler and producing war files, so keep that in mind. Cris |
@cshupp1, I just build jar by warbler gem and used following format for starting rails server on remote pc:
|
@moskvin I don't see you invoking the trinidad binstub so what server are you using? |
I used puma
|
For reasons, I compile and deploy my Ruby on Rails web apps as war files, created by warbler and using embedded jetty. If we boil it all down, I'm after the fastest way to add my new features (that are best implemented with websockets) to my Rails app. If that requires that I add support for rack-hijacking to jruby-rack/jetty, then I'd love to have a go at it. That said, if there's a better way forward re: support for ActionCable in warbler-generated war files, then I would appreciate that advice. Finally, if adding rack-hijacking support to jruby-rack is the way forward, and people have thought about how it should be done, I'd appreciate reading those thoughts and advice. |
@jefflasslett In fact, Tomcat was the same way. When I used the websocket support in the Java libraries the websocket request never even made it to rack (unless I mis-configured things, which I did do). The Java library, after getting the request, notifies the ruby code. The approach I took will likely be easier. I did eventually get all my code working cleanly, but it isn't well documented. PM me if you want me to send you a link to the repo. //Cris |
@cshupp1 PM on what platform? The way you put it, I feel like I should know, but I don't :-) |
Hi,
Is it possible to add support for WebSockets ?
I try to use faye with jruby-rack but it doesn't work. It's now compatible with JRuby and works well with Puma server.
Thanks.
This issue seems to be lacking activity, you can change that by posting a bounty.
The text was updated successfully, but these errors were encountered: