Sponsored By Aspose - File Format APIs for .NET

Aspose are the market leader of .NET APIs for file business formats – natively work with DOCX, XLSX, PPT, PDF, MSG, MPP, images formats and many more!

MassTransit.js

This week I attended the CodeMash conference in Sandusky, OH. The conference was another excellent oppertunity to really reach out to other technologies and see what I could learn from them. And I had just that opportunity when I say a tweet from my buddy Karthik that he was going to pair with another friend of mine on the new hotness node.js. I quickly bounced out of my seat and ran upstairs to join in on the fun. As with learning any new language its helpful to have a problem to solve. As would happen I have recently written a naive port of my OSS project MassTransit for the Ruby language for my talk. Knowing that there wasn’t a whole lot to it I thought this would make a great problem to tackle.

For the purposes of this small port I am focusing on the core set of functionality. Subscribe to messages, execute callbacks when messages arrive, and publishing messages. This means that I also have to be able to serialize the objects as well.

The transport we used was RabbitMQ, it’s one of the newer queuing systems out there that is built on erlang. You can read all kinds of good stuff about it just using the goog’s so I encourage you to do that.

First we had to go get ‘npm,’ the node package manager, (sweet, npm is on homebrew) once we had that we pulled down the ‘amqp’ package which allows us to talk to rabbitmq. Sweet.

Next up we wrote the ./transports/amqp.js file/package. And here I hit my first “Oh, crap! This is different.” experience in JavaScript. Namely, they don’t really have classes. You really just have a bunch of untyped objects running around that are really just glorified dictionaries. (take a look) After bmavity schooled my in the ways of JS class creation, which still hurts my head, we got our javascript talking to rabbit! Boom! whoo hoo. I knew that we would soon have something banged out. We continued on next with the Envelope class that I usually write but with the complely protypical nature of the language it proved to be unnesscary. The envelope class is usually nothing more than a container for the message name and the actual message data. With JS this class was overkill since to just make one

was as much code as the class definition. Which brings up, it was weird to serialize js objects to string based forms in JSON. Unsuprisingly, it was stupid easy to do this, so our serializer.js was also very easy to write.

Next and finally is the serviceBus.js module. this module aggregates the callbacks by message type, so I was able to learn about dictionaries and lists, and how to construct larger classes.

At this point I started to run into some weirdness in how the amqp library worked, and my lack of understanding in how node.js / javascript really worked. This is also where Mr. Mavity stepped in and started to kick some butt. You can check out everything we did on github here. Pretty excited to have this, now if we can get this to work with socket.io we will have a way to actually talk to the browser!!

:)

About Dru Sellers

Sr. Software Engineer at Dovetail Software.
This entry was posted in MassTransit. Bookmark the permalink. Follow any comments here with the RSS feed for this post.
  • Anonymous

    Not in the immediate future. But if you have interest, you should do it!

  • Hakeem

    Any plans for MassTransit.fs? I just finished Real world..

    http://www.amazon.com/dp/1933988924?tag=httptomasnet-20&camp=213381&creative=390973&linkCode=as4&creativeASIN=1933988924&adid=0PWNJQS3WJ9GRN7G0AW2&

    and was impressed by the terseness of F#. The only annoyance, if I can call that is its usage of whitespaces for indentation.

    Please let me know if you have any plans on that front, I’d be glad to pitch in 😉

  • Anonymous

    @Ryan, yes in order for me to get the serialization in need in .Net it has to be that way. One of the goals of this fun little project is to enable js ruby .net C etc so I have to make some concessions for the stricter languages.

    @Guest: Since I do not use SilverLight at all, I really have no idea. :(

  • Guest

    Does this mean that you will soon be able to use MassTransit from a Silverlight client using javascript as the famous “additional layer of indirection”?

  • http://twitter.com/cromwellryan Ryan Cromwell

    Will be fun to watch. Be interesting to look at how this evolves in comparison to Akka.

    Any reason your env.message is a string and not just another object? As in:
    var env = { messageName:”messagename”, message: {name:”dru”}};

  • Anonymous

    Will do!

  • http://twitter.com/EisenbergEffect Rob Eisenberg

    Dude. Seriously keep us posted on this goodness. I have some crazy javascript of my own I’ve been working on in my spare time. It’s probably the most excited I’ve been about something I’ve created in a while. JavaScript is really coming into its own with all the great libraries like node.js and efforts like common.js.