Requirements:
- multiple sources of input (social media content) into a system
- multiple destinations of output (social media api’s)
- sources and destinations WILL be added
some pseudo:
IContentProvider contentProvider = context.getBean("contentProvider");
List<Content> toPost = contentProvider.getContent();
for (Content c : toPost) {
SocialMediaPresence smPresence = socialMediaService.getSMPresenceBySomeId(c.getDestId());
smPresence.hasTwitter(); smPresence.hasFacebook(); //just to show what this is
smPresence.postContent(c); //post content could fail for some SM platforms, but shoulnd't be lost forever
}
So now I run out of steam, I need to know what content has been successfully posted, and if it hasn’t gone too all platforms, or if another platform were added in the future that content needs to go out for it as well (therefore my content provider will need to not only know if content has gone out, but for what platforms). I’m not looking for code, although sample/pseudo is fine… I’m looking for an approach to this problem that I can implement
I’d do something like this:
Store the messages (in their “raw” form) in a table or other persistence structure, associated with their author, and having a timestamp (creation date/time for each message).
Create an association author/publication channel.
Create one (or possibly more) queues of “unsent messages”. This queue basic structure is:
So assuming I am Pamar, and I am subscribing to Twitter, GBuzz and LinkedIn, when I “post” something on your system I get an entry in the main message table, and the new message gets ID = 7686956
Let’s suppose that the message was created at 13:05:06 on 20100428
After having created it, 3 records are added in the queue:
(note that while I wrote “LinkedIn” I expect to have a record Id there and not a string)
Now, you will have one process getting records from this queue (or maybe one or multiple process for every channel, your choice how you want to scale this) accessing the queue, possibly sorted from oldest attempt to newest – this “worker” thread attempts to post on external channel, updates the last attempt timestamp, and sets the status (OK, Failed).
Another worker can delete “OK” records in the background.
Now, what happens when you add “Facebook” to my list of channels?
Easy, this operation will have a timestamp, too – the moment you add the Facebook channel to my user. You access the message table and dump all messages created before this timestamp in the queue:
When you “inject” these messages for the new channel you can decide the rules, for example, only messages from the last week, so that the “throttling” is implicit.
Adding a completely new channel will require adding a couple records in the structure, and developing a worker or a strategy class to connect to the new channel and post there using the relevant login profile and the correct API.