Juggernaut lets you push data to browser, which means you can do awesome things like multiplayer gaming, chat, realtime collaboration and more!
Juggernaut is super simple and easy to get going. Juggernaut 2, which is a completely rewrite, is built on node.js, is insanely fast, and can scale horizontally to millions of clients.
- node.js server
- Ruby client
- Supports the following protocols:
- WebSocket
- Adobe Flash Socket
- ActiveX HTMLFile (IE)
- Server-Sent Events (Opera)
- XHR with multipart encoding
- XHR with long-polling
- Reconnection support
- SSL support
<script src="http://localhost:8080/application.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
var jug = new Juggernaut;
jug.subscribe("channel_name", function(data){
console.log("Got data: " + data);
});
</script>
Juggernaut.publish("channel_name", {:some => "data"})
Juggernaut.publish(["channel1", "channel2"], "foo")
- Node.js
- Redis
- Ruby
- Install node.js - http://nodejs.org/
- Install Redis - http://code.google.com/p/redis/
- Install the Juggernaut gem (optional) - (gem install juggernaut)
Start Redis
>> ./redis-server redis.conf
Download Juggernaut, and start the Juggernaut server:
>> git clone git://github.com/maccman/juggernaut.git --recursive
>> cd juggernaut
>> node server.js
That's it! Now go to http://localhost:8080 to see Juggernaut in action.
Flash is optional, but it's the default fallback for Firefox (until the beta is released). Start the server using root if you want Flash support. It needs to open a restricted port. Also, you need to specify the location of WebSocketMain.swf
Either copy it to your web app root, or set the address like this:
window.WEB_SOCKET_SWF_LOCATION = "http://juggaddress:8080/WebSocketMain.swf"
Juggernaut has SSL support! To activate, just put create a folder called 'keys' in the 'juggernaut' dir, containing your privatekey.pem and certificate.pem files.
>> mkdir keys
>> cd keys
>> openssl genrsa -out privatekey.pem 1024
>> openssl req -new -key privatekey.pem -out certrequest.csr
>> openssl x509 -req -in certrequest.csr -signkey privatekey.pem -out certificate.pem
Then, pass the secure option to Juggernaut:
var juggernaut = new Juggernaut({secure: true})
http://kevin.vanzonneveld.net/techblog/article/run_nodejs_as_a_service_on_ubuntu_karmic
Just create more Juggernaut daemons. Put a TCP load balancer in front of them. Make sure they all connect to the same Redis instance. Use sticky sessions.
<script src="http://localhost:8080/application.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
var jug = new Juggernaut;
jug.subscribe("/chats", function(data){
var li = $("<li />");
li.text(data);
$("#chats").append(li);
});
</script>
Juggernaut.publish("/chats", params[:body])
<script src="http://localhost:8080/application.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
var jug = new Juggernaut;
jug.subscribe("/chats/<%= current_user.id %>", function(data){
var li = $("<li />");
li.text(data);
$("#chats").append(li);
});
</script>
Juggernaut.publish(users.map {|u| "/chats/#{u.id}" }, params[:body])
def sync_clients
users.map(&:id)
end
Check out client/examples/juggernaut_observer.rb and client/examples/juggernaut_observer.js