Sunday, February 24, 2013

Extending OEDQ to Oracle DB AQ

OEDQ can be characterized as a re-active application. Subscribing or Publishing systems interact through web services. The problem with web services is that they are synchronous. This means that a request is sent and a response is recieved by the same application. There are scenarios when data quality results need to be pulbished to multiple systems, not just the application calling the web service. The below article describes how to publish the results of a request payload to multiple applications through the use of an Advanced Queue (AQ).


Purpose: Configuring OEDQ to publish results to an Oracle Database Advanced Queue (AQ)

Components Needed:
- Oracle Data Base Advanced Queue
- Custom Script Processor
- JDBC connection string to Oracle DB

Steps:
1. Create PL/SQL script to insert into Oracle DB AQ. Script needs to do the following:
     a. Recieve Input as part of call
     b. Create payload with input
     c. Insert payload to AQ
     d. Commit

2. Add OEDQ Script processor
3. Create script using Goovy to do the following:
     a. Import groovy.sql syntax/library
     b. Define input variable
     c. Create new instance to db using JDBC connection
     d. Call PL/SQL package and/or stored procedure
     e. Pass input variable as part of previous step

Example PL/SQL to AQ Script:

create or replace
PROCEDURE ( p_payload IN  CLOB ) as

 o_payload         XXX;
 enq_msgid          RAW(16);
 eopt               dbms_aq.enqueue_options_t;
 mprop              dbms_aq.message_properties_t;
 err_message        varchar2(2000);

 v_payload         VARCHAR2(5000);
 len               BINARY_INTEGER;

Begin
  o_payload := XXX( p_payload  );

  eopt.sequence_deviation := NULL;
  mprop.priority :=1;
  dbms_aq.enqueue( 'AQ Name', eopt, mprop, o_payload  , enq_msgid);
  Commit;
END;



Example Groovy to AQ Script:

#! language : groovy
import groovy.sql.Sql
import groovy.xml.MarkupBuilder
def inputs =
    '<?xml version="1.0" encoding="UTF-8" ?>' + '<Payload xmlns="http.xxx.xxx.com
' + "<Root Node>" + "<Node1>" + input1[0] + "</Node1>" + "<Node2>" + input1[1] + "</Node2>"  + ...etc. +"</RootNode>"
sql = Sql.newInstance("jdbc:oracle:thin:@hostname:port:SID, "Username", "Password", "oracle.jdbc.OracleDriver" )
sql = sql.call("call Procedure to insert into AQ('$inputs')")



6 comments:

  1. Hi,
    I would like to write a processor to call a web service. Do you have any example of widgets.xml from calling a method in jar file ?
    Regards,

    ReplyDelete
    Replies
    1. Hello,

      Great Question! Unfortunately, I do not have any sample modified widget.xml files that call a method for invoking a web service. As an alternative, you can use the script processor. You can write a script to invoke a web service endpoint url and submit an xml message. I have provided some sample code below for doing this.


      try {

      var url = "http://xxxxx";
      var xmlHttp = new XMLHttpRequest();

      var params = "" +
      "" +
      "" +
      "" +
      "" + input1[0] + "" +
      "" +
      "" +
      "";


      var request = params;
      var result = new String();
      xmlHttp.open("POST", url, false);
      xmlHttp.send(request);

      }


      catch (e) {
      result = "Error:";
      }

      output1 = result;

      Hope this helps! I will be posting an article on invoking web services and APIs through the script processor soon. That might also help.

      Delete
    2. Thanks for your reply, I tried groovy script in script processor for request like below,
      #! language : groovy
      import groovyx.net.http.*
      output1 = new String[2]
      def http = new HTTPBuilder( 'http://ajax.googleapis.com' )
      output1[0]='a'
      output1[1]='b',
      But i got Script1.groovy: 4: unable to resolve class HTTPBuilder error. Do you know that groovy ing Oracle EDQ support these ?
      Regards,

      Delete
  2. Hi,

    I would send a final output from EDQ after Match and Merge to the Target System using web services. Can you pls advice me how to do this?? I tried the script which you mentioned above but I am getting an error "unable to resolve class xmlhttprequest" @ line 5 column 17

    ReplyDelete
  3. Hi Jay,

    I have a requirement where in i need to call a stored procedure from business rule check file in EDQ to validate the data.
    Is it possible and if yes...could you please provide a sample code.

    ReplyDelete
  4. Hi,

    Does Groocy work for https url as well ?

    ReplyDelete