Using social networks to connect to WebSphere MQ: Twitter notifications for Queue manager and MQ applications

Source: Internet
Author: User
Tags getmessage zip websphere application server

Today, social networks are ubiquitous-to connect with friends, to keep up with the times, or to keep people informed of the latest developments in topics of common interest. Social networking is also useful in businesses. This article will show you how to quickly and easily use social networking software (such as Twitter) in your WebSphere MQ application to send status and problem information to a wide range of system administrators or end users, or even to other applications or middleware. The examples in this article use the WebSphere MQ and Twitter APIs for the JEE technology (simple message-driven bean) for the WebSphere application Server Community Edition runtime.

Brief introduction

Social networks have exploded, and the following are the sites of social networks: Facebook, LinkedIn and Twitter. Companies are now starting to build internal social networks, and IBM's ®lotus®connections products make it easy to build social networks of corporate size.

This article will show you how to use social networking software in an enterprise messaging product, such as WEBSPHERE®MQ. The three examples in this article use Twitter, but you can also use other social networking sites with APIs. Examples of these three mq-twitter are:

A simple queue in which text messages are retrieved from here and posted directly to Twitter

Queue Manager events, such as creating or deleting queues

An example of a publish/subscribe using WebSphere MQ File Transfer Edition (later referred to as WebSphere MQ FTE)

The example in this article was developed with a message-driven bean (MDB) deployed to the WebSphere application Server Community Edition. Another way is to use a stand-alone Java™ application with a message listener. The code listings that are described below are intercepted from a ZIP file that includes all the source files needed to run this example.

Twitter API

Many Java libraries provide an interface to the Twitter API. The example in this article uses the Apache Commons HTTP Library to communicate with the Twitter API. The Twitter API is a great specification-see the Twitter API Wiki for more information.

The Java method shown in Listing 1 can be used to tweet a given message. To obtain a complete Java class, download and refer to the zip file above.

Listing 1. TwitterPlugin.java:sendNotification () method

public void sendnotification (String message) {

if (message.length () > 140) {
System.err.pri NTLN ("message would be truncated from:"
+ message + "to:" + message.substring (0, 140));
  

Postmethod post = null;
    try {
HttpClient client = new HttpClient ();
Client.getparams (). Setauthenticationpreemptive (True);
Client.getstate (). SetCredentials (New Authscope ("Twitter.com", "" Realm "),
New usernamepasswordcredent IALs (GetUserName (), GetPassword ()));
Post = new Postmethod ("Http://twitter.com/statuses/update.xml");
Post.setquerystring (Uriutil.encodequery ("status=" +message));
Post.setdoauthentication (TRUE);   

//execute the get
int status = Client.executemethod (post);
Print the status and Response
System.out.println ("Status:" + status);
   
} catch (Uriexception e) {
System.err.println (e.getmessage ());
} CatCH (httpexception e) {
System.err.println (e.getmessage ());
    catch (IOException e) {
System.err.println (e.getmessage ());
finally {
//release no connection used by the method
if (post!= null) {
Post.re Leaseconnection ();
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.