Wrangling up XMPP
Asked Answered
V

5

18

Wikipedia defines XMPP as:

...an open-standard communications protocol for message-oriented middleware based on XML.

xmpp.org defines XMPP as:

The Extensible Messaging and Presence Protocol (XMPP) is an open XML technology for real-time communication, which powers a wide range of applications.

Although I'm sure both these definitions are very accurate, they don't tell me a thing about what I - a Java developer - can actually do with XMPP!

For instance, I've heard XMPP can be used with message-oriented middleare (MOM). How so? Can XMPP somehow integrate with my Apache Camel routes, my ESB or some SOA implementation to deliver a better/faster/more robust business tier? If so, how?!?!

A good, King's-English explanation of XMPP, along with some practical examples (preferable MOM-centric) would be greatly appreciated. Thanks in advance!

Vedda answered 7/4, 2012 at 2:38 Comment(1)
+1. Good problem statement, problem bounds, and bounty statement. I completely support this, on the grounds that the best resources appear to, once again, be paywalled, and a good working definition in prose would be widely applicable to many people here on SO. Thanks!Stirk
T
18

XMPP can be used for a wide range of messaging based applications. Basically, it provides core services which can be used to build XML based messaging applications. Its based on a decentralized client-server architecture and utilizes long-lived TCP connections for communicating...

core services include...

  • channel encryption, authentication, presence, contact lists, one-to-one messaging, multi-party messaging, notifications
  • service discovery, capabilities advertisement, structured data formats, workflow management, peer-to-peer media sessions

textbook use cases...

  • instant messaging (using presence, contact lists, one-to-one messaging)
  • group chat, gaming, systems control, geolocation, middleware/cloud computing, data syndication
  • bots (weather, database interface, system monitoring)

messaging modes/patterns...

  • point-to-point messaging is used to send to a specific receiver
  • multi-user messaging is used to message to a group of receivers
  • publish/subscribe support is used when there are large volume of events and systems are interested in differing subsets of events. Publishers put events into topics and subscribers indicate which topics they are interested in. This decouples the publisher/subscriber and allows for scalable real-time messaging. For more information, see this article: http://www.isode.com/whitepapers/xmpp-pubsub.html

deployment methods...

  • XMPP user - connects as a normal user and responds to requests addressed to the user
  • XMPP Server plugins - deployed as part of the server plugin architecture
  • XMPP Components - service external to an XMPP server that connects and behaves like a plugin

Java Integration

  • Smack API - A pure Java library, it can be embedded into your applications to create anything from a full XMPP client to simple XMPP integrations such as sending notification messages and presence-enabling devices.
  • Camel XMPP - A Camel component that allows integration with Smack API in Camel routes

To your specific question "can it be used in SOA/middleware?"....

  • yes, it can be used to wire together applications via XML messaging and XMPP APIs
  • whether its the best technology choice depends heavily upon requirements
  • one good use case, interactive system monitoring/management...here are some other examples

Also, XMPP integration with Camel is trivial. See this camel-xmpp unit test for a basic example of interfacing with a Google Talk server. Also, Camel's framework allows you to build an application and easily swap out different messaging technologies (JMS, STOMP, mina, etc).

Tonnage answered 9/4, 2012 at 23:29 Comment(0)
M
4

XMPP is an open and extensible standard for real time communications.

XMPP comes with a core that is defined in its rfc, which describes the basic protocol for doing instant messaging and exchanging presence information. However where XMPP really shines is in its extensibility: XMPP defines the building blocks (presence, message and iq stanzas) to create protocols of communication. These typically come as extensions. A list of currently available standard extensions can be found here. The most important of these are typically available for all the popular XMPP servers. It is exactly this extensibility that makes XMPP appropriate as message-oriented middleware.

Let me take as an example Publish-Subscribe which is a typical pattern for middleware and becomes a necessity as soon as you depart from the scenario with a few entities where simple messaging is adequate. PubSub is used in situations where entities, or producers, produce information that is to be consumed by other entities, the consumers. Typically, the information is written to nodes, to which consumers are subscribed. Being subscribed they receive notifications when an item is added/updated/deleted. An incredible amount of use-cases can be elegantly covered by PubSub, from queuing long-running jobs and having workers handle them, to micro-blogging. XMPP has a very robust and widely available extension to handle PubSub in a standard way, described in XEP-0060 and providing out of the box a workflow for handling publishing, subscriptions, notifications and security. Having a look at the use-cases in the XEP will give you an idea for the simplicity of the whole thing.

Now, while most use-cases are covered by using (or abusing) existing standard extensions, eventually you might need the little extra custom protocol that is not covered elsewhere. Using your language of choice you can write an XMPP component defining your own protocol. You then connect the component to the XMPP server you are running and by using simple namespacing let the server know what kind of messages you can handle and let the server advertise your protocol capabilities to clients connecting to it. There is no end to how simple or complex you can make this. Lack of better example but maybe good enough for illustration, here is a component I wrote that leverages XMPP to do real-time collaborative editing in the Plone CMS (similar to Google docs). While the details can get complicated I think having a look at the "Protocol Specication" on that page will give you an idea.

Finally, concerning Java specific libraries as @boday mentions, there are libraries around that make it easy to start with as well as Apache Camel integration (although it only does simple messaging as far as I can see). Keep in mind though that the investment in understanding how XMPP works and being able to go beyond using existing libraries is really worth it and can lead to extremely powerful and yet simple integration.

Mcavoy answered 10/4, 2012 at 15:28 Comment(0)
I
4

I can start combining information from al kinds of sources found on the internet using Google (keywords: XMPP Java MoM examples), rewrite (or even copy) the definition of XMPP, but of course I will not do so. There is just too much. I also do not have examples available for you.

Below I will list the links I found most interesting, so you can start reading and get more knowledge on the subject.

1) http://www.xmpp.org/ This is probably the best starting point. Browse through the menu left to right and top to bottom. That is what I did. The site lists servers, clients and libraries, so you should be able to find the desired examples this way.

2) http://www.ibm.com/developerworks/webservices/library/x-xmppintro/index.html Clear article, which also mentions MoM. No Java examples, but Ruby.

3) http://fyi.oreilly.com/2009/05/what-can-you-do-with-xmpp.html Maybe you should just get the book? No examples in the article.

4) http://kirkwylie.blogspot.com/2008/07/real-mom-is-hard-lets-use-xmpp.html Interesting article where the last line basically says: Why use XMPP if you can use AMQP or JMS?

I hope this helps you I finding what you need.

Iveyivie answered 10/4, 2012 at 15:45 Comment(1)
You might want to have a look at devdaily.com/java/jwarehouse/activemq/activemq-xmpp as well. It is an example of using XMPP as transport in ActiveMQ. In the test folder it includes a broker and a test client. camel.apache.org mentions Apache ActiveMQ as a project to leverage Apache Camel as a routing and mediation engine.Iveyivie
V
0

Let me just give you a good overview of what XMPP is ?

  • XMPP ( Extensible Messaging and Presence Protocol )
  • It is a Real time communication protocol.
  • The first IM service based on XMPP was Jabber.org
  • One XMPP binding is BOSH. Others include TCP and WebSocket.
  • BOSH is "Bidirectional-streams Over Synchronous HTTP", a technology for two-way communication over the Hypertext Transfer Protocol (HTTP).
  • BOSH emulates many of the transport primitives that are familiar from the Transmission Control Protocol (TCP). For applications that require both "push" and "pull" communications, BOSH is significantly more bandwidth-efficient and responsive than most other bidirectional HTTP-based transport protocols and the techniques known as AJAX.
  • BOSH achieves this efficiency and low latency by long polling.

How does XMPP works?

XMPP achieves low latency by implementing Long polling.

What is Normal Polling and Long Polling ?

NORMAL POLLING:

enter image description here

Consider the old chat apps that used normal polling. Here the top of the graph indicates client side. Bottom indicates server side. Let the timeout be 5 min.

Client asks the server : " Is there any new message for me ?"
Server Responds : "No ! "

                   After 5 min

Client asks the server : " Is there any new message for me ?"
Server Responds : "No !"

                  After 1 min

Client Receives a message

                  After 4 min

Client asks the server : " Is there any new message for me ?"
Server Responds : "Yes! " + message.

LONG POLLING

enter image description here

The top part of the graph is client . Bottom part is server.

Client asks the server : " Is there any new message for me ?"
Server Answers : "No ! But you may soon receive a new message, so let me just hold your client state for 5 min in the server."

                  After 5 min

Server Responds : "No !"
Client asks the server : " Is there any new message for me ?"
Server Answers : "No ! But you may soon receive a new message, so let me just hold your client state for 5 min in the server."

                  After 1 min

Client Receives a message
Server Responds : "Yes! " + message.

You can see clearly, how instantaneously the communication happens.

You can read more about XMPP HERE

In case, if you are curious to set up your own XMPP server, read this.

Varney answered 4/5, 2016 at 6:39 Comment(1)
BOSH is only one of multiple bindings supported by XMPP. Others include TCP and websocket.Frig
G
-2

XMPP is fundamentally a protocol for chat room clients to talk to a chat server. Camel does allow you to integrate with XMPP so that you can consume messages from or produce to such a mechanism http://camel.apache.org/xmpp.html

When you start talking business tier, ESB, SOA etc. and MOMs you're probably looking for a messaging mechanism that supports point to point and publish subscribe messaging. You're probably also thinking about things such as guaranteed messaging, high availability, and fine-grained security. You won't get these from a mechanism that reads and writes text messages into a chat server. A messaging platform such as ActiveMQ is likely to be a far better fit.

There are very few instances where I would contemplate using XMPP with integration mechanisms, maybe as a notification mechanism to a dev chat room, or as a duct-tape mechanism for controlling servers that monitor a chat server for instructions.

Granddaughter answered 9/4, 2012 at 12:29 Comment(6)
Most of your statements are inaccurate. The fact that XMPP supports simple chat messaging does not make it a chat protocol. XMPP also readily provides extensible support for PubSub (xmpp.org/extensions/xep-0060.html). Most important, XMPP provides all the cruft necessary to define and extend with new protocols.Mcavoy
@Mcavoy - you seem to be pretty confident in your understanding of XMPP. Would you care to weigh-in with an answer here?Vedda
@AdamTannon I contemplated doing so, but I always loathed Java enough to not be able to readily provide examples with it ;) Maybe if nobody comes up with an answer I will give it a try if you are happy with conceptual XML examples.Mcavoy
If the example was good enough I would accept something that wasn't Java. Java is my strongest language so it will be easier for me to relate ideas in terms of it, but I have a decent understanding of Python (as your profile indicates) or other 3GLs (.NET, etc.) to connect the dots once a solid example has been laid out for me.Vedda
@Mcavoy He is correct. XMPP was originally designed to be THE IM protocol. It even says it in their RFC introduction. "it is used mainly for the purpose of building instant messaging."Endow
@AndrewFinnell I do not claim he is incorrect. I claim he is inaccurate ;). XMPP has by design a minimal core which is about presence and messaging. There exist though tons of default extensions, that all servers come with that provide the stuff that actually make XMPP awesome and are interesting to the OP. Most of the XMPP deployments are about the extras not the core.Mcavoy

© 2022 - 2024 — McMap. All rights reserved.