Thursday 25 October 2018

Remove Duplicate Values from Array AND Sort the Dates in Ascending Order in ESQL

1.To Remove Duplicate Values from Array


declare tableref ROW;

create field tableref.{}

for ref AS environment.Variables.Message[] DO
declare temp char ref.Value;
create field tableref.{temp};
END FOR;

OR


DECLARE i,j INTEGER 1;

        DECLARE     lastvalue ROW;

        FOR  Finalref AS Environment.Variables.Response.ADACODE[] DO
             DECLARE flref REFERENCE TO Finalref;
             SET Environment.ingh[i].value[] =  SELECT f.AdaCd FROM  
             lastvalue.ADACODE[] as f WHERE f.AdaCd = FIELDVALUE(Finalref.AdaCd);

             IF  NOT EXISTS(Environment.ingh[i].value[]) THEN
                        SET lastvalue.ADACODE[j].AdaCd = Finalref.AdaCd;
                        SET j = j+1;
             END IF;
             SET i = i+1;
       END FOR;

2.Sort the Dates in Acending Order in ESQL
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:output method="xml" omit-xml-declaration="yes"/>
  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>  
  <xsl:template match="*[local-name()='DepartureDatesSorting']">
      <DepartureDatesSorting>
            <xsl:apply-templates select="*[local-name()='Item']" >                        
                <xsl:sort select="translate(EventDetails/Departure/EventDate,'-','')" data-type="number" order="ascending"/>
            </xsl:apply-templates>
      </DepartureDatesSorting>
      </xsl:template>
</xsl:stylesheet>

-- Sorting number


DECLARE Count INTEGER 1;
DECLARE rInputRef REFERENCE TO InputRoot.XMLNSC.Member.Name[1];
WHILE  LASTMOVE(rInputRef) DO
SET Environment.Variables.Array[Count] = rInputRef.Age;
SET Count = Count + 1;
MOVE rInputRef NEXTSIBLING REPEAT TYPE NAME;
END WHILE;

DECLARE totalElements INTEGER CARDINALITY(Environment.Variables.Array[]);
DECLARE i INTEGER 0;
WHILE i < totalElements-1 DO
SET i = i + 1;
DECLARE j INTEGER 0;
WHILE j <= totalElements-i-1  DO
SET j = j + 1;
IF (Environment.Variables.Array[j] >  Environment.Variables.Array[j+1]) THEN
DECLARE temp INTEGER;
SET temp = Environment.Variables.Array[j];
SET Environment.Variables.Array[j] = Environment.Variables.Array[j+1];
SET Environment.Variables.Array[j+1] = temp;
END IF;

END WHILE;


END WHILE;

--Sorting Dates

 DECLARE Count INTEGER 1;
DECLARE rInputRef REFERENCE TO InputRoot.XMLNSC.Member.Name[1];
  --Storing Input message dates to Environment Variable
WHILE  LASTMOVE(rInputRef) DO
  SET Environment.Variables.Date[Count] = rInputRef.Age;
  SET Count = Count + 1;
  MOVE rInputRef NEXTSIBLING REPEAT TYPE NAME;
END WHILE;

--Logic to sort the dates using bubble sort
  DECLARE totalElements INTEGER CARDINALITY(Environment.Variables.Date[]);
  DECLARE i INTEGER 0;
  DECLARE pattern CHARACTER 'dd-MM-yyyy';
  DECLARE dFirstDate,dSecondDate DATE;
  WHILE i < totalElements-1 DO
  SET i = i + 1;
  DECLARE j INTEGER 0;
  WHILE j <= totalElements-i-1  DO
    SET j = j + 1;
DECLARE Date1 CHARACTER Environment.Variables.Date[j];
DECLARE Date2 CHARACTER Environment.Variables.Date[j+1];
--Converting to Date Format
SET dFirstDate = CAST(Date1 AS DATE FORMAT pattern);
SET dSecondDate = CAST(Date2 AS DATE FORMAT pattern);
--If First Date is Greater then Second date Swap the dates
  IF dFirstDate  > dSecondDate THEN
   DECLARE temp CHARACTER;
   SET temp = Environment.Variables.Date[j];
   SET Environment.Variables.Date[j] = Environment.Variables.Date[j+1];
   SET Environment.Variables.Date[j+1] = temp;
    END IF;
  END WHILE;
  END WHILE;

    SET OutputRoot.XMLNSC.SortedDates.Dates = Environment.Variables;






Friday 1 June 2018

IBM Integration Bus Interview questions Basics for 2-4 years Experience


1. One bar file is not getting deployed into exe group. What can be the reason? Give 2 reasons.


          Ans: The Execution group may be in stopped state or the Bar file may contains 
          some compile time errors.

2. If one flow has to be called more than once. What to do?
      Ans: We have two ways
a. We can use timer node 
b. In version 10 we have Callable flow through that also we can call

3. What is domain?
Ans: 
Domain : Grouping of Brokers.
Broker Domain : Group of brokers under a single configuration manager constitute a Broker Domain.


4. What are the logical trees in Message Broker?.
Ans : The logical tree structure is the internal (broker) representation of a message. It is also known as the message assembly.

• Message tree 
• Environment tree 
• Local environment 
• Exception list tree 

5. What are the methods of doing transformation in broker?
• Extended Structured Query Language (ESQL) 
• Graphical mapping node 
• JavaCompute node 

6. Which nodes can be used to write ESQL?
• Compute node
• Database node
• DatabaseInput node
• Filter node


7. What is the use of  Local Environment?
Ans: 
-We will use local environment tree to override the properties of node
-If you want to call webservice or want to put message in queue or file  
  dynamically then we will use LocalEnvironment variable
-Remember the life time of this Variable is at node level it will be not available 
 throughout the flow.
-If message fails due some reason in flow the LocalEnv will lost.
-If we are using this variable in compute node then we need to set the Compute
 mode property in compute node as Message and LocalEnvironment 

8. How Aggregate, XSLT, Passthrough, Route To Label, Flow order node work?
 Ans:     
Aggregate: Aggregation is the generation and fan-out of related requests 
Means if you want to send same request for one or more backends parallel then we will go with Aggregate nodes.
           
XSLT: (Extensible StyleSheet Language)  the XSLTransform node to transform an XML message to another form of message, according to the rules provided by an XSL (Extensible Stylesheet Language) style sheet, and to set the Message domain, Message set, Message type, and Message format for the generated message.
Here we should provide the "stylesheet name".

Passthrough: Use the Passthrough node to enable version control of a subflow at run time.
Use the Passthrough node to add a label to your message flow or subflow. By combining this label with keyword replacement from your version control system, you can identify which version of a subflow is included in a deployed message flow. You can use this label for your own purposes.
The Passthrough node does not process the message in any way. The message that it propagates on its Out terminal is the same message that it received on its In terminal.
It has 1 In and 1 out terminal.

Route To Label: To send the  message dynamically based on its contents we will use this node, basically it route a message to particular Label.
We need to provide Label Name in LocalEnvironment in compute node.
                   Or
            It is just used to route the message to the specified Label name.

Flow Order: Basically we use this node to send the message in order Ex: the message will propagate to first terminal the message will not come to second terminal until the first one gets ended, if any errors occurred at first terminal then message will not come to second terminal.
It has Three terminal(Failure,First,Second)

9. What is the difference between HTTP and SOAP node?
Ans:          
 - HTTP nodes handle the HTTP protocol.
            - SOAP nodes handle SOAP messages.
 - We can use SOAP nodes with  SOAP message domain OR HTTP   transport  
   nodes with XMLNSC message domain to implement Web Services
Several advantages exist if we use SOAP nodes :

· Support for WS-Addressing, WS-Security and SOAP headers.
· A common SOAP logical tree format, independent of the bitstream format.
· Runtime checking against WSDL.
· Automatic processing of SOAP with Attachments (SwA). 
· Automatic processing of Message Transmission Optimization Mechanism   (MTOM).

Cases where it might be better to use HTTP nodes include:

· Message flows that interact with Web services that use different standards, such as REST or XML-RPC. (We don't have a WSDL definition)
· Message flow that never use WS-Addressing, WS-Security, SwA, or MTOM.


10. What is filter node? How many terminal it has  and why are used? When are unknown terminals used?
FilterNode: Filter node to route a message according to message content. You define the route by coding the filter expression in ESQL.

4 Terminals: In,True,False,Unknown.
 Unknown: IF none of the conditions satisfied in Filter node if conditions
Or if we have not written any RETURN statement in ESQL then will route to Unknown.
.
Ex: If value is a>50 true and a<50 False is set in the  code. If a=50, which terminal the message will go, False or unknown?
Ans: It goes to Unknown termi
11. How CWF is working? How TDS is working?

CWF :
Custom Wire Format (CWF) is the physical representation of a message that is composed of a number of fixed-format data structures or elements, which are not separated by delimiters.
MRM(Message Repository Manager ) TDS format:
The Tagged/Delimited String format (TDS) is the physical representation of a message that has a number of data elements separated by tags and delimiters.
The TDS physical format is designed to model messages that consist of text strings, but it can also handle binary data. The TDS physical format allows a high degree of flexibility when defining message formats, and is not restricted to modeling specific industry standards; therefore, you can use the TDS format to model your own messages.

12. ls it possible to create a message set from XSD?

Ans: Yes, You can use a Quick Start wizard to create a message set, a message set project, and other resource files that you need to create a new application using XML documents (general) for that you have to convert xsd to xml.

13. What is point to point and pub/sub? 
Ans : Publish/Subscribe
Publish/subscribe is a style of messaging application in which the providers of information (publishers) have no direct link to specific consumers of that information (subscribers), but the interactions between publishers and subscribers are controlled by pub/sub brokers.


14. What is the method of giving default values instead of using COALESCE for each field?
Ans: we can use UDP

15.How to send more than 5 messages to different locations from compute node?
Ans: There are multiple ways.
a. we can use propagate by sending the queue names dynamically in LocalEnvironment in this case set the MQ property in advance Destintion mode as Destination List.
b. Can use Route node we can add N number of out terminal for this node and we can send to multiple destination.
c. We can use Label nodes as well.

16. How to access local environment in next node?
Ans: Use SET Var = InputLocalEnvironment.Destination….;



17. What are the functionalities of WMB?
· Route messages to one or more of many destinations
· Transform messages to an alternative representation
·Perform message aggregation, decomposing messages into multiple messages and  
 sending them to their destination, then recomposing the responses into one  
 message to return to the user
· Interact with an external repository to augment a message or store it
· Invoke Web services to retrieve data
· Respond to events or errors
· Provide content and topic-based message routing using the publish–subscribe         pattern



18. What is the need for config Manager?
 Ans : To Connect to the remote broker or local broker and to deploy the message flows Into the Broker.

19. How to check a broker is running or not?
    Ans : by using  mqsilist  -a which shows the currently running brokers.

20. If execution group is hanging, what is the first step to do?
Ans: It normally means you have a message flow that is badly written and has gone into a wait state (probably for an external resource). Or the flow has called some Java code that does its own thing. 

You can force it to stop with mqsistop -i <brokername> 

That will stop the entire broker. Look at the flows and correct them, make sure all external calls have a timeout specified (NB this includes data sources in ODBC).

21. What are the commands to deploy flows and other files?
Ans:You can deploy from the command line by using the mqsideploy command. 

22. Which all files can be deployed in broker?
  Ans: message sets, maps , ESQL files, subflows.
23. Where the deployment errors are being logged?
a. Activity Log
b. Standart error log
c. Logging in flow
d. Trace node
e. Monitoring events
f. Log4j
g. FileOutputNode
h. Database logging
i. Logging into Queue




Thursday 31 May 2018

Sample Java compute node(JCN) code for beginners

Hi Folks,

I'm posting this post for only freshers on IIB, who are going to use JCN node for first time.

1.First will look how to extract the values from InputTree and will create Output tree for the same.
2.Iterating message in loop.
3.Creating message tree with different parser.
4.Configuring and connecting DB from JCN.

Ex:
1.1.First will look how to extract the values from InputTree and will create Output tree for the same.

Input Mesage :

<Employee>
<Name>Venkat</Name>
<LName>Rathod</LName>
<Company>Cognizant</Company>
<Designation>TeamLead</Designation>
</Employee>

Expected output:

<Response>
<EmployeeDetails>
<EmployeName>Venkat</EmployeName>
<EmployeeLatName>Rathod</EmployeeLatName>
<EmployeComapny>Cognizant</EmployeComapny>
<EmployeDesignation>TeamLead</EmployeDesignation>
</EmployeeDetails>
</Response>

Code :

Steps:
1. use the Default code which IIB provide when you Initially open JCN node.
2.will add our code in the below block
          // Add user code below
 --Here we add our code
           // End of user code
3. Source Code.

import com.ibm.broker.javacompute.MbJavaComputeNode;
import com.ibm.broker.plugin.MbElement;
import com.ibm.broker.plugin.MbException;
import com.ibm.broker.plugin.MbMessage;
import com.ibm.broker.plugin.MbMessageAssembly;
import com.ibm.broker.plugin.MbOutputTerminal;
import com.ibm.broker.plugin.MbUserException;
import com.ibm.broker.plugin.MbXMLNSC;


public class POC1_MF_JavaCompute extends MbJavaComputeNode {

public void evaluate(MbMessageAssembly inAssembly) throws MbException {
MbOutputTerminal out = getOutputTerminal("out");
MbOutputTerminal alt = getOutputTerminal("alternate");

MbMessage inMessage = inAssembly.getMessage();
MbMessageAssembly outAssembly = null;
try {
// create new message as a copy of the input
MbMessage outMessage = new MbMessage(inMessage);
outAssembly = new MbMessageAssembly(inAssembly, outMessage);
// ----------------------------------------------------------
// Add user code below

-- First Get the values from Input Tree
MbElement oGetRootMessage = inAssembly.getMessage().getRootElement();

MbElement Name = oGetRootMessage.getFirstElementByPath("XMLNSC/Employee/Name");
MbElement Lname = oGetRootMessage.getFirstElementByPath("XMLNSC/Employee/LName");
MbElement Company = oGetRootMessage.getFirstElementByPath("XMLNSC/Employee/Company");
MbElement Desgination = oGetRootMessage.getFirstElementByPath("XMLNSC/Employee/Designation");

-- End Of First Get the values from Input Tree

--Create Output Root for the output message
MbElement oResponseRoot = outAssembly.getMessage().getRootElement().getLastChild();
MbElement oResponse = oResponseRoot.createElementAsLastChild(MbElement.TYPE_NAME, "Response",null );
MbElement oResponseDetails = oResponse.createElementAsLastChild(MbElement.TYPE_NAME, "EmployeeDetails",null );
-- End OF Create Output Root for the output message

--map the values to output root
MbElement EmpName = oResponseDetails.createElementAsLastChild(MbElement.TYPE_NAME_VALUE,"EmployeName",Name.getValue());
MbElement EmpLastName = oResponseDetails.createElementAsLastChild(MbElement.TYPE_NAME_VALUE,"EmployeeLatName",Lname.getValue().toString());
MbElement EmpComapnay = oResponseDetails.createElementAsLastChild(MbElement.TYPE_NAME_VALUE,"EmployeComapny",Company.getValue());
MbElement EmpDesignation = oResponseDetails.createElementAsLastChild(MbElement.TYPE_NAME_VALUE,"EmployeDesignation",Desgination.getValue());

-- End of Map the values to output root

oResponseRoot.getFirstChild().detach();
// End of user code
// ----------------------------------------------------------
} catch (MbException e) {
// Re-throw to allow Broker handling of MbException
throw e;
} catch (RuntimeException e) {
// Re-throw to allow Broker handling of RuntimeException
throw e;
} catch (Exception e) {
// Consider replacing Exception with type(s) thrown by user code
// Example handling ensures all exceptions are re-thrown to be handled in the flow
throw new MbUserException(this, "evaluate()", "", "", e.toString(),
null);
}
// The following should only be changed
// if not propagating message to the 'out' terminal
out.propagate(outAssembly);

}

}


ESQL date sorting logic : -

--Get all the dates from Inputmessage
DECLARE VesselDetailsRef REFERENCE TO InputRoot.JSON.Data.VesselSchedule.VesselDetails.PortDetails.Item[1];
CREATE LASTCHILD OF Environment DOMAIN('JSON')  NAME 'VesselDetails';
DECLARE i INTEGER 1;

WHILE LASTMOVE(VesselDetailsRef) DO
SET Environment.VesselDetails.PortDetails.Provider[i].datetimeBegin = VesselDetailsRef.EventDetails.EventDate;
SET Environment.VesselDetails.PortDetails.Provider[i].PortDetails = VesselDetailsRef;

MOVE VesselDetailsRef NEXTSIBLING REPEAT TYPE NAME;
SET i = i + 1;
END WHILE;


--Sort the date in Ascending Order
DECLARE rEnv REFERENCE TO Environment.VesselDetails.PortDetails;
SET rEnv.LastProvEffDate = rEnv.Provider[1].datetimeBegin;
DECLARE k INTEGER 1;
FOR rList AS rEnv.Provider[] DO
IF(rEnv.LastProvEffDate > rList.datetimeBegin) THEN
SET rEnv.TempProvider = rEnv.Provider[k-1];
SET rEnv.Provider[k-1] = rList;
SET rEnv.Provider[k] = rEnv.TempProvider ;
END IF;
SET rEnv.LastProvEffDate = rList.datetimeBegin;
SET k =k+1;
END FOR;
DELETE FIELD rEnv.TempProvider;


-- Search the next date where Unloading is happening

DECLARE rNextDate REFERENCE TO Environment.VesselDetails.PortDetails.Provider[1];
WHILE LASTMOVE(rNextDate) DO
DECLARE PortFunctionCode CHARACTER rNextDate.PortDetails.PortFunctionCode;

--Check the current Protcode is doing Loading
IF (PortFunctionCode ='L') THEN
--Taking Date where Loading is happening
DECLARE LoadDate DATE CAST(rNextDate.PortDetails.EventDetails.EventDate AS DATE);
DECLARE rNextDateFinder REFERENCE TO Environment.VesselDetails.PortDetails.Provider[1];

WHILE LASTMOVE(rNextDateFinder) DO
DECLARE NextDate DATE CAST(rNextDateFinder.PortDetails.EventDetails.EventDate AS DATE);
DECLARE cUnloadingFlag CHARACTER rNextDateFinder.PortDetails.PortFunctionCode;

IF (LoadDate < NextDate) AND (( cUnloadingFlag = 'I') OR ( cUnloadingFlag = 'D')) THEN
DECLARE BackEndCalls CHARACTER;
--Call a Backend
END IF;

MOVE rNextDateFinder NEXTSIBLING REPEAT TYPE NAME;
END WHILE;
END IF;
MOVE rNextDate NEXTSIBLING REPEAT TYPE NAME;

END WHILE;





Wednesday 30 May 2018

IIB Developer IBM Written Technical questions and answers


1.Default timeout for SOAP/HTTP request Node?
Ans : 120 Sec

2.For Input message the transaction mode is yes  and failure terminal is not connected to any of the nodes, what happens to message.?
Ans : The message will repeat until it reaches the maximum threshold of Backout Queue

3.In Filter node only RETURN statement is written then which terminal message will go?
Ans: Unknow Terminal

4.dfdl:assert annotation contains?
Ans :an xs:element reference, xs:group reference,xs:sequence,xs:choice.

5.In AIX system which command will use to create the bar file?
Ans : mqsicreatebar

6.one of the database password is Expired which command will you use to Reset the Password?
Ans : mqsisetdbparams

7.In MQ output node what are the Destination modes are available?
Ans : QueueName,ReplyToQueue,DestinationList

8.In application We dont have WSDL for soap input/Request node, is it possible to call webservice?
Ans : Yes, By using GatewayMode(Invoke a generic webservice)

9.In application we have SOAP input node and the WSDL is not exists in application, then it will show compile time error? True/False.
Ans : True

10. To Expose web service what we require?
Ans: WSDL

11.In what all nodes we can use ESQL?
Ans:ComputeNode,FilterNode,DataBase Input,Database.

12.How will we deploy the flow in stoped state.?
Ans: Manual (in bar file Mainflow  start mode should be manual)

13.From an application you sent the message to other application how do you get the exact message which you sent in First application?
Ans: CorrelationId

14.Why we will use TDS message?
Ans: To handle Delimited message.

15. How will you ensure that the Database operation code written in ESQL are executed perfectly?
Ans:By seeing ESQL Return values. or SQLCODE = 0

16.Opaque parsing is a performance feature that is offered by the XMLNSC domain
Ans: If you are designing a message flow and you know that certain elements in a message are never referenced by the message flow, you can specify that these elements are parsed opaquely. This reduces the costs of parsing and writing the message, and might improve performance in other parts of the message flow.

17, What is easiest way to add MQMD header in flow?
Ans: using MQHeader node.