[Backgroundrb-devel] can't return array object from worker

MurugaRaj murugarajb at dckap.com
Wed Dec 23 22:49:57 EST 2009

Hello all,

Subject: Not able to return object from backgroundrb worker

I am trying to use xmpp4r and backgroundrb for my chat application.
I am able to create a connectnion with XMPP4r through a worker in

I have the problem in returning the object from the worker to my rails

My code is as follows:

class ChatWorker < BackgrounDRb::MetaWorker
  require 'xmpp4r'
  require 'xmpp4r/bytestreams'
  require 'xmpp4r/roster/helper/roster'
  require 'xmpp4r/roster/iq/roster'
  include Jabber
  Jabber::debug = true

  set_worker_name :chat_worker
  def create(args = nil)
    # this method is called, when worker is loaded for the first time
    logger.info 'Initializing Chat Worker.......'
  def connect_chat(args)
    logger.info "Conencting chat.......#{args[:username]} --"
    jid = Jabber::JID.new(args[:username])
    @client = Jabber::Client.new(jid)
    logger.info "Chat Connection status - #{@client.is_connected?}"
    return @client.is_connected?
  def connected?
    return @client.is_connected?
  def get_buddies
    if self.connected?
      @buddy_list = []
      roster = Jabber::Roster::Helper.new(@client)
      mainthread = Thread.current
      roster.add_query_callback { |iq|
      roster.groups.each { |group|
         roster.find_by_group(group).each { |item|
          @buddy_list << item#[{:name => item.iname, :jid => item.jid,
:subscription => item.subscription}]
      logger.info "Buddies\n#{@buddy_list.inspect}"
      return @buddy_list


When i call the connect_chat worker method from console i am able to
connect to the server as below.
MiddleMan.worker(:chat_worker).connect_chat(:arg => {:username =>
'xxx at gmail.com',:password => 'xxxx'})

But when i try to call the get_buddies worker method, i am not able to
get the buddy list as below.
Even in the log file, i printed the @buddy_list object and its showing
the correct result. But it is not returning the result.

The problem is with result returning.

Could you please help me in solving the issues. I am struggling with
this for the whole day.

Thank you for your any kind of suggestions.

Murugaraj B

More information about the Backgroundrb-devel mailing list