EGL Development User Group

EGL Development User Group

EGL Development User Group

The EGL Development User Group is dedicated to sharing news, knowledge, and insights regarding the EGL language and Business Developer product. Consisting of IBMers, HCL, and users, this community collaborates to advance the EGL ecosystem.

 View Only

A Solution for Message Transfer in EGL

By Jiyong Huang posted Wed April 01, 2020 09:19 PM

  
Many Web 2.0 applications need a mechanism to transfer messages between each other. In many enterprise environments, developers use WebSphere MQ to provide support for exchanging messages. In this blog, I will introduce a message mechanism which uses EGL and WebSphere MQ Bridge for HTTP to exchange messages.

Solution
1. Introduction of WebSphere MQ Bridge for HTTP
Websphere MQ Bridge for HTTP enables client applications to exchange messages with WebSphere MQ on any platform or language with HTTP capabilities without the need for a WebSphere MQ client. The WebSphere MQ Bridge for HTTP consists of a J2EE servlet that is connected to WebSphere MQ via a resource adapter. The HTTP servlet is capable of handling 3 different types of HTTP requests: POST, GET and DELETE. For more details, visit the WebSphere MQ Bridge for HTTP website.  

2. Combine EGL and WebSphere MQ Bridge for HTTP
Below is a framework that allows EGL to access and exchange external messages via HTTP, and transfer internal messages within HTTP client (Web 2.0 application) though the EGL Infobus.

image

In this solution, we define two message entries: Event and Chat. Event means a real-time event that happens in the HTTP client, while Chat means a message by which users communicate in the distributed environment. They have the same way of working, for example:

One user “Tom” publishes a status to his web page: Hello EGL. The Rich UI handler publishes the message to the Infobus, and we have already subscribed the Infobus under the same topic with a callback function. When the message reaches the Infobus, the callback function is invoked and the EventScanner delivers the message to the WebSphere MQ Bridge for HTTP. The WebSphere MQ Bridge for HTTP transfers the message to the corresponding Message Queue.

Another user “Paul” has signed in the web application. The EventScanner polls the data though HTTP every second. When the new message “Hello EGL” arrives, the message is delivered to the Infobus and the Rich UI handler displays it on Paul’s web page.

Implementation
1. Set up environment of WebSphere MQ Bridge for HTTP

For the detailed instructions of how to install and configure the WebSphere MQ Bridge for HTTP, you can access the tutorial and installation package

Create a connection factory with WebSphere MQ messaging provider in WebSphere Application Server. The JNDI name is “jms/WMQHTTPJCAConnectionFactory”, and the Queue Manager is “HTTPQM”.  (We’ll create it in MQ later).

After the application is deployed,  launch WebSphere MQ Explorer, open the view “MQ Explorer-Navigator”, and create a Queue Manager named “HTTPQM”. Leave the defaults for the other parameters and click Finish. The queue manager is created.

At last, create the following local queues as the pictures show.
queues

2. Develop EGL application for Web 2.0
In this section, we’ll develop a web 2.0-based application named “RBD Team Hub”. Please note that we’ll not demonstrate all the components for the application in this blog. I’ll just focus on the message component.
screenshot of messaging app
Here is the code snippet for the message component, according to the message solution.

library ChatScannerLib type BasicLibrary{}
    oldMessage string = "";
    function scan()
        Infobus.subscribe("com.ibm.egl.hub.chat.send", callback);
        new Job{runFunction = getMessage}.repeat(1000);
    end
    function callback(name stringin, data anyin)
        sendmessage string = data asstring;
        destInternetId string = clip(sendMessage[21 : 40]);
        atIndex int = strLib.indexOf(destInternetId, "@");
        destQueue string = destInternetId[1 : atIndex - 1];
        serv IRest{@RestBinding{}};
        call serv.invokePost("http://localhost:9080/mq/msg/queue/" +
                        destQueue, sendmessage) returningto invokePostCallback
                onException handlerExcep;
    end
    function getMessage()
        myInternet string = RbdMemberScannerLib.myInternetId;
        atIndex int = strLib.indexOf(myInternet, "@");
        myQueue string = myInternet[1 : atIndex - 1];
        msg string;
        serv IRest{@RestBinding{}};
        call serv.invokeDelete("http://localhost:9080/mq/msg/queue/" +
                        myQueue, msg) returningto invokeDeleteCallback
                onException handlerExcep;
    end
    function invokeDeleteCallback(message stringin)
        if(message != oldMessage && message != "")
            srcInternetId string = clip(message[1 : 20]);
            destInternetId string = clip(message[21 : 40]);
            rbdMember RbdMember = RbdMemberScannerLib.getRbdMemeberByInternet(srcInternetId);
            if(rbdMember != null)
                ChatDialogLib.setUserName(rbdMember.name);
                ChatDialogLib.setPhoto(rbdMember.photo);
            end
            messageBody string = clip(message[41 : strLib.characterLen(message)]);
            chatHistory string = rbdMember.chatHistory + rbdMember.internetid +
                            ": " + messageBody + "<BR>";
            RbdMemberScannerLib.setChatHistory(destInternetId, chatHistory);
            ChatDialogLib.setChatHistory(rbdMember.chatHistory);
            ChatDialogLib.showChat();
        end
    end
    function invokePostCallback(sendMesage stringin)
    // TODO
    end
    function handlerExcep(e AnyException in)
    // TODO
    end
end

For the part of message, the topic of Infobus is listed as below.

TopicPublisherSubscriber
com.ibm.egl.hub.event.sendUserDetailEventScannerLib
com.ibm.egl.hub.event.recieveEventScannerLibWorkBench
com.ibm.egl.hub.chat.sendChatDialogLibChatScannerLib
 

Samples
You can download the HubClient sample project. Open “MainHandler.egl” with the Visual Editor, or just deploy the whole project to an application server and run it in external browser.

Below is a list of username for end-users:
tom@us.ibm.com
john@us.ibm.com
jack@us.ibm.com
paul@us.ibm.com
tina@us.ibm.com

Login to the application using one of the user names above, using “password” as the password.
login dialog

When you click the Login button, the system will verify the username and password via the dedicated service. Once the authentication passed, the main workbench will display. In this scenario, assume there are two users using this application: Tom and Paul. Let’s see how the components of Event and Chat work in this solution.
  • Event in the web page
User “Tom” published a status “Hello EGL!”, and we can see the event shows in the message panel within Paul’s web page.
image
  • Chat in the web page

User “Tom” launches a chat session with “Paul”, let’s see the effect in the web page. The chat history has been pictured as follows.
image

 

Summary

EGL supports many ways to communicate with legacy systems, such as databases, message queues, and service providers. You can use SOAP or REST services in EGL to consume or provide services as part of your SOA and Web 2.0 applications. The Enterprise Service Bus (ESB) and MQ can be also integrated quickly in EGL without even writing any code.

To sum up, EGL has a flexible and extensible way to enable users customize their own frameworks or solutions in their applications.


Peng Fei Yu 

0 comments
3 views

Permalink