Search This Blog

Tuesday, August 9, 2011

Biztalk interview questions 2004/2006/2010 Part :2



Biztalk interview questions :
Part 1

Part 3

Part 4

22. Is there a way to limit the number of active instances of a given orchestration?

BizTalk Server 2004 has no built-in mechanism for controlling the number of instances of a given orchestration. The BizTalk Server engine does its own throttling to maximize system throughput.
If you need to control the number of active instances because of external resource constraints (for example, availability of database connections), then the orchestration must does its own access control? Typically you do this by implementing a singleton or a fixed number of resource-controller orchestrations that dispense access to the resource.
Perhaps the simplest example of instance control is as follows: You want to control the number of instances of orchestration A that are doing work. Orchestration B is the singleton resource dispenser. On activation, A sends a request to B. B reads the request, determines if this new A can execute now, and returns a reply: yes or no. A reads the reply. If the reply is no, A delays for a period of time and then requests again. If the reply is yes, A executes. At completion, A sends another message to B telling B that it is finished.
As stated above, this is a simple example. In practice, you might need something more complex. More abstractly, you need to control the rate at which messages are activated to better match the rate that activated instances can complete their processing.

23. How can I share global variables across all instances of a given orchestration?
There is no easy way to share global variables across all instances of an orchestration. If the global variables are static values, you might consider storing them in a persistent storage, such as a configuration file or SQL database, and allowing each instance to get the values from storage. You can also share a static state in user code as long as locks are placed correctly on access and modification of the shared state.

24. Why is my orchestration instance suspended with the status of "Completed with Discarded Messages"?
"Completed with Discarded Messages" is one of the states an orchestration instance may end with. A message that is discarded in this way is called a "zombie" and typically occurs when an extra message is routed after control flow in the executing orchestration has passed the Receive shape with the matching subscription. This can be due to a time-out on a long-running transaction or a time-out of a Delay branch on a Listen shape. It can also occur in a loop that contains a Receive shape that exits before consuming all routed messages.
You can use a Windows Management Instrumentation (WMI) method to listen to the suspend events, find the message associated with the orchestration instance, and resubmit the message.

25. Many messages end up with the status of "Delivered Not Consumed" in HAT. Should I be concerned with them and where should I look?
A message is in the "Delivered Not Consumed" state when it is in the BizTalk Server internal work queue. It might be in this state because the engine is busy with other messages, or because the message destination is processing more slowly than expected.
You first need to determine where these messages are going: to the orchestration or to the send port. In HAT, you can figure this out by looking at what service the "delivered not consumed" references are associated with. Then you can check whether the destination orchestration or the send port is working correctly.

26. Why does the compiler require my variable to be serializable?

The XLANGs runtime may persist to the database (dehydrate) your orchestration, including all of its data, at any point (except in the atomic scope). When the orchestration dehydrates and rehydrates, user-defined variables are binary serialized and deserialized. In most cases, you need a serializable object. A non-serializable object can only be declared and used in an atomic scope. The XLANGs compiler gives you compilation errors if you try to use a non-serializable data type outside of an atomic scope.
Message definitions, whether with .NET types or with actual message types, require that the .NET types be XML serializable (for example, System.IntPtr cannot define a message), and that all the message parts (in the message type) be defined through either XML-serializable .NET types or schema types.

27. My object is serializable and implements an interface. When I try to access my object in an Expression shape of a non-atomic scope, the compiler complains that my object is non-serializable. Why?
Interfaces cannot be marked serializable, nor can you assume that they are serializable, because you never know how they are implemented. Therefore, XLANGs treats interfaces as non-serializable. Non-serializable objects must run inside atomic scopes. This is why interface-based programming must be done inside an atomic scope. In fact, in .NET, you cannot declare an interface to be serializable.

28. How does an orchestration invoke a COM/COM+ component?
XLANG generates C# code. All user-declared XLANGs variables are generated as C# variables. There is no special behavior except in the case of atomic transactions. When a serviced component (that is, an instance of a class that implements System.EnterpriseServices.ServicedComponent) is declared in an atomic scope, then and only then does XLANGs generate and use a real DTC COM+ transaction.
If a variable is referenced as an L-value (that is, it is written to) in the atomic scope, but is declared in an outer scope, the variable is cloned to support rollback. However, an object (such as an XmlDocument) can be modified inside a .NET function call when passed as an in-parameter, and thus XLANGs will miss that the object is being written to and it will not roll back correctly. The workaround in this case is to pass such objects as ref parameters.
The bottom line is that components should behave as they do in other C# programs.

29. Why doesn't my atomic transaction retry? How does the atomic transaction retry work?
An atomic transaction retries when a RetryTransactionException is deliberately thrown by the user or when a PersistenceException is raised at the time that the atomic transaction tries to commit. The latter could happen if, for example, your atomic transaction was part of a distributed DTC transaction and some other participant in that transaction aborted the transaction. Likewise if there were database connectivity problems at the time when the transaction was trying to commit, a PersistenceException would be raised.
There can be several root causes for PersistenceException, depending on the situation, but what you generally observe is that all the XLANGs actions in your atomic scope seem to go through correctly, but then instead of committing, the scope fails. If that happens for an atomic scope that has Retry=True, then the atomic scope will retry up to 21 times. The delay between each retry is two seconds by default (but you can modify that value). After 21 retries, if the transaction is still unable to commit, the whole orchestration instance gets suspended. Then you can manually resume it and it will start over, with a fresh counter, from the beginning of the offending atomic scope.
Note that only two exception types can cause an atomic scope to retry: RetryTransactionException and PersistenceException. Any other exception raised in your atomic scope cannot cause it to retry, even if you have the Retry property set to True. If you're having trouble trying to figure out why an atomic scope isn't retrying, double-check the exception type.
You can override the two-second default delay between consecutive retries by using a public property on RetryTransactionException (if that's the exception you're using to cause the retries).

30. Does orchestration support parallel activation?
Parallel-activating Receive shapes do work under the following conditions:
1. If one of the tasks of a parallel activation has an activatable Receive as the first shape, all of the tasks of that parallel activation must have an activatable Receive as the first shape, and all of those Receive shapes must initialize at least one correlation.
2. If a particular correlation is initialized on more than one task of a parallel activation by a Receive shape, each of the concerned activating Receive shapes must initialize exactly the same correlation.
This is the parallel convoy case. It is the only parallel activation that XLANGs supports.

31. Why do I sometimes get "could not find subscription error" when I send a message from the parent orchestration to the child orchestration, which was just started by the parent?
This is a race condition. Apparently you expect that the new orchestration will start in time to create the necessary subscriptions to receive the messages that will be sent to it. But you have no idea how long it will take to create the orchestration, because starting a new service is not a synchronous operation.
It would be better to have the newly created orchestration send a message back to its parent orchestration, reporting that it has started. Then have the new orchestration listen for its messages. In this scenario, the parent orchestration knows that there is a receiver for the messages before sending them. This also provides the necessary commit point to get the subscription to the MessageBox database.

32. How can I get context or other promoted properties from XLANGMessage?
In an Expression shape, you can use yourMessage(propertyName), for example, yourMessage(BTS.MessageID). However, if you want to access message properties from the XLANGMessage interface (for example, from user code), you would use the XLANGMessage methods SetPropertyValue and GetPropertyValue. You cannot use a context property for routing unless the property is in a correlation that is either initialized or followed in a Send shape.

33. I attach a dynamic send port to a logical port with Delivery Notification = Transmitted. However, the runtime does not seem to deliver any delivery notification. What is going on?
Dynamic ports are not designed to inherit all attributes and characteristics of the port whose address is assigned to the dynamic port. A dynamic port just gets an address, which is analogous to casting a void* pointer in C/C++ to a more structured pointer type. The pointer that initialized that address has had all its information stripped away. The XLANGs runtime only listens for delivery notification if the port is statically set up that way.

34. How can I perform dynamic transform in XLANGs?
You can use construct/transform code inside an Expression shape, to make it possible to assign the map dynamically. The code inside the Expression shape is similar to the following:
mapType = System.Type.GetType(mapName);construct Out_msg{ transform(Out_msg) = mapType(In_msg, In2_msg);}

36. I changed some message fields inside an Expression shape. However, when I send the message out, I do not see the updated values. Why?
In BizTalk Server, the messages are immutable. You can use a Construct shape to create a new message. Copy the original message to the new message and update the fields on the new message.

37. The orchestration calls a Web service with the SOAP send adapter and receives the response. When an exception occurs, the orchestration service is suspended with "Suspended (not resumable)". How can I retry the Send?
You can place the SOAP Send inside a scope with an exception handler and let the exception handler catch the resulting SoapException. Then you can retry the SOAP Send by nesting the scope inside a while loop.

38. What parameters control dehydration?
Three parameters control dehydration in BTSNTSvc.exe.config: MaxThreshold, MinThreshold, and ConstantThreshold. These work as follows:
MaxThreshold is the maximum time that a dehydratable orchestration is retained in memory before being dehydrated.
MinThreshold is the minimum time that a dehydratable orchestration is retained in memory before it is considered for dehydration.
Note
MaxThreshold and MinThreshold are upper and lower bounds for time-to-dehydration. The true time-to-dehydration fluctuates between the MinThreshold and MaxThreshold values. It takes into account both the history of how long it took that subscription to dehydrate in the past and stress/throttling
ConstantThreshold is used to attempt to ignore the throttling implication in deciding when to dehydrate. Changing this parameter is not recommended. -1 is the default value, and it tells the engine not to use a constant threshold.
History is used as follows in determining time-to-dehydration: Recycling the BizTalk service process resets the history. The history is kept parameterized by subscription; therefore, the history of a given Receive is independent of orchestration instance. The first time a subscription is seen, there is no history, so BizTalk Server chooses to dehydrate immediately. After the first dehydration, BizTalk Server uses the history.
The default for MaxThreshold is 30 minutes and the default for MinThreshold is one second. The default dehydration threshold is 30 minutes. With resource pressure this scales down to as little as MinThreshold. When a Receive blocks, BizTalk Server looks up past blocking times of this Receive for every instance of this orchestration and creates an estimate of how long it will take to receive a message to unblock. If this estimate is greater than the dehydration threshold, then BizTalk Server dehydrates. The first time through the loop with a single instance, there is no history so BizTalk Server dehydrates immediately.
BizTalk Server 2004 and BizTalk Server 2006 differ as follows:
In BizTalk Server 2004 only: If the history of a subscription across other instances has satisfied the subscription in less time than MaxThreshold, then BizTalk Server waits without dehydrating at that subscription forever or until it is satisfied.
In BizTalk Server 2006 only: BizTalk Server dehydrates if it has been waiting at any subscription with a non-empty history for more than 2*MaxThreshold.

39. When does the persistence of an orchestration happen?
Guaranteed persistence is at end-of-transaction (EOT), Send, and Suspend. Delay or Receive only persists if dehydration occurs. When end-of-service (EOS) or Terminate occurs, there is not a commit of any pending database operations, but the instance state is not persisted.
Commit points are optimized away in the following patterns:
· Two or more EOTs collapses to a single commit.
· One or more EOT followed by EOS collapses to a single commit.
· A Send followed by EOT or EOS collapses to a single commit. For example, Send immediately followed by EOT immediately followed by EOT immediately followed by EOS is a single commit. However, some potential optimizations are missed, for example, "Send, Send, Send, EOT" is three commits because we only coalesce a single "Send, EOT". Similarly, "Send, EOT, Send, EOT" is two commits.
On graceful shutdown BizTalk Server attempts to dehydrate and thus persist all orchestrations in memory. This is not always successful; sometimes orchestrations are not dehydratable and so the process ends without performing all the dehydrations. If this happens, the orchestration is restored on restart from the last persisted point.

40. How can an orchestration be updated without bringing down the BizTalk Server host?
To update an orchestration
1. Change the AssemblyInfo version number of the orchestrations, and then build and deploy the new assembly.
2. Bind the new orchestrations.
3. Manually perform the following steps:
a. Disable the receive location to temporarily prevent new messages from arriving. Of course, this implies that your service is unavailable to the outside world.
b. Unenlist the old version using BizTalk Explorer (do not stop it). This prevents new instances from starting while allowing old ones to finish.
c. Enlist the new version and start it. All new instances will be created using this one.
d. Enable the receive location.

41. How can I load a message to construct an XLANGMessage?
When constructing an XLANGMessage with a stream, the stream type must either implement IStreamFactory or else be a MemoryStream. The following code sample shows how to construct an XLANGMessage:
public class FileStreamFactory : IStreamFactory
{
string _fname;

public FileStreamFactory(string fname)
{
_fname = fname;
}

public Stream CreateStream()
{
return new FileStream
(
_fname,
FileMode.Open,
FileAccess.Read,
FileShare.Read
);
}
}

public static void AssignStreamFactoryToPart(XLANGMessage msg)
{
IStreamFactory sf = new FileStreamFactory( @”c:\data.xml” );
msg[0].LoadFrom( sf );
}

42. How can I make an orchestration output a string without any XML tags?
An orchestration always wraps the System.String string as an XML document when sending it out. For example, the following is the output of the string "mystring: from an orchestration:
mystring

to get a simple string without any XML tags, you need to define a custom-formatted part that serializes to raw text.
The following code shows an example of how to define a type that can be used in place of System.String to define such an XLANGs message part:
public abstract class BaseFormatter : IFormatter
{
public virtual SerializationBinder Binder
{
get { throw new NotSupportedException(); }
set { throw new NotSupportedException(); }
}

public virtual StreamingContext Context
{
get { throw new NotSupportedException(); }
set { throw new NotSupportedException(); }
}

public virtual ISurrogateSelector SurrogateSelector
{
get { throw new NotSupportedException(); }
set { throw new NotSupportedException(); }
}

public abstract void Serialize( Stream stm, object obj );
public abstract object Deserialize( Stream stm );
}

public class RawStringFormatter : BaseFormatter
{
public override void Serialize(Stream s, object o)
{
RawString rs = (RawString)o;
byte[] ba = rs.ToByteArray();
s.Write( ba, 0, ba.Length );
}

public override object Deserialize(Stream stm)
{
StreamReader sr = new StreamReader( stm, true );
string s = sr.ReadToEnd();
return new RawString( s );
}
}

[CustomFormatter(typeof(RawStringFormatter))]
[Serializable]
public class RawString
{
[XmlIgnore]
string _val;

public RawString(string s )
{
if (null==s)
throw new ArgumentNullException();
_val = s;
}

public RawString()
{
}

public byte[] ToByteArray()
{
return Encoding.UTF8.GetBytes( _val );
}

public override string ToString()
{
return _val;
}
}



1 comment: