Monday, February 23, 2015

Must receive before sending a message whose messagetype corresponds to a requestresponse operation on an implemented port




The above error occurred in an Orchestration, in which following scenario was to be orchestrated: the process gets started after receiving message over the RequestResponse port (HTTP based) followed by transformation to the destination format and sending out the transformed message to destination system. If all is ok then response message is to be sent back to RequestResponse with status as Processed and if something goes wrong then response message is to be sent back to RequestResponse with status as Failed and Error message.

Based on this, below Orchestration is designed:


As an exception was to be handled so Scope with TransactionType None was added followed by Exception Handler. So flow looked simple and straight forward:
1. Receive Input Message
2. Transform to destination format 
3. Send transformed message to destination system
4. Construct response message and send Positive response back
5. If an exception occurs in above steps then catch it in Exception Handler
6. Construct response message and send negative response back including exception message

All looked good, until it was compiled and error was notified.


Why it happened:

As can be interpreted from error message, there was mismatch found in the number of Request received to the number of Responses sent to the RequestResponse port. Although the flow logically appears correct but syntactically it is not. RequestResponse port requires a pair (one receive and one response) to get successfully validated, so while compiling when first send shape (connected to response operation) is found it gets validated (for compiler pair is completed), and going down in Exception block when second send shape (connected to response operation) is found it throws an error as no matching receive shape is found to complete the pair.



What to do:

In actual, there is if else situation depending on which Response message is to be sent with respective status associated with it. And even compiler loves this segregation as only one condition at a time will be true thus only one pair will form which is valid.
Below is the redesigned Orchestration:


The changes done :
1. Added a Boolean variable _exceptionOccurred initialized with false.
2. In Exception block _exceptionOccurred  is set to true, so whenever exception occurs the variable will be true

3. Then Decide shape is placed under Exception block
4. So if value of variable is false(NoException) then Response message with status processed ok is constructed and sent to requestresponse port

5. And if value of variable is true then Response message with status failed is constructed and sent to requestresponse port


Wondering if there is any other way to handle this scenario?



6 comments:

  1. Not handles such scenario but will sure help to handle such scenario

    ReplyDelete
  2. Hi,
    If i am working on this scenario i would connect the success response send shape to the response port operation and construct a fault message in the catch block and connect fault to a fault on the port.
    Thanks

    ReplyDelete
  3. Can you please explain me what is _exceptionMessage?

    ReplyDelete
  4. _exceptionMessage is a variable to which I assign the message (exception message) from the exception object. So if you see systemEx is the object of type System.Exception and whenever there will be any exception this object will get its properties (ie., Message,InnerException etc) populated with respect to the exception occurred.
    Thus systemEx.Message gives me the exception message and that I have assigned to the _exceptionMessage variable which I later use to update the status field which denotes success or exception .

    ReplyDelete
  5. I had read this blog long back but today when I was facing the same issue, couldn't recall it.
    Very well written blog.
    Thanks.

    ReplyDelete
  6. I have read this blog long back but today when I faced this issue couldn't recall it.
    Very nicely written blog.
    Keep Blogging :)

    Thanks,
    Prashant Singh

    ReplyDelete