A voir, BizTalk rencontre passablement de probl??mes pour g??rer les fichiers dont le volume est important. Pourtant, malgr?? les efforts entrepris pour r?? architecturer l’application, il est parfois impossible de s’affranchir de ses OutOfMemoryException. Dans le cas du projet actuel, le probl??me ne se passe que lorsque BizTalk doit traiter plus d’un fichier en m??me temps. J’ai donc d??cid??, provisoirement, de ne soumettre ?? BizTalk qu’un seul fichier ?? la fois, et attendre qu’il en ait termin?? le traitement avant d’en soumettre le suivant. Or, il me semble qu’il n’est pas possible d’??tre averti lorsqu’une orchestration se termine, dans le framework .NET.
La m??thode que j’ai trouv??e passe par WMI. Ainsi, pour conna??tre quand une orchestration se termine :
private void MountBTSOrchestrationMonitoring()
{
// Only one watch to mount, because we can only monitor orchestration deletion
WqlEventQuery q = new WqlEventQuery(__InstanceDeletionEvent,
new TimeSpan(0,0,0,10),
“TargetInstance isa \”MSBTS_ServiceInstance\””);
m_btsWatcher = new ManagementEventWatcher(new ManagementScope(root/MicrosoftBizTalkServe),
q);
m_btsWatcher.EventArrived += new EventArrivedEventHandler(bts_OrchestrationDeleted);
m_btsWatcher.Start();
}
private void bts_OrchestrationDeleted(object sender, EventArrivedEventArgs e)
{
// Do something
}
Ainsi, lorsqu’une orchestration se terminera, l’??v??nement bts_OrchestrationDeleted sera appel??. Le seul petit probl??me, c’est qu’il n’est pas possible de conna??tre quelle orchestration s’est termin??e. Il faut alors interroger BizTalk, via WMI, ?? nouveau, pour savoir si une instance de l’orchestration observ??e est encore active :
private int OrchestrationInstanceCount(string strOrchestrationName)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder(“SELECT * FROM MSBTS_ServiceInstance WHERE ServiceName=\””);
sb.Append(strOrchestrationName);
sb.Append(“\””);
WqlObjectQuery w = new WqlObjectQuery(sb.ToString());
ManagementObjectSearcher objSearcher = new ManagementObjectSearcher(new ManagementScope(kstrWMIBTSNamespace),
w);
return objSearcher.Get().Count;
}
Si la m??thode retourne 0, aucune orchestration avec le nom donn?? en param??tre n’est active.
Attention toute fois ! BizTalk met un certain temps avant de mettre en route une orchestration, faisant que m??me si un fichier est d??pos?? dans un r??pertoire d’accueil de BizTalk, la m??thode risque de renvoyer la valeur 0, car l’orchestration n’aura pas encore d??marr??. Il serait alors judicieux de voir si des fichiers sont encore pr??sent dans le r??pertoire d’accueil avant d’en poster de nouveaux.
According to a lot of blogs, BizTalk has some issues with large files. However, despite of the efforts for rearchitecturing the application, it is sometimes not possible to avoid the OutOfMemoryException.
In the case of the actual project, that happens only when BizTalk has to process more than one file at a time. So, I temporary decided to pass to BizTalk only one file at a time and to wait the orchestration stops before copying the next file to the receive location. But, it seems that it is not possible to be warned when an orchestration stops with .NET.
The way I found is using WMI. To know when an orchestration stops, I install an event handler :
private void MountBTSOrchestrationMonitoring()
{
// Only one watch to mount, because we can only monitor orchestration deletion
WqlEventQuery q = new WqlEventQuery(__InstanceDeletionEvent,
new TimeSpan(0,0,0,10),
“TargetInstance isa \”MSBTS_ServiceInstance\””);
m_btsWatcher = new ManagementEventWatcher(new ManagementScope(root/MicrosoftBizTalkServe),
q);
m_btsWatcher.EventArrived += new EventArrivedEventHandler(bts_OrchestrationDeleted);
m_btsWatcher.Start();
}
private void bts_OrchestrationDeleted(object sender, EventArrivedEventArgs e)
{
// Do something
}
When an orchestration will stop, the bts_OrchestrationDeleted event will be called. There is only one little issue. It is impossible to know which orchestration stopped. We have to get the answer from BizTalk itself, through WMI again, and getting the number of active instance with a given name :
private int OrchestrationInstanceCount(string strOrchestrationName)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder(“SELECT * FROM MSBTS_ServiceInstance WHERE ServiceName=\””);
sb.Append(strOrchestrationName);
sb.Append(“\””);
WqlObjectQuery w = new WqlObjectQuery(sb.ToString());
ManagementObjectSearcher objSearcher = new ManagementObjectSearcher(new ManagementScope(kstrWMIBTSNamespace),
w);
return objSearcher.Get().Count;
}
If the method returns 0, no orchestration with the given name is still running.
But, warning ! BizTalk needs a bit of time before starting an orchestration and event a file is dropped in a BizTalk receive location, the method will certainly return 0, because the orchestration is not yet started. It would be a good idea to test is there are files in the receive location before dropping new files.
0 Comments