Pages

Saturday, September 1, 2012

ROQUE : the simplest way to do asynchronous queuing and events in .NET

I am excited to announce that Benjamin Eidelman from the Cinchcast Tech team open-sourced ROQUE : the simplest way to do asynchronous events and queuing in .NET.
You can read more details about it at GITHUB page: https://github.com/benjamine/Roque


ROQUE sits on top of the C# abstractions you know (plain old C# events and methods), and uses Redis behind the scenes to make them work in an asynchronous, transparent, distributed, scalable, decoupled and failure-proof way.
Message queueing doesn't get simpler than this!
Lets say we have a website and we want to build thumbnails for uploaded pics, that's a time-consuming operation we can't perform during the lifetime of web request.
1- Create a service interface.
    public interface IImageProcessor {
        void CreateThumbnail(string filename, int width, int height, AlgorithmOptions options);
    }
2- Use it on your application:
    public class ImageBiz {
        IImageProcessor ImageProcessor = RoqueProxyGenerator.Create<IImageProcessor>("images");
        public void ImageUploaded(filename){
            ImageProcessor.CreateThumbnail(filename, 160, 120, new AlgorithmOptions { Quality=0.7 });
        }
    }
Note: add references to Roque.Core and Roque.Redis assemblies to your project.
3- Config a redis-based queue named "images":



That's it you are already enqueuing jobs!

4- Implement your image processor service:
    public class ImageProcessor : IImageProcessor {
        public void CreateThumbnail(string filename, int width, int height, AlgorithmOptions options = null){
            // a time-consuming task, eg: resize the image and save it adding a suffix
            throw new NotImplementedException();
        }
    }
5- Install Roque service on a machine (with access to your Redis server).
6- On the same folder of roque.exe drop the assembly(ies) containing IImageProcessor interface and ImageProcessor class.
7- On the worker Roque.exe.config:



8 - Start Roque service to start processing images!
(or you can roque.exe from a console, use: roque.exe /debug to attach your VisualStudio and debug your image processor)
You're done, now you can start adding more workers to get automatic load balancing by repeating steps 5 to 8.
To check the status of your queues you can run: roque.exe status
C:\>roque status /maxage=10 /maxlength=500000
Redis send-pump is starting
roque Information: 0 : [REDIS] connected to localhost:6379
Queue images has 262570 pending jobs. Next job was created < 1sec ago.
Queue audiofiles has 3342 pending jobs. Next job was created 12sec ago. [TOO OLD]
Queue zipping is empty.
ERROR: 1 queue have too old pending jobs

Reactions:

3 comments:

You don’t always have to do everything you want done by yourself. You can hire people to take care of it for you. The free college research papers only here can do a perfect work on uploading pictures. Sometimes when you have to read throughout a post it makes it boring. The pictures with its colors can help make the reading fun.

Post a Comment