Building a Queue Service - Serializing Tasks for later use

I am working on creating a “Queue Manager” service and its sole responsibility is to add work items to the queue and remove work items from the queue. I have implemented the service as a singleton because I have some unique synchronization issues I have to deal with. Any time a new task is needed, I create a new Task object, set the parameters and then send it to the QueueManager service and have it added to a SQL Database. The Task object is serialized to the database at that time. When a process requests an item from the QueueManager, the service finds the next available work item and deserializes it back to a Task object – from there it gets returned to the client.

Technically, this works great. However, I’m not happy with having to shoehorn all types of tasks into a Task object. Work items can range from anything from copying files to updating databases. I have to add a lot of properties to the Task object that don’t mean anything to many other task types – it’s getting pretty sloppy. My first thought on how to fix this would be to have Task implemented as a base class, and then have all other tasks derive from Task. This would allow me to have work items such as CopyFileTask, UpdateDatabaseTask, DoLaundryTask, etc. I would then serialize the object to the database and add a column to tell me what the type is so I know how to deserialize it later.

The first problem I see doing it this way would be that the WCF Service needs to return just one type. That would require the service to down cast the work item (CopyFileTask for example) to Task. However, I now need to cast it back to its real type, but the client will have no idea what that type is.

I’m probably not doing a good job explaining this. In a nutshell, I need to:

  • Create a work object of any type
  • Pass it to a WCF service to have it stored in a DB
  • Call a WCF service to get a new work item (anything it finds)
  • Have that work item retuned to the client as a real (non casted) object

My Queue needs to be very generic since many other applications are adding and removing work items. This is being designed for a massive parallel system and will be the hub for all distributed work items. Any and all help and ideas will be greatly appriciated.

Thanks,

Scott

Answers


Have you looked at ServiceKnownTypeAttribute? Have a look at the sample code on this MSDN: http://msdn.microsoft.com/en-us/library/system.servicemodel.serviceknowntypeattribute.aspx


Need Your Help

is there 2G limit for file reading/writing by c++ fstream?

c++ windows file-io

I am writing a c++ program to read/write a large file (probably larger than 60GB). By googling the problem, it seems that there is a 2GB limit on file io in 32 bit system (I am using windows 7 64bi...

interprocess communication in webobjects (jvm, wotaskd, apache module)

java jni apache-modules webobjects

I am using the Java edition of Apple Webobjects and was wondering how it all works under the hood. For an app to run successfully it would appear that one needs the java WebObjects Application runn...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.