Cloud and Microsoft technologies enthusiast architect in Switzerland RSS 2.0
# Monday, July 11, 2005

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.

Monday, July 11, 2005 1:34:22 PM (GMT Daylight Time, UTC+01:00)  #    Comments [0] -
BTS2004 | Programming | Technical
Google Cloud Platform Certified Professional Cloud Architect
Ranked #1 as
French-speaking SharePoint
Community Influencer 2013
Navigation
Currently Reading :
I was there :
I was there :
I was exhibiting at :
I was there :
I was a speaker at :
I was a speaker at :
I was a speaker at
(January 2013 session):
I was a speaker at :
I was a speaker at :
United Nations (UN) SharePoint Event 2011
I was a speaker at :
I was there !
I was there !
I was there !
I was there !
Archive
<October 2021>
SunMonTueWedThuFriSat
262728293012
3456789
10111213141516
17181920212223
24252627282930
31123456
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2021
Yves Peneveyre
Sign In
Statistics
Total Posts: 290
This Year: 0
This Month: 0
This Week: 0
Comments: 20
Themes
Pick a theme:
All Content © 2021, Yves Peneveyre
DasBlog theme 'Business' created by Christoph De Baene (delarou)