Skip to content

Instantly share code, notes, and snippets.

@billyyarosh
Last active August 29, 2015 14:02
Show Gist options
  • Save billyyarosh/f5dabd1992bb48cf11e7 to your computer and use it in GitHub Desktop.
Save billyyarosh/f5dabd1992bb48cf11e7 to your computer and use it in GitHub Desktop.
Celluloid Stomp Worker failing due to passing of current actor.
class EventsReceivingSupervisor < Celluloid::SupervisionGroup
include Celluloid::Logger
trap_exit :work_exited
def start_work(queue_name, queue_uri)
supervise_as :event_listener, StompWorker, current_actor, queue_name, queue_uri
Celluloid::Actor[:event_listener].connect
end
# Handle receiving of Message from Event Listener.
def received_message(msg, from_listener)
debug 'received_message'
end
def work_exited(actor, reason)
warn "#{actor.inspect} has died because of a #{reason.class}"
end
end
class StompWorker
include Celluloid
include Celluloid::Logger
attr_accessor :supervisor, :client
def initialize(supervisor, queue_name, queue_uri)
@supervisor = supervisor
@queue_name = queue_name
@queue_uri = queue_uri
end
def connect
info "connecting to #{@queue_uri}"
@client = Stomp::Client.open(@queue_uri)
subscribe
end
def subscribe
info "subscribing to #{@queue_name}"
@client.subscribe(@queue_name) do |msg|
debug 'subscribed msg'
@supervisor.async.received_message(msg, current_actor)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment