Search BrianLoesgen.com
Categories
Archives
Saturday
Oct302004

Checking the BizTalk MessageBox for specific suspended messages

I recently did something for a project I was on that I thought was pretty cool. The project took a different architectural path, so we didn’t end up using it, but I’m posting it here as I think someone out there will find it very useful….

 

I got my start on this from the great info Lee Graber posted on the BizTalk Core Engine blog (http://blogs.msdn.com/biztalk_core_engine/archive/2004/09/20/231974.aspx)

This code sample shows how to check the BizTalk MessageBox for suspended messages that were destined for a specific orchestration.

Is this useful? Well… maybe not. Here’s why: in order for a message that was destined for a specific orchestration to be suspended in the MessageBox, it means that a message agent got the message, looked up the subscription, and tried to send it to the orchestration. So, in order for the subscription to exist the orchestration must have been enlisted, and if it was enlisted, then the send should never fail.

 

So, while perhaps not directly useful, this sample does show some cool techniques that you could re-use elsewhere. Also, with some minor mods, you can check other tables and do things like have one orchestration be aware of pending messages destined for another orchestration.

 

Caveat: I did a lot of hacking and exploring while doing this. Use of this is purely your own decision. This may or may not be the best way to achieve the stated goal. As always, you should exercise extreme caution when doing *anything* directly affecting the MessageBox. Having said all that, I had fun hacking and reverse engineering, hopefully this helps someone.

 

How it works… The stored proc will iterate through the Q_Suspended tables for each of the host instances, looking for a uidInstanceID that matches the orchestration ID you pass in as a parameter.

 

Every orchestration has a unique identifier associated with it that gets created when the orchestration is created. You need to get this instance identifier. In order to do that, put this inside an Expression shape:

 

 

OrchestrationInstanceID = System.Convert.ToString(Microsoft.XLANGs.Core.Service.RootService.InstanceId);

 

Next, you’ll want a helper class that you can call that will check for messages. Here’s a sample (don’t worry about the UDL in the connection string, I’ll talk about that in a future post J).

 

      [Serializable()]

       public class MessageBoxHelper

       {

             // Connection string info is contained in UDL file, which must be present...

            protected String connectionString = "Provider=SQLOLEDB;File Name =\\\\" + System.Environment.MachineName.ToString() + "\\c$\\BTS.udl";

         public MessageBoxHelper()

        {

                  //

                  // TODO: Add constructor logic here

 

                  //

 

            }

             ///

            /// Calls a stored proc that checks the BTS MessageBox to determine if there are any messages either suspended

 

            /// or waiting to be delivered to a given orchestratrion instance. Usage is to determine if a convoy is done or not.

 

 

            public bool CheckForSuspendedMessages(string OrchServiceID)

 

            {

 

                  bool retval = false;

 

                  try

                  {                

 

                        OleDbConnection con = new OleDbConnection(connectionString);

 

                        System.Data.OleDb.OleDbCommand cmd = new OleDbCommand("BL_BTS_CheckForSuspendedMessages", con);

 

                        cmd.CommandType = System.Data.CommandType.StoredProcedure;

 

                        cmd.Parameters.Add("@OrchServiceID", OrchServiceID);

 

                        con.Open();

 

                        object ret = cmd.ExecuteScalar();

 

 

                        retval = !(Convert.ToInt32(ret)==0);

 

                  }

 

                  catch (Exception ex)

                  {

                         Logger errorLogger = new Neudesic.Utilities.Logger();

                         errorLogger.WriteEntry("Neudesic.Utilities.MessageBoxHelper Error", "Error accessing database: " + ex.Message, 5000, System.Diagnostics.EventLogEntryType.Error);

                         throw new ApplicationException("Critical error accessing BizTalk MsgBox database from Neudesic.Utilities.MessageBoxHelper: " + ex.Message , ex);

                   }

                   return retval;

             }

       }

 

 

In my case, I used the helper class as the decision expression in a decision shape as shown below (the orchestration had a variable declared that was of the MessageBoxHelper type):

 

 

MessageBoxHelper.CheckForSuspendedMessages(OrchestrationInstanceID)

 

Then, and this is the last piece, we have the stored proc itself:

 

SET QUOTED_IDENTIFIER OFF

GO

SET ANSI_NULLS OFF

GO

 CREATE  PROCEDURE [dbo].[BL_BTS_CheckForSuspendedMessages]

(

@OrchServiceID varchar(36)

)

 AS

 SET NOCOUNT ON

SET TRANSACTION ISOLATION LEVEL READ COMMITTED

SET DEADLOCK_PRIORITY LOW

 CREATE TABLE #Temp (Entries int)

DECLARE @nvcAppName sysname

 

DECLARE MyCursor CURSOR FAST_FORWARD FOR

SELECT nvcApplicationName FROM [BizTalkMsgboxDb]..[Applications] WITH (NOLOCK)

OPEN MyCursor

FETCH NEXT FROM MyCursor INTO @nvcAppName

WHILE (@@FETCH_STATUS = 0)

BEGIN

   INSERT INTO #Temp

   exec (' SELECT COUNT(*) FROM ' +  @nvcAppName + 'Q_Suspended WHERE uidInstanceID = CAST(''' + @OrchServiceID +''' AS uniqueidentifier)')

   FETCH NEXT FROM MyCursor INTO @nvcAppName

END 

SELECT SUM(Entries) AS TotalReferences FROM #Temp

CLOSE MyCursor

DEALLOCATE MyCursor

DROP TABLE #Temp

GO

SET QUOTED_IDENTIFIER OFF

GO

SET ANSI_NULLS ON

GO

Thursday
Sep302004

BTSServiceWindows for BizTalk Server 2004 -- Version 2.0 is released.

A new version of BTSServiceWindows for BizTalk Server 2004 is now available.

Version 2.0 introduces conditions. Now, when the time comes to enable or disable a receive location, BTSServiceWindows can optionally call a method in an assembly you specify that controls whether the location gets enabled or not. Conditions allow you to implement interresting requirements such as: “Every hour, check to see if a file exists on a remote FTP site, and if not, turn on a receive location and leave it on for at least 10 minutes. Check every 10 minutes, and leave the receive location on as long as there are files in a specified folder that need to be processed“.

Same price as the last version (free), and it's also a free upgrade :)

http://www.gotdotnet.com/Community/UserSamples/Details.aspx?SampleGuid=cf64cccf-00de-4608-9a6f-ac4d25a6afbb

Sunday
Aug222004

Day of Whidbey

OK, I think I win the “Least Prolific INETA Blogger” award :)

So let me just say a couple of words about the “Day of Whidbey” my user group put on in Carlsbad CA a couple of weeks ago.

I'd like to thank our AWESOME speakers:

  • Rob Howard, >>telligent systems
  • Chris Rolon, Neudesic
  • Russ Nemhauser, MVP

These guys rocked. It's tough to predict how a program will turn out when selecting speakers and topics, but they were awesome, and the evals were all exceptional. Thanks guys!

In addition, I'd like to thank the hard-working folks who worked with me on the Events Committee, and all our other volunteers for their support. This could not have happened without all the time and effort put in by a lot of dedicated people. It's a great pleasure to work with all of you for the good of our local developer community.

This was a world class event, ~120 people, and everything just worked perfectly.

If you're in SoCal, stay tunned, the next two confererences will be in November and then in Feb (we have two more booked beyond that too!).

In other user group news, SanDiego.NET UG just received 501(c)(3) certification from the IRS, making us the second .NET UG in the US to do so. Yes, we will be writing this up for INETA!

Brian

Friday
Jun252004

New utility for BizTalk 2004: ServiceWindows

Well now that my part of the SAMS BizTalk 2004 Unleashed book's done, I'm bored.

So, I wrote a little utility that we at Neudesic could have used on a couple of our BizTalk projects, and I'm thinking others may need it as well. So, say hello to "ServiceWindows".

What is ServiceWindows?
ServiceWindows is a utility that allows you to turn BizTalk 2004 receive locations on and off at intervals specified in a configuration file.

What problem does ServiceWindows solve?
BizTalk Server 2004 provides a powerful business process automation capability via orchestrations. However, you may only want these processes to run during defined service windows. An effective way to control execution of orchestrations is by controlling the receive locations that trigger instantiation of the process, effectively “turning the tap on and off”.

BizTalk Server 2004 allows you to specify a single service window for a receive location (eg: “process messages between 1:00AM and 2:00AM every day”). ServiceWindows extends this capability by allowing you to turn on receive locations at specified intervals, and automatically disable them after a specified duration has elapsed (eg:”Enable this receive location every hour, and keep it enabled for 10 minutes”).

How does it work?
ServiceWindows uses the BizTalk Server Explorer Object Model, and I manipulate the receive location state through that.

Is it easy to use?
You betcha! Here's an example:

ServiceWindowManager mgr = new ServiceWindowManager(@"C:\Visual Studio Projects\BTSServiceWindows\BTSServiceWindows\ServiceWindows.xml");
mgr.LoggingEnabled = true;
mgr.StartProcessing();

There are two sample programs included with it, a console app and a sample Windows service, to show you how to use it.

You can see the readme here.

You can download ServiceWindows here.

Enjoy!

Monday
May312004

TechEd 2004 Post-mortem...

So TechEd is over, and the world is slowly returning to normal. How was it? In a word, "wow". Another word, "intense".

I had more high-profile things going on the TechEd than at any prior events, and they all worked out perfectly. Here's my personal scorecard for events I was directly involved in/coordinating:

- My TechEd session on BizTalk and Web services: a success. In fact, turns out this was the most attended BizTalk session at TechEd!
- INETA User Group Leader conf: a success, just like past ones, lot's of fun, great attendee feedback
- Regional UG Meeting: approx 120-140 people attended to hear the C#/VB.NET teams present at a regional UG meeting I organized
- INETA Board/working group meetings: done, many of them, lots of good brainstorming

Trivia:
- Number of sessions I was in all the way through: 1 (the one I gave!)
- First day I was able to see even a partial session: Thursday (Day 4)
- Best dinner award: The Marine Room

The weather:
Yeah, it sucked. The attendees got to see the worst San Diego ever gets, it was like days we get in Feb (I warned you this could happen). On Saturday, after most of you had gone, the clouds parted and it was a bright sunny morning, followed by more seasonal temps in the mid-70's. My wife and I wandered around the Gaslamp and caught part of the jazz festival. Sunday it was ~80 at the coast (I did a therapeutic beach day :)), which is as hot as it ever gets. For those of you that chose to hang out for a couple for a few extra days: great choice, you got to see why we love to live here.

Thanks to everyone for making this the best TechEd yet. See you all in Orlando next June!

Friday
May212004

Coming to San Diego for TechEd? 11,000 of you are!

Are you coming to San Diego?

Are you coming to San Diego for TechEd? A lot of people are. I’m looking forward to seeing a lot of my old friends, fellow INETA folks, fellow authors, fellow speakers, and a whole lot of other folks starting in another day (yeah, I meant to post something a week ago, but have been slammed with TechEd prep and client obligations). Next week will be intense for me, with INETA (ineta.org) planning and Board meetings, the INETA user group leader conference we’re hosting, the regional UG meeting I’m hosting on Tues (see SanDiegoDotNet.com), speaking at TechEd, and what seems like an continual stream of meetings and parties. Intense, but fun, and I’m really looking forward to seeing y’all.

Welcome to my adopted home town. Here are some random things you may want to know.

Weather

Pretty well perfect, that’s why I moved here. Average temp year-round is 72 deg. The coast is coolest, as you drive inland temps go up at a rate of about one degree/mile for the first 20 miles or so. Nov – Feb is our “rainy season”, meaning it could rain a few times (not sure, I think it must have rained approx 6 times in the past year). That’s as bad as it gets. The second worst weather (not counting firestorms as “weather”!) we get is “May gray/June gloom”, which you folks may experience. After living here for 5 years, I’m still not 100% clear on the cause, it’s some complex interplay between ocean temp, air temp, pressure, etc. It’s essentially a fog blanket on the coast that moves in at night and burns off in the morning. Sometimes it gets so thick that it doesn’t burn off, hence the “gloom”, making San Diego seem like Seattle with palm trees. Don’t like it? Drive inland a few miles and it’ll be 80 deg with not a cloud in the sky.

Places to eat

I live ~40mins north of downtown (10 minutes from the beach) and very very rarely go downtown (we have everything we need close to us), so I can't make many recommendations. Here’s some though (probably take about 20 minutes by cab to La Jolla):

Croce’s (Gaslamp): owned by Jim Croce’s wife, lots of memorabilia. Apparently his son plays guitar there sometimes. Food is pretty good, mid-range place.

George’s (La Jolla): my experiences here have ranged from good to exceptional. High end place, good place to spot actors and famous people.

Crab Catcher (La Jolla): excellent food, great views, a little less formal than George’s, but still a very nice place.

Marine Room (La Jolla): the quintessential California experience. Large plate glass windows that at high tide are pummeled by the surf. High end.

Like Mexican food? San Diego has the best Mexican food in the US (sorry Texas, Arizona, et al, it IS true!). Some of my favorite places are little hole-in-the-wall taco shops that serve authentic Mexican.

Around San Diego

San Diego downtown is VERY small. Everything is either a short walk or a short cab ride away.

The Gaslamp is a historic area with lots of bars (ranging from very trendy to beer-swilling places) and places to eat. This is where most TechEd people will be wandering around in the evenings.

We have the “world famous San Diego zoo”, however if you’re into that I personally prefer the Wild Animal Park in Escondido. It’s actually part of the zoo organization, but much bigger. You’ll need a car to get there from downtown.

Balboa park is a nice area to walk around in. Nice gardens, lots of museums. Close to downtown.

Looking for Sunday brunch? Try the Hotel Del on Corronado island (at the other end of the sweeping bridge you see going across the San Diego bay). Not cheap, but world famous. Great beaches there too.

La Jolla. Nice place to walk around and people watch. Lots of trendy galleries where you could spend vast fortunes, but it’s free to look. The seals in the cove are a big attraction, as is diving if you’re into that.

The desert. My favorite places to go to get away. Unfortunately it’ll be “toasty” this time of year (90-100deg), you’re a couple of months late. If you can handle the heat, head to Borrego Springs and do the 3 mile mega-touristy Palm Canyon hike (take lots of water).

Legoland. If you’re here with kids, it’s up in Carlsbad. If you don’t have kids with you, forget it, go to the beach instead.

Tijuana. Yes, it's true, you can grab a trolley near the convention center and be in Mexico in 30 minutes. Great place to go if you want to 1) shop 2) drink excessively. Also, crossing back into the US can be an interesting experience for any non-US citizens.

Old Town. It's not Tijuana, but there's shopping, lots of Mexican eats. Good place to kill a half day around lunch.

So after visting you're hooked and now want to live here in paradise?

Our biggest problems are cost-of-living and traffic. I read yesterday that in April the median home increased in value by ~$950 *PER DAY*. We’re hitting new affordability lows, where only something like 12% of the population can afford a $440K median-priced home. A shack in an area most people would not want to live in will cost you 300K. And none of those $440K homes are anywhere near the coast. Want ocean *view* and a decent family home? Think 1.1M or… a LOT more. However, somehow, people keep on coming…

Wednesday
Apr282004

Taking a break in Thailand...

I've been working with Sanjay Shetty (Mumbai, India) and Colt Kwong (Hong Kong, ROC) for quite some time now planning the launch of INETA (www.ineta.org) in the Asia-Pacific region. We're holding a 2-day User Group Leader Summit in Bangkok April 29th and 30th, bringing together some 30 people from across the region. Having never been to Thailand before, I took advantage of this opportunity to explore a little. So, I got to Bangkok -- and left (first time I had the chance to spend the weekend in L.A. I left to go diving at Catalina Island, can you spot the emerging trend? :)).

I've just spent the past 4.5 days in Chiang Mai, in the north of Thailand. It has been an incredible experience. I did the required tourist things (see some temples, get a massage, shop shop shop, eat eat eat...), but the high point, and the reason I came up here, was to go trekking in the mountain jungle. It really was the experience of a lifetime. The incredible part was just being there. It was butally hot, and a few in our group were having heat problems, but I was OK. Mist shrouded mountains, waterfalls... it was an idylic setting right out of a movie.

Day 1, our group got together and left the city. I got lucky, it was a great group of people. We ate at some wall-less shack two hours out that had water running down the tin roof (that was their air conditioning). We then drove some more, until we got to the elephant place (farm? ranch?). We rode elephants through the jungle, which was pretty cool. Did you know that elephants like to sneeze on themselves, presumably to cool off? I didn't. Some do so more than others, one poor woman almost needed rain gear. After that we hiked for a few hours, then got to a beautiful (and VERY welcome!) waterfall where we jumped in and cooled off. We then carried on, and spent the night in a Karen hilltribe village. We slept in a hut (under mosquito nets, natch), and ate villager food, which was very good. The village had no electricity, and was very remote. It was really interesting to see their lifestyles, and I have some great photos.

Day 2 we hiked some more, passing through some scattered settlements and isolated homes (a "home" can be a bamboo platform on stilts with a thatched roof and no -- or few -- walls). The school was interesting, they had a TV (solar powered), the only one I saw on the whole trek. We passed through lots of rice paddies (dry now, until the rains start in a month or two). We got to a waterfall which had a little "outpost", some enterprising locals who had brought ice in by motorcyle, and had cold beer. I supported them by paying their rather steep price (USD$1 for a cold beer, in the jungle in the middle of nowhere!). We rested a bit, then hiked on. We had lunch in some tiny village (excellent food once again). We then went bamboo rafting down the Wang river, which was a let-down due to low water lever (maybe it's me, that happened with Kayaking in New Mexico last year too). The damn raft kept running aground on rocks, just like in New Mexico. But, at least it was cooler. It was also a nice experience, passing under tenuous-at-best foot bridges, round a bend to see elephants, etc...

This has been a magical experience, one that you'd never get if you didn't venture beyond the confines of your hotel. So, I spent 3 nights in a five star hotel in downtown Chiang Mai, and one night sleeping in a hut in the jungle. When I look back, I prefered the hut and the experiences associated with it: the camraderie, the scenery, and the glimpses into a lifestyle so very far removed from my everyday modern life.

I'm already planning to come back, to do a 7-day trek, or maybe head further north to Chiang Rai or even Laos.

Now I'm off to hustle-bustle-polluted-crowded Bangkok, where I will connect to the Internet for the first time in a week (really dreading the backlog that must be waiting for me), and will have to rejoin the real world and get back to work. Vacation's over. I'm doing Powerpoints on the plane :(