回到目录

为什么要有本篇文章

本篇文章主要实现了RTX消息生产者,并且完成了整体的设计方式,之前在设计时消息生产者全局使用单一的生产方式,即一个项目里使用了Email就不能使用SMS,这种设计方法和实际不相符,虽然在性能上是最佳的(采用了单例模型,维护一个生产者,使用策略模式进行生产者的实现,使用工厂模式生产具体生产者),实际项目中,应该是可以自动选择消息生产者的,当然为了程序的性能,我们还必须使用单例模式来生产具体生产者,这种单例,在本程序中,采用了具体类型,具体单例的方法,即Email自己维护单例,SMS自己维护单例,这样,程序即能满足实际的需要,又可以提高自己的性能!

第五回  消息组件

第六回  消息组件~续

强大的设计

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAyMAAAErCAIAAABCfcvWAAAgAElEQVR4nO3d+1NTaYL/8f1Tzv/ED1219a2aqi3L7qp2pYHBZm3HbttpjJdVbARBESEY7qJc5NJeQG65QSCAAqLiJZKEi649Tu8u1tbz/SEME3M5OQnJc/LkvF/1ri46HALtPHg+I6j/IgAAAJAb/2L2BwAAAFCwWFoAAAC5wtICAADIFZYWAABArrC0AAAAcoWlBQAAkCssLQAAgFxhaQEAAOQKSwsAACBXWFoAAAC5wtICAADIFZYWAABArrC0AAAAcoWlBQAAkCssLQAAgFxhaQGAtW1vC69X2O3CbhfnzwubjUi9Igd4dFSEw2Z/RsViaQGAhU1Nibo60dIi+vrE+LjwesXKinj2jEilZmfF+LgYHBStreLqVdHbK/7nf8z+1PonlhYAWNL2tmhsFA6HePxYvH4tPn4Unz4RqV0gIFwu0d0trl0T796Z/Tm2h6UFANYTDovaWjEwIObmxIcP5t8gibLV77+LlRUxMiLq68Xr12Z/pgnB0gIAy/n8Wdy4IQYHxYsX4m9/IyrAQiHx8KGorc2HLyOytADAYsbGRFubWFgw/3ZIlLvW1kR3t+jtNfvzjaUFAJayvS3q6sTEhHj/3vx7IVFO83rFtWumfw2RpQUAVjI+LhwO8eqV+XdBM9I0Lebl6Efir0l4gfHXpvXxJHu2lB+hzodxwA9P+cJh0dUl+vrM/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QiqVFloqlBQCQiqVFloqlBQCQiqVFloqlBQCQKrK0pqaILNHEBEsLACARS4ssFUsLACAVS4ssFUsLACAVS4ssFUsLACCVzSbGx8XkJJElYmkBAKRiaZGlYmkBAKRiaZGlYmkBAKSKLK2JCSJLND7O0gIASMTSIkvF0gIASMXSIkvF0gIASMXSIkvF0gIASMXSIkvF0gIASGWzicePxfg4kSV6/JilBQCQiKVFloqlBQCQiqVFloqlBQCQ6soV8eCB+fc/IjmxtAAAUjU2inv3zL//Ecnp4UNx+bK5n3MsLQCwkqEh0dEhHj8mskR374rWVnM/51haAGAlL16IhgYxNmb+LZAo142NCbtd+Hzmfs6xtADAYlpbxd275t8FiXLd4KC4cUN8/mzuJxxLCwAs5tMnUVsrHj40/0ZIlLsePRL19SIcNvvzjaUFABb05IloaGBsUcH26JFoahJut9mfaUKwtADAovx+UVsr7t4VY2NEBdXQkLh+PU9mlmBpAYB1ffokWltFU5O4c8f8uyPRwRsYEC0t4to18e6d2Z9d/8TSAgBrW1gQnZ3CZiNSvsZG4fWa/i3wMVhaAAAAucLSAgAAyBWWFgAAQK6wtAAAAHKFpQUAAJArLC0AAIBcYWkBAADkCksLAAAgV1haAAAAucLSAgAAyBWWFgAAQK6wtAAAAHKFpQUAAJArLC0AAIBcYWkBAADkCksLAAAgV1haAAAAucLSAgAAyBWWFgAAQK6wtAAAAHKFpQUAAJArLC0AAIBcYWkBAADkCksLAAAgV1haAAAAucLSAgAAyBWWFgAAQK6wtAAAAHKFpQUAAJArLC0AAIBcYWkBAADkCksLAAAgV1haAAAAucLSAgAAyBWWFgAAQK6wtAAAAHKFpQUAAJArLC0AAIBcYWkBAADkCksLAAAgV1haAAAAucLSAgAAyJX/D8948ahgg4rxAAAAAElFTkSuQmCC" alt="" />

强大的生产者

  /// <summary>
/// 消息生产者
/// 具体消息生产者是单例,如Email,SMS,Rtx等
/// </summary>
public class MessageFactory
{
/// <summary>
/// 消息工厂
/// </summary>
public static IMessageManager GetService(MessageType messageType)
{
switch (messageType)
{
case MessageType.Email:
return EmailMessageManager.Instance;
case MessageType.SMS:
return SMSMessageManager.Instance;
case MessageType.RTX:
return RTXMessageManager.Instance;
default:
throw new NotImplementedException("消息生产者未被识别...");
}
} }

RTX生产者的实现

   /// <summary>
/// RTX消息服务
/// </summary>
internal class RTXMessageManager : IMessageManager
{
#region Singleton
private static object lockObj = new object();
public static RTXMessageManager Instance;
static RTXMessageManager()
{
lock (lockObj)
{
if (Instance == null)
Instance = new RTXMessageManager();
}
}
private RTXMessageManager()
{ }
#endregion private string EncodingString(string str)
{
return HttpUtility.UrlEncode(str, Encoding.GetEncoding("GB2312"));
} private string rtxUrl = System.Configuration.ConfigurationManager.AppSettings["RtxApi"] ??
"http://192.168.1.8:8012/sendnotifynew.cgi?"; #region IMessageManager 成员 public void Send(string recipient, string subject, string body)
{
Send(new List<string> { recipient }, subject, body);
} public void Send(IEnumerable<string> recipients, string subject, string body)
{
try
{
var dic = new Dictionary<string, string>()
{ {"title",EncodingString(subject)},
{"msg",EncodingString(body)},
{"receiver", EncodingString(string.Join(",",recipients))},
{"delaytime",""}
};
StringBuilder str = new StringBuilder();
foreach (var item in dic)
{
str.Append(item.Key + "=" + item.Value + "&");
}
new HttpClient().GetAsync(rtxUrl + str.ToString()).Wait();
}
catch (Exception ex)
{
Logger.Core.LoggerFactory.Instance.Logger_Info(ex.Message);
}
} public void Send(IEnumerable<string> recipients, string subject, string body, bool isAsync)
{
if (isAsync)
Task.Run(() =>
{
Send(recipients, subject, body);
});
else
Send(recipients, subject, body);
} #endregion
}

回到目录

我心中的核心组件(可插拔的AOP)~消息组件~完善篇的更多相关文章

  1. 我心中的核心组件(可插拔的AOP)~大话开篇及目录

    回到占占推荐博客索引 核心组件 我心中的核心组件,核心组件就是我认为在项目中比较常用的功能,如日志,异常处理,消息,邮件,队列服务,调度,缓存,持久化,分布式文件存储,NoSQL存储,IoC容器,方法 ...

  2. 我心中的核心组件(可插拔的AOP)~第二回 缓存拦截器

    回到目录 AOP面向切面的编程,也称面向方面的编程,我更青睐于前面的叫法,将一个大系统切成多个独立的部分,而这个独立的部分又可以方便的插拔在其它领域的系统之中,这种编程的方式我们叫它面向切面,而这些独 ...

  3. 我心中的核心组件(可插拔的AOP)~第四回 异常拦截器

    回到目录 之前说过有关拦截器的文章,第二回  缓存拦截器,事实上,在那讲里说的最多是AOP和缓存组件,对于拦截的概念并没有详细的说明,这一讲,不说AOP,主要说一下拦截器,拦截器Interceptio ...

  4. 我心中的核心组件(可插拔的AOP)~第五回 消息组件

    回到目录 之所以把发消息拿出来,完全是因为微软的orchard项目,在这个项目里,将公用的与领域无关的功能模块进行抽象,形成了一个个的组件,这些组件通过引用和注入的方式进行工作,感觉对于应用程序的扩展 ...

  5. 我心中的核心组件(可插拔的AOP)~第六回 消息组件~续

    回到目录 上一回写消息组件已经是很久之前的事了,这一次准备把消息组件后续的东西说一下,事实上,第一篇文章主要讲的是发消息,而这一讲最要讲的是收消息,简单的说,就是消息到了服务器之后,如何从服务器实时的 ...

  6. 我心中的核心组件(可插拔的AOP)~调度组件quartz.net

    回到目录 quartz.net是一个任务调度组件,它可以灵活的设置你的调试方式,按时间,按日期,按周期都可以很容易的实现,quartz不仅可以用在web中,而且还可以部署在winform,winser ...

  7. 我心中的核心组件(可插拔的AOP)~第十二回 IoC组件Unity

    回到目录 说在前 Ioc组件有很多,之前也介绍过autofac,castle等,今天再来说一下在微软Nlayer DDD架构里使用的unity组件,今天主要说一下依靠注入,如果希望看拦截的用法,可以阅 ...

  8. 我心中的核心组件(可插拔的AOP)~第十三回 实现AOP的拦截组件Unity.Interception

    回到目录 说在前 本节主要说一下Unity家族里的拦截组件,对于方法拦截有很多组件提供,基本上每个Ioc组件都有对它的实现,如autofac,它主要用在orchard项目里,而castle也有以拦截的 ...

  9. 我心中的核心组件(可插拔的AOP)~第十五回 我的日志组件Logger.Core(策略,模版方法,工厂,单例等模式的使用)

    回到目录 之前的讲过两篇关于日志组件的文章,分别是<第一回  日志记录组件之自主的Vlog>和<第三回  日志记录组件之log4net>,而今天主要说一下我自己开发的另一种日志 ...

随机推荐

  1. qq协助

    今天和一个朋友开完笑说让我进他的电脑,从而出现这篇文章!!!!   目前的QQ版本支持远程协助,所以想到通过两个QQ号码完成对另一台电脑的控制第一台电脑:1.自动登录QQ2.打开另一个QQ号码窗口3. ...

  2. 《Photon》

    搭建客户端: using UnityEngine;using System.Collections;using ExitGames.Client.Photon; public class GameCl ...

  3. 自定义actionbar标题

    这是我自己封装的一个activity,主要作为所有Activity的基类,可以一键关掉所有的activity, 并共享一个自定义actionbar.直接切入主题吧. 第一步就是创建自定义标题的布局文件 ...

  4. 原生js-日历插件

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  5. golang坑1

    :=比较方便,不过今天掉进了一个小坑 var ( foo *XXX ) func bar() { fmt.Println(foo.abc) } func main() { foo, err := XX ...

  6. Add more security in Visual Studio 2012

    Compile flags: /GS: Stack protection from buffer overrun. /SDL: Subset of W3&W4 security warning ...

  7. armv6, armv7, armv7s的区别

    ARM是微处理器行业的一家知名企业,arm处理器以体积小和高性能的优势在嵌入式设备中广泛使用,几乎所有手机都是使用它的. armv6, armv7, armv7s是ARM CPU的不同指令集,原则上是 ...

  8. vim插件神器spf13在Linux上的安装

    官网给出的安装办法很简单: curl http://j.mp/spf13-vim3 -L -o - | sh 可惜有问题: connection reset by peer 正确的姿势是: curl ...

  9. 8.4.3 Glide

    1). 导入库 dependencies { compile 'com.github.bumptech.glide:glide:3.5.2' compile 'com.android.support: ...

  10. 转:linux coredump调试

    1 )如何生成 coredump 文件 ? 登陆 LINUX 服务器,任意位置键入 echo "ulimit -c 1024" >> /etc/profile 退出 L ...