要求:
一些伪的:
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
}因此,现在我已经没有精力了,我需要知道哪些内容已经成功发布了,如果还没有发布所有的平台,或者如果将来添加了另一个平台,那么内容也需要发布(因此,我的内容提供商不仅需要知道内容是否已经发布,还需要知道哪些平台)。我不是在找代码,尽管样本/伪代码很好.我正在寻找解决这个问题的方法,我可以实现
发布于 2010-04-27 14:13:09
我会这样做:
将消息(以其“原始”形式)存储在与其作者关联的表或其他持久性结构中,并具有时间戳(每个消息的创建日期/时间)。
创建关联作者/发布通道。
创建一个(或多个)“未发送消息”队列。这个队列的基本结构是:
| channelId | MessageId | Status | Last Attempt Timestamp因此,假设我是Pamar,并且订阅了Twitter、GBuzz和LinkedIn,当我在您的系统上“发布”一些东西时,我在主消息表中得到一个条目,新消息获得ID = 7686956,假设消息是在20100428的13:05:06创建的。
在创建它之后,将在队列中添加3条记录:
| channelId | MessageId | Status | Last Attempt Timestamp
| LinkedIn | 7686956 | New | 20100428 13:05:06
| Twitter | 7686956 | New | 20100428 13:05:06
| Gbuzz | 7686956 | New | 20100428 13:05:06 (请注意,当我编写"LinkedIn“时,我希望有一个记录Id,而不是一个字符串)
现在,您将有一个进程从这个队列获取记录(或者每个通道可能有一个或多个进程,选择如何缩放这个队列),可能是从最老的尝试排序到最新的--这个“工作”线程试图在外部通道上发布,更新最后一个尝试时间戳,并设置状态(OK,失败)。另一个工作人员可以删除后台的"OK“记录。
现在,当你在我的频道列表中添加"Facebook“时会发生什么呢?
很简单,这个操作也会有时间戳-当你向我的用户添加Facebook频道的时候。访问消息表并转储队列中在此时间戳之前创建的所有消息:
| channelId | MessageId | Status | Last Attempt Timestamp
| Facebook | 7685963 | New | 20100429 11:12:08
| Facebook | 7680064 | New | 20100429 11:12:08
| Facebook | 7697046 | New | 20100429 11:12:08 当您为新通道“注入”这些消息时,您可以确定规则,例如,仅决定上周的消息,因此“节流”是隐式的。
添加一个全新的通道将需要在结构中添加一对记录,并开发一个worker或策略类,以便使用相关的登录配置文件和正确的API连接到新的通道并在那里发布。
发布于 2010-04-27 13:25:05
Content知道它将被派往哪里是好的。这个逻辑应该是外部的。SocialMedia实现,则必须创建一个新的‘ll实现,并修改选择目的地的服务以添加逻辑。new操作符。(我非常赞成DI)所以,就像:
class Content {
String content; // or whatever type you store it in
ContentSource source; // who's the source of the content
// other relevant properties
}
interface SocialMedia {
boolean post(Content content);
boolean isContentSuitable(Content content);
}
class Facebook implements SocialMedia {
boolean post(Content content) {
// implement posting, return "true" if successful, "false" otherwise
}
boolean isContentSuitable(Content content) {
// decide whether this socialmedia is suitable for this content
// based on its source, its length or other features
}
}
class Twitter implements SocialMedia { .. similar to facebook }
class ContentDestinationService {
List<SocialMedia> getContentDestinations(Content content) {
List<SocialMedia> result = new ArrayList<SocialMedia>();
SocialMedia facebook = new Facebook();
if (facebook.isContentSuitable(content)) {
result.add(facebook);
}
// etc for others
return result;
}
}然后:
for (Content content : toPost) {
List<SocialMedia> destinations =
contentDestinationService.getContentDestinations(content);
int successfulPosts = 0;
for (SocialMedia sm : destinations) {
boolean success = sm.post(content);
// do something with this result, for example:
if (success) {
successfulPosts++;
}
}
}发布于 2010-04-27 13:14:03
为了保持灵活性--例如,添加新的目的地--而不是将平台(twitter、facebook)合并到函数名中,而是让它更通用。
smPresence.hasPlatform("facebook");并遍历它拥有的所有服务。继续张贴-成功标志在地图上,例如,按服务索引。
这就是你要找的吗?
https://stackoverflow.com/questions/2721419
复制相似问题