📄 x503.htm
字号:
<HTML
><HEAD
><TITLE
>Asynchronous Nature</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.64
"><LINK
REL="HOME"
TITLE="Programming Jabber"
HREF="book1.htm"><LINK
REL="UP"
TITLE="Inside Jabber"
HREF="c445.htm"><LINK
REL="PREVIOUS"
TITLE="XML-Based"
HREF="x455.htm"><LINK
REL="NEXT"
TITLE="Messaging"
HREF="x524.htm"></HEAD
><BODY
CLASS="SECT1"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>Programming Jabber</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="x455.htm"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
>Chapter 2. Inside Jabber</TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="x524.htm"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="SECT1"
><H1
CLASS="SECT1"
><A
NAME="JABTDG-CH-2-SECT-2.2"
>Asynchronous Nature</A
></H1
><P
>The exchange and distribution of information in real world scenarios
requires more than a synchronous (sequenced) request/response framework.
In IM, people originate chat messages in a spontaneous and unpredictable
manner (especially if there's alcohol involved). In a loose network of
independent applications, messages originate on a similar 'random' event
basis. This asynchronous activity requires a design equally asynchronous
in nature—and that is what Jabber has.</P
><P
>To allow for the generation—and more importantly the
receipt—of messages in an asynchronous fashion, Jabber's
programming model for client and server alike is an
<I
CLASS="EMPHASIS"
>event-based</I
> one. An event-based programming model
is nothing to be afraid of. In simple terms it's just a loop that iterates
either doing nothing in particular or doing something regularly (like
checking for user input and acting upon it if required) while waiting for
something—an event—to happen.
In Jabber's case, it will be the receipt
of an XML fragment. Depending on what type of fragment it is, a
<I
CLASS="EMPHASIS"
>handler</I
> will
be called to deal with that fragment. We saw a simple example of this in
the Perl script in <A
HREF="c324.htm"
>Chapter 1</A
>.</P
><P
>In all but the simplest deployment examples of Jabber, the event model
pervades. We will see the model in action in Part II.
And while we've reduced the receipt of chat messages to a rather dry and
generic event idea, let's also look at some concepts that often go hand
in hand with event-based messaging systems.</P
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="JABTDG-CH-2-SECT-2.2.1"
>Store and forward</A
></H2
><P
>Depending on circumstances, if you send a message to someone who's not
currently connected, that message will be held and passed to the recipient
when he does connect. </P
><P
>Likewise, in the wider context of application to application (A2A) or
application to person (A2P) messaging, this store and forward concept
is often useful in non-time-critical situations, such as a centralized
logging mechanism where the log-writing component might be temporarily
unavailable, or a workflow scenario where an application passes a message
to a supervisor for approval (in this case, the message would be similar
to an email). </P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="JABTDG-CH-2-SECT-2.2.2"
>Queuing</A
></H2
><P
>Indeed, in the case of the recipient being offline and messages being
handled by a store and forward mechanism, or simply where the recipient
cannot handle the messages as fast as they arrive, the nature of the XML
stream in which these message fragments are transmitted
(see <A
HREF="c3612.htm"
>Chapter 5</A
> for details)
means that the messages are naturally <I
CLASS="EMPHASIS"
>queued</I
>,
to be handled in the order that they arrive. </P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="JABTDG-CH-2-SECT-2.2.3"
>Message receipt</A
></H2
><P
>In many cases, it's not much use sending a message to an application, and
have it queued or stored offline, without having an idea of whether the
recipient actually did (eventually) receive and handle it. Jabber supports
the concept of <I
CLASS="EMPHASIS"
>message receipt</I
>, whereby the sender can
request an
acknowledgment of receipt from the recipient. This request is sent along
with the message itself. We'll see message receipt in action in the recipes
in Part II.</P
></DIV
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="x455.htm"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="book1.htm"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="x524.htm"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>XML-Based</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="c445.htm"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Messaging</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -