总结Exchange同步事件与异步事件

来源:互联网 发布:淘宝买iphone靠谱上家 编辑:程序博客网 时间:2024/05/17 22:46

         Exchange内建了事件处理机制,包括同步事件与异步事件。这些事件是非常有用的,可以通过它们拦截Exchange的邮件信息,并作出相应的处理。那么,究竟什么是Exchange同步事件和异步事件,他们之间又有怎样的区别和联系,这篇文章里将给出具体的解答。

  1.首先来看一看Exchange SDK给出的同步事件定义:

Synchronous Events


Synchronous events are processed in the context of an OLE DB transaction and occur before the item has been committed to the Exchange store. Each synchronous event is called twice, once for the begin phase, and once for the commit or abort phase. The begin phase is called first for all qualifying sinks. Then the commit or abort phase is called for the same sinks. Exchange waits for each synchronous event sink to finish before calling the next.

 

There are two synchronous events that fire in the Exchange store: OnSyncSave and OnSyncDelete.

Name When the event fires OnSyncSave When an item is saved to the store, before the changes are committed. OnSyncDelete When an item is deleted from the store, before the deletion is committed.

The save and delete events also handle other events, such as moving or copying an item. Copying an item in a store generates a save event. A move causes both the save and delete events.

从中我们可以总结出以下的几点规则:

  • Exchange同步事件是在一个OLEDB事务上下文中进行处理的。
  • 同步事件在事务提交给Exchange Store之前就已发生。
  • 每一个同步事件被调用两次,一次在初始阶段,一次在事务提交或离开阶段。
  • Exchange在调用下一个事件前一直等待当前同步事件钩子完成。

用图1来描述同步事件的处理过程更加直观些:

2.SDK中关于异步事件的定义是:

Asynchronous Events


Asynchronous events fire in response to a data request after Exchange processes the request.

 

There are two asynchronous events that fire in the Exchange store: OnSave and OnDelete.

Name When the event fires OnSave When an item is saved to the store, after the changes are committed. OnDelete When an item is deleted from the store, after the deletion is committed.

The save and delete events also handle other events, such as moving or copying an item. Copying an item in a store generates a save event. A move causes both the save and delete events.

显然,异步事件是在Exchange处理完数据请求后才发生的,因此只发生一次。

用图2来描述异步事件的实现机制如下:

 3.使用Exchange同步事件、异步事件

        一个比较典型的例子就是做一个COM+,注册到Exchange服务器上,同时注册Exchange同步事件并进行安全性设置,这样当server端捕获到邮件达到的动作时就可以调用同步事件处理的有关方法,比如获得发件人、收件人甚至是邮件正文的信息等。