On 1 November 2011 08:23, Alex Kazeko
<kazekoa...@gmail.com> wrote:
"Before describing Faye I want to say that Juggernaut has 1 great benefit which Faye doesn't have - you can push events directly to Redis and Juggernaut will catch it and process. You can't easily do the same with Faye (maybe it will be done in future). Instead of it you have to send a HTTP request, which is slower and loads Faye's server."
This is technically possible, although how to do it is probably not at all obvious. I think I implemented it on a branch a while ago but now I can't find it. It was weird and I probably got rid of it. Anyway, consider the local transport, used to send messages between a client and server in the same process:
module Faye
class Transport::Local < Transport
def self.usable?(endpoint)
endpoint.is_a?(Server)
end
def batching?
false
end
def request(message, timeout)
@endpoint.process(message, true) { |responses| receive(responses) }
end
end
Transport.register 'in-process', Transport::Local
end
What we want is a client that can talk directly to Redis. Transports accept client messages and deal with sending them to the server, and giving the response back to the client, as you can see above. To make a Redis transport, what we do is we construct a Server object using the Redis engine *within* our transport, and send messages to that. No HTTP traffic is involved; the Server translates messages into Redis commands for you and it just works.
module Faye
class Transport::Redis < Transport
def self.usable?(endpoint)
endpoint.is_a?(Hash) and endpoint[:host] and endpoint[:port]
end
def batching?
false
end
def request(message, timeout)
server.process(message, true) { |responses| receive(responses) }
end
def server
@server ||= Faye::Server.new(
:engine => {
:type => 'redis',
:host => @endpoint[:host],
:port => @endpoint[:port]
}
)
end
end
Transport.register 'redis', Transport::Redis
end
You also need to make some changes to Server to support this, in order to adjust how transport negotiation works, but that's the basic idea. I ended up taking this idea out of the codebase because it was too hard for the user to make this transport's internal server act the same as a normal server, in terms of running the same extensions, etc. But if you want to have a crack at it be my guest.