Tuesday, July 29, 2014

Asynchronous webservice response.

I hope you all are doing well.
After a very long time I am going to post this article. I switched to a different technology.
Within last two years I worked on android and few Java related things. Now again I moved to CF.

Recently I faced one issue with my client Process we built one webservice which accept large XML file from client and process it parallel. While processing large data 1st we faced challenges with the memory.
It was a quick fix we used Sax parser instead of DOM.

But recently we faced one issue that when client is sending large files in every 5 minutes our process is not able to process that file within 5 mins. So we are not receiving very next file.

To resolve that I change our webservice from synchronous to Asynchronous mode.
In Asynchronous mode we are sending them response after getting file and processing that file in backend so we are not missing any files.

This solution is really worked for me. If you are having same kind of issue this solution may help you to come up from your situation.
To do that I used ColdFusion event gateway feature.
Event gateway lets CFML code send a message to CFC methods asynchronously. This event gateway lets you initiate processing by a CFC method without waiting for it to complete or return a value.
By default, ColdFusion delivers the message to a CFC method named onIncomingMessage. You can specify any method name, however, in the SendGatewayMessage method's data parameter.
3 Steps to create gateway
·          Create a CFC with an onIncomingMessage method. Put the CFC in an appropriate directory for your application. For example, you can put it in the cf_root\WEB-INF\cfusion\gateway\cfc directory on J2EE configurations, in the cf_root\gateway\cfc directory on server configurations, or in a subdirectory of these directories. ColdFusion is installed with mappings to these cfc gateway directories.
·          The onIncomingMessage method must take a CFEvent structure that contains input information in its Data field, and processes the contents of the Data field as needed.
·          Use the Gateways page in the ColdFusion Administrator to add an instance of the CFML event gateway type. Specify the following:
o    A unique Gateway ID.
o    The path to the CFC that you created in step 1.
o    The startup mode. Select Automatic startup mode to start the event gateway when ColdFusion starts up.
o    Do not specify a configuration file.
·          Start the event gateway instance.

Using Gateway
·          Write CFML code that uses SendGatewayMessage functions to send messages in structures to the event gateway instance ID that you specified in CFAdmin. The SendGatewayMessage function returns true if the gateway successfully queues the message in the ColdFusion Gateway Service; false, otherwise. It does not ensure that the CFC receives or processes the message.
·          Run your CFML application.






Friday, June 29, 2012

New flavor to execute query from coldfusion cfscript.


As you know that coldfusion added java coding style in cfscript tag.

Here one example of executing query from coldfusion cfscript tag.

Retrieve resultset with multiple id's

function getResultSetByIDs(string dsn, required numeric userIDs) {
     // Setup a variable for the Query Result
    var qResult = '';
    // Setup the Query variable
    var q= new query();
    // Add Parameter
    q.addParam(name="ID", value=arguments.userIDs, cfsqltype="CF_SQL_INTEGER" list="true");
    // Create the SQL String
    var sqlString="
            SELECT    *
            FROM      USERS
            WHERE    
                      USERID IN (:ID)
        ";
    q.setdatasource(arguments.pDsn);
    q.setsql(sqlString);
    qResult=q.execute().getresult();
    return qResult; 
}

Monday, June 25, 2012

Now Facebook session can be shared with our ColdFusion Applications


Yesterday I was trying to build one application which can share session with FaceBook. That means if I logged in FaceBook Then I don’t need to login in my application.
I know Facebook Platform is a set of APIs. SO i try to digg into FB and after a bit of research I find out it’s possible and ‘Benoit Hediard’ already build it in ColdFusion. That’s great !!!! .
SDK URL http://facebooksdk.riaforge.org/
To use facebook session in our application we need to create one APP id/Key in Facebook Development
https://developers.facebook.com/
By which we can also track how many users logged in
From where logged in.
What they are doing in our site.
…..
…..

and Many more.
I like it very much.