Powered By Blogger

Tuesday, December 16, 2014

MQ Correlation Through Orchestration In Biztalk(Without Using MQSeries Adapter)

Hi there ,

In this post I'm going to explain in detail about how to push and retrieve message from IBM websphere MQ through orchestration in biztalk. To begin with, ensure that you have IBM websphere mq installed and configured in your system properly.

The Process:

The below screenshot depicts the overall process



1. Create any schema you like. I have created the following schema as depicted in the figure below.


2 . Add orchestration to your project. Create one receive shape of message type = your schema and bind it to logical receive port.


3. Drop one scope shape and make transaction type property of that scope to atomic.Inside the scope, place one assignments shape.


4. Add amqmdnet.dll file as a reference to your project. The file can be found at default installation directory : C:\Program Files (x86)\IBM\WebSphere MQ\bin

5. Create following variables under the above created scope.

a. quemgr - type: IBM.WMQ.MQQueueManager 
b. ReqMsg - type: IBM.WMQ.MQMessage
c. RespMsg - type: IBM.WMQ.MQMessage
d. rqstqueue - type: IBM.WMQ.MQQueue   
e. respqueue - type: IBM.WMQ.MQQueue
f. gmo-            type: IBM.WMQ.MQGetMessageOptions

6. I have written the following lines of code to push and retrieve the msg with same           correlationID from MQ.


7. I'll be explaining this code block by block from request message creation to response message    creation . Our primary aim is to push and retrieve the message from queue based on correlationID.
Create one variable of type System.xml.xmldocument. This variable will hold the values arriving from receive shape.

8. Now we will be generating guid for our request message.correlationID . I tried creating the guid in the expression shape but since XLang doesn't support byte [] array , i was compelled to make one class library for creating guid and using it to assign it to request message correlationID.

9. Add one C# Class library project in the same solution. Name it : GUIDCLASSLib and the class as ClassGuid.

10. Add the following lines of code as shown below:



11. Build the project and add the class library reference to your project. Also register the dll file in    gac through gacutil /i [dll name] command.

12. Now switch back to message assignment shape and assign the values retrieved from receive message shape to the xml variable : Variable_XML= Message_Rcv.

13. Copy the following code with values that of your environment.

IBM.WMQ.MQEnvironment.Hostname = "your host name";
IBM.WMQ.MQEnvironment.Port = your port [int]; //ex: 7714
IBM.WMQ.MQEnvironment.Channel = "your channel name"; //ex: APP.ALL

quemgr = new IBM.WMQ.MQQueueManager("Queue Manager Name"); //ex:SDCQMGR.T1

rqstqueue = quemgr.AccessQueue("Your_ request queue name",IBM.WMQ.MQC.MQOO_OUTPUT + IBM.WMQ.MQC.MQOO_FAIL_IF_QUIESCING);

respqueue = quemgr.AccessQueue("Your_ response queue naem",IBM.WMQ.MQC.MQOO_INPUT_AS_Q_DEF + IBM.WMQ.MQC.MQOO_FAIL_IF_QUIESCING);


The MQEnvironment sets the environment variables to the given values. MQQueueManager manages all the queues and channels which reside under it . rqstqueue variable is the instance of IBM.WMQ.MQQueue type which will act as a Request queue. Similarly, respqueue is of type MQQueue and will act as response queue.

14.Now we will be creating instance of MQMessage, One request message and response message respectively. First we will be instantiating ReqMsg variable.

ReqMsg = new IBM.WMQ.MQMessage();

15. Copy the following code for setting the property of request message. This request message carries the content of xml file which we are receiving at receive shape.

ReqMsg.WriteString(Variable_XML.OuterXml); \\the original message.
ReqMsg.Format = IBM.WMQ.MQC.MQFMT_STRING;
ReqMsg.MessageType =IBM.WMQ.MQC.MQMT_REQUEST;
ReqMsg.Report = IBM.WMQ.MQC.MQMO_MATCH_CORREL_ID;
ReqMsg.ReplyToQueueName = "FOCiS.TO.EIL";
ReqMsg.ReplyToQueueManagerName = "SDCQMGR.T1";
Variable_obj = new GUIDCLASSLib.ClassGuid(); \\ create variable Variable_obj of type GUIDCLASSLib.ClassGuid()..

ReqMsg.CorrelationId = Variable_obj.returnguid(); \\assigning the guid to correlationId

16. Now put ReqMsg into rqstqueue :

              RequestQueue.Put(ReqMsg);

17. Log the request message.

        System.Diagnostics.EventLog.WriteEntry("RequestQueueMsg",ReqMsg.ToString());
18. Similarly instantiate the response message variable RespMsg .

RespMsg = new IBM.WMQ.MQMessage();
RespMsg.MessageType = IBM.WMQ.MQC.MQMT_REPLY;
RespMsg.CorrelationId = ReqMsg.CorrelationId;

19. Also add the following lines of codes for GetMessageOptions.

gmo = new IBM.WMQ.MQGetMessageOptions();
gmo.Options = IBM.WMQ.MQC.MQGMO_WAIT;
gmo.WaitInterval = 5000;
gmo.MatchOptions = IBM.WMQ.MQC.MQMO_MATCH_CORREL_ID;

20. Now get the response message by passing RespMsg and gmo as parameters to ResponseQueue.Get() method.

ResponseQueue.Get(RespMsg, gmo);

21. Log the response message:
 
     System.Diagnostics.EventLog.WriteEntry("ResponseMessage",RespMsg.ReadString(RespMsg.MessageLength));

22. Sign and build the project and deploy it to Othe BTS. You can also create one send port to send the response message to the disk. After deployment configure the application with one receive port and location . Drop the generated instance into the the receive location and check your event log.
That's all, your job is done.

I tried explaining the subject in the best possible manner I could. Your doubts and suggestions would be whemingly responded.

Hope you all had a good read. Happy blogging and reading :) .

Thank You.

Saurav Suman
Software Engineer @ Agility
Hyderabad,India.



Thursday, October 9, 2014

Parallel Convoy Correlation In BTS

Hi there,


In this blog , i'll show you how parallel convoy correlation works in biztalk by showing a pracical example.A parallel convoy enables multiple single messages to join together to achieve a required result.The set of related messages can arrive in any order, but BizTalk Server must receive all of them before starting the process.

Scenario:

Suppose you go to a shopping site and you decide to buy an item, your item will not be booked unless and until the system receives the payment confirmation as well as the stock availability.
We will be creating two schemas here, one for the payment and other for the stock availability with one common field element Status so that we are able to correlate these two schemas.

Steps

1.Create one schema for payment information



2.Create one schema for stock availability



3.Promote the Status element of both the schemas. (Do Quick Promotion)

4.Add an orchestration process to your project.

5.Perform the following steps in orchestration.

 a)Drag and drop a parallel action shape.

 


 b)Take two receive shape



 c)Now go to the orchestration view and expand types. Right click correlation types and add new            correlation type. Update the correlation property as shown in the figure below as well as the
   description,identifier.


 d)Similary add a new correlation set as shown in the figure.



 e)Rename one receive shape to Receive_Payment and set the following properties:

    Activate = true; Initializing Correlation Set=Name of Correlation Set; Message and operation.

 f)Rename the other receive shape to Receive_StockInfo and set the following properties:

    Activate = true; Initializing Correlation Set=Name of Correlation Set; Message and operation.

 g)Make a final destination schema as shown below



 h)Drop a transform shape in your orchestration process and update it as shown below,make         destination your final send shape.



 i)Link the source schema and destination schema as shown below


 
 j)Finally drop a send shape with message type = your destination schema

 f) Your whole business process should look like this:



6.Sign your project and deploy it to biztalk admin console

7.Configure your send, receive port and orchestration accordingly in administrative console.


Do leave your comments if you face any problem.

Happy blogging!!

Saurav Suman
Software Engineer @  Agility

Wednesday, October 8, 2014

Renaming Your Biztalk Machine Without Loosing Data

Hi there,

I recently came across a situation where i had to change my machine name.You all may be wondering about the big stuff in that but let me tell you that it turned out to be a big headache for me when i had to reconfigure my biztalk again as i had to preserve my old data.I followed the following steps which helped me to get my biztalk running back....

Note: Do this on your own risk, it worked for me but i'm sure if you follow the steps carefully it would work for you too.


Steps to configure your biztalk incase of machine name change

1. Add your current domain as member to each biztalk group by going to the computer management.

   Administrators,BizTalk Application Users,BizTalk Isolated Host Users,BizTalk Server  Administrators,BizTalk Server B2B Operators,BizTalk Server Operators,SSO Administrators(Very  Important).

2. Navigate to  your installation directory and search for SampleUpdateInfo.xml file.
   You can find SampleUpdateInfo file in Microsoft  Biztalk Server 2013\Bins32\Schema\Restore           folder.

3. Edit SampleUpdateInfo file like this:-
 
   Find and Replace all the “SourceServer” value with your original Server name.
   Find and Replace all the “DestinationServer” value with your new Server name.
   Stuff related to Analysis, BAM, RuleEngine, HWS, and EDI are commented by default, if you are      using them in your environment un-comment the required ones.

   save and close the file after editing.

4. Open Command prompt and change the directory to following location :
    D:\Installation\Microsoft  Biztalk Server 2013\Bins32\Schema\Restore

  (You would have your biztalk installed in different drive but the script files reside under                     \bins32\schema\Restore folder)

5.After changing the directory, run the following command to update the biztalk database:-

   cscript UpdateDatabase.vbs SampleUpdateInfo.xml

 //Make sure that the management database,messagebox db and rule engine db gets updated.

 Again run the following command for updating the registry:-

   cscript UpdateRegistry.vbs SampleUpdateInfo.xml

 //This script will update the local registry with the correct server name. You need to run this script on each BizTalk server you have    in the group.

6.Restart the WMI service by going to services.msc
 
  //This step is required because most of the administration tasks you perform from the admin console depends on WMI.

7.Promote the new server as master secret server:
  Follow these steps :-

A) On the Start menu, click All Programs, click Microsoft Enterprise Single Sign-On, and then click SSO Administration.

B) In the scope pane, right click System, and then click Properties. The Master secret server is displayed on the General tab of the System    Properties dialog box.

C) Click Change to select a new Master secret server.

D) Logon to the new Master secret server to restore the Master secret to the registry of the new Master secret server.

E) On the Start menu, click Run, and then type cmd.

F) At the command line prompt, go to the Enterprise Single Sign-On installation directory. The default installation directory is
   :\Program Files\Common Files\Enterprise Single Sign-On.

G) Restart the new Master Secret Server.

H) Type ssoconfig –restoreSecret , where is the path and name of the file where the master secret is stored.
   The master secret is stored in the registry at the following location:
   HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\ENTSSO\SSOSS

8.Restart your machine.

9.Open Sql Server Management Studio and logon using windows authentication

  Check the following table and column name under BizTalkMgmtDb for new server name, if the column still has the old server name then update that with the new server name:-

   adm_group table, SSOServerName
   adm_server table, Name column
   adm_MessageBox, DBServerName

10. Restart all the BizTalk/SSO services.

11.Open the BizTalk administration console, click on the existing node (the one pointing to original server), right-click and remove.
 Right click on the “BizTalk Server 2006 Administration” node and select “Connect to Existing      Group…”. Provide the new Server Name and select the BizTalkMgmtDb database.

Click Ok.You will get all your application. Incase the host instance is unable to start, try reconfiguring it with your btsadmin credentials.

12. Restart your system again and try running any working application.If you are able to run your application then your setup was a success otherwise you need to look into the the error and try resolving those errors by yourself.







Sunday, August 31, 2014

Creating a flat file schema through a wizard in biztalk


Hi there,



It has been a way long since I wrote my last blog. These days i'm working on a new technology named biztalk which according to me has so far been an interesting endeavour in my tryst with biztalk programing :P . Biztalk is one of the widely used integration tool available in the market which supports extensive B2B & EAI integration developed by microsoft. But I'm not writing this blog to explain what biztalk is and what it does. Here is the link to the brief introduction of biztalk --msdn- BizTalk Introduction .
Rather, i'm here to share the inbuilt capabilities of biztalk artifacts which form the backbone of biztalk runtime architecture i.e adapters,pipelines,orchestration,schemas and maps . It would be impossible for me to briefly introduce all the artifacts in a blog and therefore i decided to go with oneartifact/blog :) ....

Schema is one of the important part of biztalk architecture which i will be discussing here. Basically, a schema is something which creates the structure of a file and that file could be anything ranging from xml to flat files.The extension for schemas in biztalk or any other tool is .xsd (XML Schema Definition). The work of schemas is to define the structure of the message it receives, based on which we can create an instance of the generated xsd file into the format we want. Biztalk supports following type  schemas : -

1.XML schema
2.Flat file schema
3.Envelope schema
4.Property schema

For a biztalk beginner, XML schema and Flat file schema should be of concern so as to grasp the logic behind these two schemas so that we meet with minimum problems while facing complex types of schemas.
I will start with flat file schema and in this whole process would be dicussing in brief flat file schemas.
A flat file is a file which consists of records with no structured relationship and stored data in a plain text file.
Flat file are of two types:-

1. Delimited flat files - Example - 1,Saurav,SoftwareEngineer,sauravsuman007@gmail.com

---  In delimited flat file schema the elements of a record are identified after a delimiter like (,) etc.

2. Positional flat files - Example - 1 Saurav SoftwareEngineer sauravsuman007@gmail.com

--- In positional flat file schema the elements of a record are separated by space and are of fixed length

Creating Flat File Schema through a Wizard :

1. Create a BizTalk project by navigating as shown in the figure




2. Select Empty Biztalk Project under biztalk templates



3. Now open notepad and type the following as shown below


After creating the notepad file, save it with appropriate file name of your choice 

4. Now switch back to visual studio and do the following:-  right click on project ----->add---->new item




5. On add new item dialog, select flat file schema wizard as shown below 



6. On the consecutive page give the path of your instance file name which you created in notepad and name the record name as EMP and click next




7. The next will show you all the record, select only one line of record as shown below. Do not check wrap long lines. 



8. On the next page select delimiter type as your file is a delimiter type.




9.  Proceed further by clicking the next button without modifying anything



10. Select record in element type and click next



11. Keep clicking the next button until you meet up with the screen shown below. Select (,) as child delimtier type and the proceed further by clicking the next button.


12. Proceed further and finish the wizard process. Now open properties of your falatfile schema and browse the file you want to five to give to your input instance filename. Similarly repeat the step for output instance filename.




13. Now validate your schema by right clicking on you schema file and selecting validate schema





14. After valdating schema repeat the step for validating instance. If validation is successful then a xml file instance would be created on the specified output instance file name path. Open your instance by holding the ctrl key and pointing to the path name showm in the output





15. You will find your xml output but this shows only one record.




16. For all records to show do the following as shown below




17. Your final output





 For beginners, it is strongly recommended to first make your schema using the wizard and then try making it manually wherein if in case you get stuck in the process you can quickly switch back to the properties window of schema made through the wizard.

 I hope it was a good read and  look forward to your queries and feedback.

Happy Blogging!!

Saurav Ambastha
Software Engineer @ Agility