ESB Guidance...part 6

Listen with webReader
Published 01 February 08 11:04 PM | wmmihaa

Policy based routing using the Business Rule Engine resolver

There are several samples that come with the ESB Guidance installation utilizing the BRE Resolver to resolve the endpoints.  All of them implements a very simple rule that states  {if 1==1 then...}. This can still be useful when you only want to use the BRE for the purpose of having an endpoint repository. In which case you'd create one policy for each endpoint.

But what if you'd like to apply a rule like {if Customer == "Microsoft" then... else..}. Of course the ‘else' statement has to be implemented as a new rule, but part from that, this could be very useful if you like to route the message to different endpoint depending on the context of the message. Sort of like Content Based Routing but being able to support more complex scenarios.

Looking at the BRE connection string there is a ‘useMsg' property. How to use this property is not described in the documentation, and in all the samples useMsg is set to null (False).

BRE:\\policy=GetCanadaEndPoint;version=1.0;useMsg=;

Setting this property to True, should cause the Resolver Manager to add the message as a fact upon executing the policy. Unfortunately there is a bug in the ResolveProvider in ESB.Resolver.ESB assembly:

Dictionary<string, string> IResolveProvider.Resolve(string config, string resolver, 
    IBaseMessage message, IPipelineContext pipelineContext)
{
    
    // Resolve the params from arguments by creating
    // class from schema, and storing the results
    Resolution resolution = new Resolution();
    XmlDocument xd1 = null;

    try
    {
        // Populate context
        ResolverMgr.SetContext(resolution, message, pipelineContext);

        // resolve with rules and return dictionary
        return ResolveRules(config, resolver, xd1, resolution, message);

    }
    catch (System.Exception ex)
    {
        EventLogger.Write(MethodInfo.GetCurrentMethod(), ex);
        throw;
    }
    finally
    {
        if (null != resolution)
            resolution = null;                
    }
}

The problem is that the XmlDocument xd1 (the actual bts message) is always going to be null, and will cause an null object reference exception to be raised. You will have to fix this by changing it to (line 224):

XmlDocument xd1 = new XmlDocument(); 

The next problem was a little bit trickier to figure out. It seemed the BRE could not match the DocumentType with the actual message. As it turn out, the DocumentType has to be added to the BizTalk context properties before the resolver is executed or it will be set to "Microsoft.Practices.ESB.ResolveProviderMessage".

This means you have to change the DocumentType in the Business Rule Composer.

BRE Fact Explorer

Then set the useMsg property to True:

BRE:\\policy=GetEndPointByCustomer;version=1.0;useMsg=True;

And implement your rule:

Rule

Good luck!

 

Filed under: , ,

Comments

# Mikael Håkanssons' Blog said on February 1, 2008 11:55 PM:

Extending ESB Guidance · Blogical.Adapter.SQL - Download · Blogical.Adapter.SMTP - Download · Blogical

# Abby said on February 4, 2008 03:52 PM:

Great Post Please keep it up. Unfortunatly the final version documentation is worst than the CTP release.

Thanks,

Abby

# Jim Bowyer said on February 26, 2008 04:36 AM:

Intrested to know if you managed to get BRE itineraries to work with 2-way adapters for downstream (e.g. SOAP instead of file you have working here).  Great post!  Thx, JB

# petos said on March 14, 2008 12:19 AM:

I tried to modify the Resolver dll, but as you compile the asembly you end up with an assembly with a different public key token than the one from the assembly installed with the Guidance MSI package. How did you managed to make this work?

# wmmihaa said on March 14, 2008 08:06 AM:

When you install ESB Guidance you have the choice of doing it from Windows installer files or from Solution projects. If you install using the msi packages, you don’t get access to the key, since they used the same key as they used for compiling biztalk assemblies.

I’m sorry to say, but I think you have to do it all over again, but using the solution projects.

//Mikael

# Abir said on April 25, 2008 03:53 PM:

Hi Mikael,

             I tried your example had a hell of a time redeploying everything and finding the places of hardcoding. Finally managed to set things up but now I am gettuing a starnge problem the message is getting routed in the right place but the contents are blank. do you ahve any idea why this is happening?

Regards

Abir

# Abir said on April 25, 2008 03:53 PM:

Hi Mikael,

             I tried your example had a hell of a time redeploying everything and finding the places of hardcoding. Finally managed to set things up but now I am gettuing a starnge problem the message is getting routed in the right place but the contents are blank. do you ahve any idea why this is happening?

Regards

Abir

# Abir said on April 25, 2008 03:53 PM:

Hi Mikael,

             I tried your example had a hell of a time redeploying everything and finding the places of hardcoding. Finally managed to set things up but now I am gettuing a starnge problem the message is getting routed in the right place but the contents are blank. do you ahve any idea why this is happening?

Regards

Abir

# wmmihaa said on April 25, 2008 11:35 PM:

Abir, are you refering to the message sent to the BRE or to the dynamic send port?

If the BRE can't match the DocType, make sure you set the [Document Type] property of your schema to "Microsoft.Practices.ESB.ResolveProviderMessage" (in BRE Facts Explorer).

Get back to me if this is not the problem.

//Mikael

# Abir said on April 28, 2008 02:51 PM:

Hi Mikael,

               I am setting the DocumentType property in the Facts explorer to Microsoft.Practices.ESB.ResolveProviderMessage. But the final message which I am getting which is sent out by the dynamic send port is blank with 0kb size. the routing though is happening as per the rule.

Do i need to change anything in my actual schema? I presently am not doing anything in the actual schema.

Abir

# wmmihaa said on April 28, 2008 03:58 PM:

No, you should not need to change anything on your schema.

What adapter provider are you using?

If you set up a new File Send port, and subscribe to the same receive port, does it come out with its full content(not empty)?

//Mikael

# Abir said on April 29, 2008 01:25 PM:

Hi Mikael,

            I am setting the transport type dynamically(in the business rule) to FILE. Also If i set up a static file send port it gives the same problem that is empty content however if i use a pass through/xml pipeline things behave properly i get the message etc.

I tried using a custom pipeline using the ESB Dispatcher Disassemble that too didnt work. is it possible for you to share your work maybe I can try that on my machine,

One more thing which i tried was stopped the send point and then observed the message in the biztalk group page. Here one strange thing i noticed is  that the body is blank and also the adapter and the URI

Abir

# wmmihaa said on April 29, 2008 02:33 PM:

I'd be happy to share, what would you like?

What other resolution attributes did you set (other than the TransportType). You must set the:

* TransportLocation (Eg. c:\...)

* Action (Eg. SubmitRequest)

* MessageExchangePattern (Eg. One-Way)

Are you calling any transormation service?

Where are you defining the itinerary. In the pipeline component or in the client message?

If I'm on-line you might be better of reaching me on the msn messenger.

# Abir said on May 5, 2008 11:11 AM:

Hi Mikael,

              Sorry for replying late actually I thought of trying the itinary examples first.  Well the good news is that dynamic routing using BRE worked when I did it using the Itinary service.  Earlier when i was having that 0KB issue I was using the dynamic resolution exaple and then trying to manipulate it.

Regards

Abir

# WHAmarcelo said on October 9, 2008 10:17 PM:

I'm having the same problem related by Abir.

I changed the line 224 of ESB.Resolver.BRE, put the documenttype on BRE, this happens when i set the usemsg=true,  but the message arrives with 0kb size, even if i call the BRE resolver as a service in itinerary, or too when i call the BRE resolver in ESB dispatcher disassembler. ( Itinerary sample and Dynamic resolution sample ).

How didi u resolve this problem???

can u give more details??

thx

# ... said on February 1, 2009 02:55 PM:

Nice site really!

# Music_Mp3_Sleerpelabulp said on February 5, 2009 08:27 AM:

Hello to all :) I can’t understand how to add your site in my rss reader. Help me, please

# wmmihaa said on February 9, 2009 12:33 AM:

Click the RSS or Atom link, which  brings you to the Feedburner site. From there click the "View feed XML" link.

or just follow this link:

Leave a Comment

(required) 
(required) 
(optional)
(required) 

This Blog

News

    MVP - Microsoft Most Valuable Professional BizTalk User Group Sweden BizTalk blogdoc

    Follow me on Twitter Meet me at TechEd

    Visitors

    Locations of visitors to this page

    Disclaimer

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

Syndication