The community forums are in BETA and closed to the public.

node.js pipelined client


I've put together a node client using the HTTP pipelining API. It currently supports publish, subscribe, grant and works only on Objects and JSON'd objects (although the change is trivial). The API is a bit different as I've tried to make this as bare to the metal as possible. As usual any feedbacks and contributions are welcomed.


Daniel, here's my first impression: You are awesome.

We'll play around with this and get you some real feedback this week.

Thanks. I've added compression support for subscribe (gzip), it seems to work nicely.

Any idea why the official pubnub client JSON.stringify's twice when publishing an encrypted message?

Hi Ian, did you guys have time to check it?

The JavaScript SDK double-JSON-encodes because the crypto library only works with strings as input:

If an Array or other Object were passed to this function, it would explode. :\ Some form of serialization is required at the encryption level. JSON was chosen because it's easy to deserialize on the other end, after decryption.

The encrypted output is also a string, and can only be sent over the PubNub network as JSON. So there's a second level of JSON encoding for that.

All that so you can support not only JSON strings? hehe so everyone pays the price of two JSON.stringify's.

It's a combination of the limits imposed by the language (how do you encrypt an Object?) and the REST API (how do you send it?

Everything seems to check out from my end. Theoretically this should be faster than our current NodeJS implementation, would be cool to measure. I forwarded the repo to the maintainer of our current js libs and our CTO @stephen_blum.

Ian, thanks but he knows it already ;) This library was born out of necessity here at Our backend had problems dispatching a high volume of grants and publishes using the official js library, so I wrote this one. It is faster, for the naive case like a setInterval(publish, 0); it's 35x faster. I'm still investigating a JSON parser error I saw in my logs yesterday, this client is in production since last Wed.

Daniel, it sounds most excellent! Just tried it out briefly, and it's working great.

I think we could use the same kind of thing for Python, which is a project I'm interested in starting...

Comments to this discussion are now closed!