visionmedia/axon — pull request #26 by gjohnson (2012-08-13 05:42:43+00:00)
Title: req,rep,dealer,router

Includes the last of the major socket patterns. The only thing they are really missing is fair-queueing.

Adds a `Socket#onmessage` which can be overridden by each socket type. This returns a closure so it is super easy to write back to the socket that sent the message (super handy for rep and router). It also allows us to internally hook into messages prior to emitting the event.

Currently the "empty frame" is exposed in the router (see tests), but I am sure we could figure out how to hide it by the end of the PR. I remember chatting about this before and now I see why zmq does it; if you have multiple address envelopes with multiple body parts, you need something to distinguish the two: << address1, address2, null, body1, body2 >>.

Also, I tried to write a broker and noticed a 2 pain-point with routers:
- Routers kinda need their messages to be pretty flexible, for example this guy [lruqueue.c#L142](https://github.com/imatix/zguide/blob/master/examples/C/lruqueue.c#L142) handles 3 part messages and 5 part messages based on the context of the message. As you can probably imagine, its little awkward to accomplish this using event handlers.

- Routers also send multiple parts which makes encoding interesting, I only used binary so I skirted around it. For example, might need to be able to: `router.send("addr-1", "addr-2", "", { foo: "bar" })`.

See comments for everything else...