right now im building a rails app which needs to send xmpp (Jabber)
messages from time to time. Instead of connecting to the xmpp server
every time i want to send a message, i would like to establish a
persistent connection when the rails instance is started and use this
connection every time a message needs to be sent. What would be the
recommended way to do this in Rails. My Ideas so far are to implement
the xmpp code either as a plugin or using some kind of BackgrounDRb
task. What would you think is the best way to do it?
One way is to use a class variable in the controller which needs it.
Either create the connection in your config/environment.rb file, or add
a custom init method to the controller and set it there, like:
class MyController < ApplicationController
def initialize *args
# make sure we do the normal startup stuff
# now stuff for our specific class
@@xmpp_connection = ...
You don't need to worry about the actual arguments expected. They may
change in future versions anyway. Using *args allows for whatever they
may be and giving no arguments to #super will use any args that are