Calling EM.run within Goliath

64 views
Skip to first unread message

Jason Dixon

unread,
May 4, 2012, 8:52:43 AM5/4/12
to golia...@googlegroups.com
Is it possible to add tasks to EM.run within Goliath? For example, I'm
trying to create a proxy that connects outbound to a pool of sockets
without having to open a new connection for every response. The goal is
to take our existing server-queue-client model and compress it into a
single Goliath/EM application. You're probably asking "why?", and I
don't have a good answer for that one. ;)

The equivalent code in our existing worker looks something like this:

EM.run do
parser = Yajl::Parser.new
queue = EM::Hiredis.connect(redis)
ENV['SOCKET_HOSTS'].split(",").each do |socket_host|
(host,port) = socket_host.split(":")
EM::connect(host, port, SocketClient, queue, parser)
end
end

The end goal would be to have Goliath response push the payload to
EM::Queue, which would then get popped by the SocketClient and sent over
one of the long-running socket connections.

Thanks,

--
Jason Dixon
http://obfuscurity.com/
https://twitter.com/obfuscurity

Ilya Grigorik

unread,
May 4, 2012, 11:46:40 AM5/4/12
to golia...@googlegroups.com
Yup. That's exactly what the "config" files are for. In the repo, take a look at the amqp examples (or a few others). Config files are parsed at boot time and you can make shared connections available to all requests, etc.

ig

Jason Dixon

unread,
May 4, 2012, 11:49:38 AM5/4/12
to golia...@googlegroups.com
Yeah I started using a Plugin for the connection stuff and config for
the queue. Still debugging but it seems the general design is working as
intended. Thanks! :)

Jason

findchris

unread,
Mar 9, 2015, 9:03:18 PM3/9/15
to golia...@googlegroups.com
Does middleware have access to the config?

I've got a Goliath::Rack::AsyncMiddleware, and in the `call` method, I try to access `env.statsd`, where `config['statsd']` is defined in a config file with the same filename as my Goliath::API.  Seems like it should work.

Thanks for any guidance here.
Reply all
Reply to author
Forward
0 new messages