Showing posts with label OIC. Show all posts
Showing posts with label OIC. Show all posts

Wednesday, February 26, 2020

Call Custom function in OIC - Random Number Generator

Oracle Integration Cloud has lot of out-of-the-box functions available. But there would be cases where the available functions do not match our requirements. In such cases, we can create custom functions and make sure that these functions are available in our mapper or integration layer for use.

The only constraint in OIC in that the custom functions need to be written in Java Script (and not Java, unlike other products like SOA and OSB) and exported as a java script library.

Registering a Library:

Let's take a simple example of generating random numbers in the provided range and using that in our integration.


Here's the java script code -


function getRandomNum(min, max) {
  var rnd = Math.floor(Math.random() * (max - min)) + min;
  return rnd;
}

This function takes two input parameters - min and max values. The function will calculate random numbers between the min and max values each time.

Few points to note here -


  • Logic should always be wrapped in a function, if you want it to be used in OIC.
  • You always have to assign the return value to a variable and return it.

Following code will not work as intended -
  return Math.floor(Math.random() * (max - min)) + min;
You will have to assign it to a variable say rnd and return it.

Save the code in the first snippet as .js file (RandomNumGenerator.js) in your local machine. Now, we will register the js file as a library in OIC.

1. Login to OIC console, go to Integrations -> Libraries and click on the Register button at the top right corner.
2. In the Register Library pop up screen, choose the js file that you saved above. Give proper name and description of the custom library and click on Create.



3. Library has been registered successfully. You can now see the function you created in the left functions pane and some input and output parameters that you need to define.


4. Classification Type defines if you want to use the library to be used in orchestration or xpath. I chose orchestration.
5. Define the type of the input and output parameters, where they should be of Number, String or Boolean type.

Now the final library looks as follows. We are done with registering the library.



Invoking the library in your integration:

In this example, lets create a simple App driven orchestration based integration. This will be exposed as a synchronous REST service which will take two variables as input in query parameters and return a json response which will contain the random number.

1. I have created the integration with name PG_CUSTOMFUNCTION.
2. The REST trigger (named GetRandomNumber) details looks as follows -

Resource /getRandomNum

Method GET

Query Parameters

  • minVal
  • maxVal

Response

Response Media Type
  • application/json
Response sample
    { "randomVal" : "" }
3. From the Actions palette, drag and drop Javascript call after the initial trigger. Give it a name (genRandomNum) and description.
4. An editor screen of javascript opens. Click on + function to choose the javascript library that you registered.

5. Now map the input values of the javascript library by clicking on the edit icon next to Value.

6. Map the Query param minVal to the js function's input min.

7. Similarly map the Query param maxVal to the js function's input max. Save and close the action window.

8. Now map the output of the js function to final output randomVal as follows.



9. Final integration looks as follows -



Activate the integration and test it. In the below REST url, I submitted the minVal as 5 an maxVal as 99999.

https://test.oracletest.com/ic/api/integration/v1/flows/rest/PG_CUSTOMFUNCTION/1.0/getRandomNum?minVal=5&maxVal=99999

I received the response in JSON as follows. 

{
"randomVal" : "53152"
}

You will get different randoms values each time you test the service.



Tuesday, February 25, 2020

Types of Integrations in OIC

If you are SOA experienced person and new to OIC, I have covered OIC in relation to SOA . You can have a look if interested.

This blog would help us understand the differences between various integrations in OIC. I would mostly be covering the differences in technical features, so that it would be helpful during development.

Types of integrations in OIC –

Basic Routing – Any simple app to app integrations can be done through basic routing.
- No complex orchestration supported. Simple app to app integration with mappings.
- Data enrichment can be done by querying data from other systems
- Looping not supported
- Error handling not supported
Features: You would find only connections and triggers in this type of integration.

App Driven Orchestration – Supports complex orchestrations with multiple applications involved.
- Supports multi-step integration
- Looping, Error handling and many advanced concepts are supported
- Provision for Callbacks, email notifications 
- For app or business events specific integrations.
Features: You would find actions like scopes, assign, logger, notifications, for loop, etc along with connections and invokes.

Scheduled Orchestration – As the name suggests, this type of integration can be scheduled to be triggered at a mentioned time or in a timely frequency.
- Most of the features of App driven orchestration are supported here as well
- Majorly used for file based integrations or batch processing
Features: All features as in App Driven orchestration.

File transfer – Basic integration that would help to transfer files from one location to location.
Features: All features as in App Driven orchestration.

Publish to OIC - Supports publishing of any kind of messages to OIC.
- This is more like a basic routing with just connections available to publish messages to OIC through IC Messaging Service Connection.
- No other orchestration can be done here.

Subscribe to OIC – Supports subscribing the messages from OIC.
- Allows subscription of messages and pass it along to other downstream services.
- Data enrichment and app connections are allowed. 
- Not as extensive as App driven orchestration.

The above two integration can be related to working with messaging services in weblogic like Java Messaging Service.

Note: Based on the integration you choose to develop, the activities related to that integration are shown in the right palette.

Oracle Integration Cloud in relation to SOA

Are you Oracle SOA (Service Oriented Architecture) developer trying to understand OIC (Oracle Integration Cloud) from development perspective?

If you are already a pro in SOA, then OIC is a cake walk for you. But, if you are just acquainted with SOA and want to relate/compare it with OIC, well, you are at the right place.

This post will help SOA developers to understand OIC easily in SOA terminology.

1. Connection - A connection in OIC has multiple references in SOA.
  • DB Connection - It can be referred to datasource created in weblogic. DB based Connection will have the connection details to connect to DB like host name, port, service name/SID, username, password, etc.
  • REST Connection - Can be related to an empty REST adapter created in SOA without any service or schema related details associated.
  • SOAP Connection - a SOAP/Webservice adapter in SOA with WSDL associated.
  • FTP Connection - Similar to FTP outbound connection pool created in SOA's weblogic server. This will contain FTP server's host address, port, username, password, security policy etc
  • Oracle ERP Cloud Connection - ERP Cloud adapter in SOA with ERP services catalog url, username and password defined.
Similarly, there are different other types of Connections which can be created.

2. Trigger and Invoke - These are the roles that can be assigned to a connection. Trigger role means that the Connection can be exposed as a "Service" in SOA terms and accept input like "Receive" activity. An Invoke role means that the Connection can be invoked as a "Reference" partner link in SOA and sent input through "Invoke" activity.

3. Integrations - These can be compared to "Composites" in SOA. Like each composite can be designed as Empty Composite, Composite with BPEL, etc, integrations also be designed as Basic Routing, App Driven Orchestration, Scheduled Orchestration, etc.

4. Packages - Packages are like Applications in SOA. All integrations in a package can be bundled together and moved to different environments.

5. Libraries - Unlike SOA where custom java classes can be written and imported into the component, OIC does not support Java libraries. OIC only supports Java Script libraries. You can write all your functions in java script, add them as a library and use in OIC integrations.

OIC is much more simpler product than SOA in terms of the richness of components.
OIC is can be used in scenarios where you want to do simple integrations with services or APIs already present in cloud or on-premise. Where message size is not too huge and there is not lot of orchestration needed.