diff --git a/docs/src/reference/docbook/xmpp.xml b/docs/src/reference/docbook/xmpp.xml index 9576a9fe9c..691df3c57b 100644 --- a/docs/src/reference/docbook/xmpp.xml +++ b/docs/src/reference/docbook/xmpp.xml @@ -7,10 +7,6 @@
Introduction - - Spring Integration provides adapters for sending and receiving both XMPP messages and status changes from other - entries in your roster as well as XMPP. - XMPP describes a way for multiple agents to communicate with each other in a distributed system. The canonical use case is to send and receive instant messages, though XMPP can be, and is, used for far more @@ -19,12 +15,8 @@ as broadcast status changes. - XMPP provides the messaging fabric that underlies some of the biggest Instant Messaging networks in the world, - including Google Talk (GTalk) - - which is also available from within GMail - and Facebook Chat. + including Google Talk (GTalk) - which is also available from within GMail - and Facebook Chat. There are many good open-source XMPP servers available. Two popular implementations are Openfire @@ -33,76 +25,28 @@ ejabberd - . - In XMPP, - rosters - (the roster corresponds to the notion of a "buddy list" in your typical IM client) are used to manage a list of - other agents ("contacts", or "buddies", in an IM client) - in the system, calledroster items. - The roster item contains - at a minimum - the roster item's JID which is its unique ID on the network. - An actor may subscribe to the state changes of another actor in the system. The subscription can be bidirectional, - as well. - The subscription settings determine whose status updates are broadcast, and to whom. - These subscriptions are stored on the XMPP server, and are thus durable. - + Spring integration provides support for XMPP via XMPP adapters which support sending and receiving both XMPP messages and + status changes from other entries in your roster. As many other adapters, XMPP adapters come with a convenient namespace-based + configuration. + To configure XMPP namespace include the following elements into the headers of your XML configuration file: + + + - -
-
- Using The Spring Integration XMPP Namespace - - - Using the Spring Integration XMPP namespace support is simple. - - Its use is like any other module in the Spring framework: import the XML schema, and use it to define elements. - - A prototypical XMPP-based integration might feature the following header. We won't repeat this in subsequent - examples, because it is uninteresting. - - - - - - ... - - -]]> - - - -
- - +
XMPP Connection - To participate in the network, an actor must connect to an XMPP server. Typically this requires - at a minimum - a - user, apassword, ahost, and aport. + Before using inbound or outbound XMPP adapters to participate in the XMPP network actor must establish XMPP connection. This + connection object could be shared by all XMPP adapters connected to a particular account. Typically this requires - at a minimum - + user, password, host. - To create an XMPP connection, you may use the XML namespace. + To create a basic XMPP connection, you can utilize the convenience of the namespace. + subscription-mode="accept_all"/> ]]>
@@ -120,218 +63,62 @@ http://www.springframework.org/schema/context/spring-context-3.0.xsd
XMPP Messages
- Inbound Message Adapter + Inbound Message Channel Adapter The Spring Integration adapters support receiving messages from other users in the system. To do this, the - adapter "logs in" as a user on your behalf and receives the messages sent to that user. Those messages are then + Inbound Message Channel Adapter "logs in" as a user on your behalf and receives the messages sent to that user. Those messages are then forwarded to your Spring Integration client. The payload of the inbound Spring Integration message may be of the raw type org.jivesoftware.smack.packet.Message, or of the type - java.lang.String - - which is the type of the raw - Message's - body - property - - depending on whether you specify - extract-payload - on the adapter's configuration or not. - Inbound Messages are typically small and are text-oriented. Messages received using the adapter have - a pretty standard layout, with known headers (all headers have keys defined on - org.springframework.integration.xmpp.XmppHeaders): - - - - Header Values - - - - - - - - - Header Name - What It Describes - - - - - XmppHeaders.TYPE - The value of the - the - - org.jivesoftware.smack.packet.Message.Type - - enum that describes the inbound message. Possible values are: - normal, - chat, - groupchat, - headline, - error. - - - - - XmppHeaders.CHAT - A reference to the - org.jivesoftware.smack.Chat - class which represents the - threaded conversation containing the message. - - - - - - -
- - - - This adapter requires a reference to an XMPP Connection. You may - use the - xmpp-connection - element to define one. - - An example might look as follows: - - - - - - - - - - - - ]]> - - - ]]> - -]]> - - + java.lang.String if you set extract-payload value attribute to 'true' + when configuring an adapter. + Configuration support for XMPP Inbound Message Channel Adapter is provided via message-inbound-channel-adapter element. + + ]]> + + As you can see amongst the usual attributes this adapter also requires a reference to an XMPP Connection. - In this example, the message is received from the XMPP adapter and passed to a - service-activator - component. Here's the declaration of theservice-activator. - + It is also important to mention that XMPP inbound adapter is an event driven adapter and a LifeCycle object. + When started it will register a PacketListener which will listen for the incoming XMPP Messages forwarding them to the underlying + adapter which will convert them to Spring Integration Messages and send them to the output-channel. It will + unregister PacketListener when it is stopped. -
+ +
- Outbound Message Adapter - - You may also send messages to other users on XMPP using the - outbound-message-channel-adapter - adapter. The is configured like the - - xmpp-message-inbound-channel-adapter. The - adapter takes an - xmpp-connection - reference. - - - Here is a (necessarily) contrived example solution using the outbound adapter. - - - - - - - - - - - - - - - - - - - - - -]]> - - - - - The adapter expects as its input - at a minimum - a payload of type java.lang.String, and - a header value - for - XmppHeaders.CHAT_TO_USER - that specifies to which the user the payload body should be sent to. - To create a message destined for theoutbound-message-channel-adapter, you might use the following - Java code: - - - xmppOutboundMsg = MessageBuilder.withPayload("Hello, world!" ) - .setHeader(XmppHeaders.CHAT_TO_USER, "userhandle") - .build(); -]]> - - - - It's easy enough to use Java to update the XmppHeaders.CHAT_TO_USER header, and this has the advantage of dynamically updating the header at runtime in Java code. - If, however, the target is more static in nature, you can - configure it using the - XMPP enricher support. Here is an example using the enricher. The enricher enriches the Spring Integration - message - to support the header values that the outbound XMPP adapters expect. - - - - - - - -]]> - - + Outbound Message Channel Adapter + + + You may also send messages to other users on XMPP using the Outbound Message Channel Adapter. + Configuration support for XMPP Outbound Message Channel Adapter is provided via message-outbound-channel-adapter element. + + ]]> + + The adapter expects as its input - at a minimum - a payload of type java.lang.String, and a header value + for XmppHeaders.CHAT_TO_USER that specifies to which user the Message should be sent to. To + create a message you might use the following Java code: + + xmppOutboundMsg = MessageBuilder.withPayload("Hello, XMPP!" ) + .setHeader(XmppHeaders.CHAT_TO_USER, "userhandle") + .build();]]> + + Another mechanism of setting such header is by using the XMPP enricher support. Here is an example using the enricher. + + + +]]> +
+ +
XMPP Presence @@ -345,98 +132,114 @@ public class XmppMessageConsumer { If you would like to receive notification, or notify others, of state changes, you can use Spring Integration's "presence" adapters. - - The most important data for these adapters resides in the headers. The header keys are enumerated on - the org.springframework.integration.xmpp.XmppHeaders class. - - The header keys specific to these "presence" adapters start with the token "PRESENCE_". - - Not all headers are available for both inbound and outbound. - - - Header Values - - - - - - - - - Header Name - What It Describes - - - - - - - XmppHeaders.PRESENCE_LANGUAGE - The java.lang.String language in which the message was written. - - - - XmppHeaders.PRESENCE_PRIORITY - - The priority (int) of the message. Arbitrary, but it can be used to help assign relevance to a message which - in turn might be used in its handling. - - - - XmppHeaders.PRESENCE_MODE - - An instance of the enum org.jivesoftware.smack.packet.Presence.Mode that has one of the following values: - chat, available, away, - xa, dnd - - - - XmppHeaders.PRESENCE_TYPE - - An instance of the enum org.jivesoftware.smack.packet.Presence.Type - that has one of the following values: - available, unavailable, subscribe, subscribed, - unsubscribe, unsubscribed, and error. - - - - - XmppHeaders.PRESENCE_STATUS - - A java.lang.String string representing the status of the agent. This corresponds to an agents "away" message. - - - - XmppHeaders.PRESENCE_FROM - - A java.lang.String string representing the handle of the user whose state is being received. - - - - - - - -
-
- Inbound Presence Adapter + + +
+ Inbound Roster Message Channel Adapter - The first adapter supports receiving messages whenever an agent on your roster has updated its - state. Most of the important data comes in through the headers. - + Spring Integration provides Inbound Roster Message Channel Adapter which supports receiving Presence (Roster) + events from other users in the system. To do this, the Inbound Roster Message Channel Adapter "logs in" as a user + on your behalf, registers RosterListener and forwards received roster events as Messages to the channel + identified by the channel attribute. The payload of the Message could either be org.jivesoftware.smack.packet.Presence + object (see http://www.igniterealtime.org/builds/smack/docs/3.1.0/javadoc/org/jivesoftware/smack/packet/Presence.html) or + java.util.Collection<String> representing roster entries. + + + Configuration support for XMPP Inbound Roster Message Channel Adapter is provided via + roster-event-inbound-channel-adapter element. + ]]> + + As you can see amongst the usual attributes this adapter also requires a reference to an XMPP Connection. + It is also important to mention that this adapter is an event driven adapter and a LifeCycle object. + It will register RosterListener when started and will unregister RosterListener + when stopped.
-
- Outbound Presence Adapter - TBD + +
+ Outbound Roster Message Channel Adapter + + + Spring Integration also supports sending Presence (Roster) events to be seen by other users in the network. When you send a Message + to the Outbound Roster Message Channel Adapter it extracts the payload which is expected to be of + type org.jivesoftware.smack.packet.Presence + (see http://www.igniterealtime.org/builds/smack/docs/3.1.0/javadoc/org/jivesoftware/smack/packet/Presence.html) and sends it to + the XMPP Connection, thus advertising your presence events to the rest of the network. + + + Configuration support for XMPP Outbound Roster Message Channel Adapter is provided via + roster-event-outbound-channel-adapter element. + + ]]> + + It can also be a polling consumer (if it receives Messages from the Polling Channel) in which case you would + need to register a Poller. + + + +]]> + + Similar to its Inbound counterpart it requires a reference to an XMPP Connection. +
- - +
+