Part 3: Itineraries with Orchestrations
Why do you need Orchestrations in Itineraries?
1. If you have a custom logic that can only be executed in an orchestration (you can also use custom pipeline components though) like correlation stuff.
2. If you use multiple resolvers. In this case, we need a mechanism to loop through the resolvers and find out what is in there.
Here is my example:
1. Receive a message “Msg1”
2. Call orchestration1 with a transform resolver & route resolver. Orchestration will transform Msg1 -> Msg2 using transform resolver and routes the Msg2 to a folder using route resolver.
Rcv -> Orchestration1 Trasnform & Route -> Send
2. Create Maps to be used in Orchestration, between Msg1 -> Msg2. Deploy these maps so that they are visible in Itinerary designer.
3. Create Orchestration1 which receives Msg1. Add Receive shape to receive Msg1 using Direct binding and use the filters as shown below.
4. Add reference to the following schemas and create a filter as below.
6. Sign the assembly and build it & GAC it. We will update the orchestration after completing the Itinerary.
7. Open ESB.Config file which in the ESB Toolkit installation folder and add two configurations as below under “ItineraryServices”
<itineraryService id=”7A5CFD7D-A571-4170-ABC9-5D8679CAD3B5″ name=”MyOrchestration1″ type=”Itineraries.Orchestrations.Orchestration1, Itineraries.Orchestrations, Version=22.214.171.124, Culture=neutral, PublicKeyToken=08cc287fde27369a” scope=”Orchestration” stage=”None” />
8. Create an Itinerary -> New OnRamp (if you are new to Itineraries, see my previous posts on how to use this)
a. Set Model Exporter to Database
b. Remove Encryption
c. Point the OnRamp to a One Way Receive Location -> Pointing to some In Folder.
9. Add an Itinerary Service, change the extender to orchestration extender.
10. Under Service Name -> Select Orchestration 1 which we just added in esb config. Rename ItineraryService1 to Orchestration1
11. Add two STATIC resolvers to the Orchestration1 (if you are new to Itineraries, see my previous posts on how to do this). One resolver will be a transform resolver pointing to Map1 and other Resolver will be a static resolver which provides routing information (Some Msg1 Folder)
12. Join the two components & Deploy the Itinearary.
13. Now open Orchestration1 and complete the rest of the parts. Here is what we are going to do
a. Access the Current Step in the Itinerary
b. Access the resolvers.
c. Get the Map Name, Execute Transform
d. Get the Routing Details and update the messages’s outbound transport details.
e. Send the message via a dynamic & direct send port.
14. Create two variables for Itinerary & Itinerary Step of types Microsoft.Practices.ESB.Itinerary.SerializableItineraryWrapper & Microsoft.Practices.ESB.Itinerary.SerializableItineraryStepWrapper
15. Add an expression shape with the below code to get the current Itinerary & Itinerary Step
Itinerary.Itinerary = Microsoft.Practices.ESB.Itinerary.ItineraryOMFactory.Create(Msg1);
ItineraryStep.ItineraryStep = Itinerary.Itinerary.GetItineraryStep(Msg1);
16. Get the Current Resolver. Create variables as below.
ResolverCollection = Microsoft.Practices.ESB.Itinerary.ResolverCollection
ResolverDictionaryString = System.String
17. Add the below code in an expression shape. Additionally you can add debug statements.
ResolverCollection = ItineraryStep.ItineraryStep.ResolverCollection;
ResolverDictionaryString = ResolverCollection.Current;
Now if you watch the values of Debug Statements in Debug view, we can see that this step has two resolvers as configured in Itinerary. Resolver value contains the map like – “STATIC:\\transportType=;transportLocation=;action=;endpointConfig=;jaxRpcResponse=false;messageExchangePattern=;targetNamespace=;transformType=Itineraries.SampleMap.Map1,Itineraries.SampleMap, Version=126.96.36.199, Culture=neutral, PublicKeyToken=71718544606bd247;”
18. We can parse the Resolver String by ourselves or make us of Resolver manager in Microsoft.Practices.ESB.Resolver.dll . Add a reference to Microsoft.Practices.ESB.Resolver.dll and parse the Resolver string as a dictionary as below.
19. Create a variable of type ResolverDictionary (Microsoft.Practices.ESB.Resolver.ResolverDictionary) and add the below code.
ResolverDictionary = Microsoft.Practices.ESB.Resolver.ResolverMgr.Resolve(Msg1, ResolverDictionaryString);
20. Now we have the resolver. So get the map name using the code
21. Now we can execute the map by getting the type name as shown in the linkor use the Microsoft.Practices.ESB.Transform. Dll. So add a reference to Microsoft.Practices.ESB.Transform. Dll and use the below code to execute the map.
XMLDocument = Msg1;
ResponseString = Microsoft.Practices.ESB.Transform.MapHelper.TransformMessage(XMLDocument.OuterXml,mapName);
22. Convert the ResponseString to Msg2 and copy the context properties.
Msg2 = XMLDocument;
Msg2(*) = Msg1(*);
23. Now we need to route Msg2 using the Resolver Details provided in Itinerary. For that we need to load the 2nd Resolver.
ResolverDictionaryString = ResolverCollection.Current;
System.Diagnostics.Debug.WriteLine(“SecondResolver: ” + ResolverDictionaryString);
ResolverDictionary = Microsoft.Practices.ESB.Resolver.ResolverMgr.Resolve(Msg2, ResolverDictionaryString);
24. Create a one way dynamic send port. Now using the second resolver, get the Transport URL and assign it to a dynamic Send Port.
Port_2(Microsoft.XLANGs.BaseTypes.Address) = ResolverDictionary.Item(“Resolver.TransportLocation”);
Port_2(Microsoft.XLANGs.BaseTypes.TransportType) = ResolverDictionary.Item(“Resolver.TransportType”);
26. Deploy & Test. Message should have transformed and routed to the folder that you specified in the Itinerary Static Resolver of the Orchestration Component.
27 If you would the output of first orchestration to pass to second orchestration – then create Orchestration2 like Orchestration1 with same type of filters in the Receive Port. Update the Itinerary to include Second Orchestration after the first one.
28. Update the Orchestration, to create a new message and call the “Advance” step to promote the values of new Service into the message. Below is the code for that.
Msg3 = Msg2;
Msg3(*) = Msg2(*);
29. Use Direct Binding Send Port which will publish the message to Msg Box with appropriate service name of the next step in Itinerary (Orchestration2 here). This message will then be picked up Orchestration2. Completed orchestration will be like below.
30. However, these ServiceName, State & Type are not promoted. You can use correlation in the send port to promote them.
Hope this gives you a good idea.
No comments yet.