librelist archives

« back to archive

Multiple Handlers For the Same Route?

Multiple Handlers For the Same Route?

From:
Matt Towers
Date:
2011-01-07 @ 17:49
Hi Everyone,

	Does anyone know if it's possible to have multiple handlers for the same 
route?  What I'd like to be able to do is, for a given incoming HTTP 
request, have one handler that does the work of sending a reply to the 
requesting client.  The other handler would simply be responsible for 
handling some custom logging based on the contents of the message payload,
but sending no reply, giving me the capability of handling my logging 
asynchronously.

	The documentation on N:M Responses seems to suggest that this is possible
but I don't see anyway to accomplish either.

	Is this the right approach?  I'm completely new to Mongrel2, so it may be
necessary to state the obvious.

	Thanks!

✈ Matt


Re: [mongrel2] Multiple Handlers For the Same Route?

From:
Zed A. Shaw
Date:
2011-01-07 @ 20:30
On Fri, Jan 07, 2011 at 09:49:07AM -0800, Matt Towers wrote:
> Hi Everyone,
> 
> 	Does anyone know if it's possible to have multiple handlers for the
> 	same route?  What I'd like to be able to do is, for a given incoming
> 	HTTP request, have one handler that does the work of sending a reply
> 	to the requesting client.  The other handler would simply be
> 	responsible for handling some custom logging based on the contents
> 	of the message payload, but sending no reply, giving me the
> 	capability of handling my logging asynchronously.

Yep, it's possible.  The easiest way is for you to write a little
"router" that just translates the normal PUSH socket into a PUB socket.
ZeroMQ comes with a few example tools that do this already and it's
literally a 10 second job.  Your handlers then just subscribe to this
PUB socket and the handler that sends replies then subscribes to
Mongrel2's pub socket.

That turns your handlers into complete PUB/SUB actors so they all the
all of the messages.  There's tons of different architectures you can
pull off with the same pattern.

-- 
Zed A. Shaw
http://zedshaw.com/

Re: [mongrel2] Multiple Handlers For the Same Route?

From:
Alex Brasetvik
Date:
2011-01-07 @ 22:49
On Jan 7, 2011, at 21:30 , Zed A. Shaw wrote:

> On Fri, Jan 07, 2011 at 09:49:07AM -0800, Matt Towers wrote:

>>         [...] The other handler would simply be
>> 	responsible for handling some custom logging based on the contents
>> 	of the message payload, but sending no reply, giving me the
>> 	capability of handling my logging asynchronously.
> 
> Yep, it's possible.  The easiest way is for you to write a little
> "router" that just translates the normal PUSH socket into a PUB socket.

On a related note, perhaps the log_spec should be configurable, defaulting
to the currently hardcoded inproc://access_log?

(It wouldn't necessarily help Matt, though, since the log_data leaves out 
some things that's available in the request message.)

-- 
Alex Brasetvik