The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

OrBee (61) [Avatar] Offline
#1
I want to implement a flow that calls a web service to insert data into a database. If that service is unavailable I want to save the data directly to a database. Here are my ideas for implementing this part of the flow. I would appreciate your comments if this is a good approach.

<flow name="main1">
<!-- Call to webservice.....-->
<http:outbound-endpoint ..exchange-pattern="request-response"...>
<flow-ref="if-webservice-fails">
</flow>

<flow name="if-webservice-fails">
<choice>
<when expression="http.status.response!=201">
insert to database>
</when>
<otherwise>
</otherwise>
</choice>

<! -- if database insert throws exception -->
<exception-strategy>
<logger...../>
</exception-strategy>
</flow>
David Dossot (233) [Avatar] Offline
#2
Re: Flow Implementation question
I would change the following:

- have the status code check in "main1", right after the HTTP outbound
- add an exception strategy in "main1" that also calls "if-webservice-fails" (otherwise you're not covered if an exception is thrown there).
OrBee (61) [Avatar] Offline
#3
Re: Flow Implementation question
One problem I see is that the second flow has a jdbc outbound-endpoint which a private flow is not allowed to have. This leaves me with a subflow as the only option. In that case I see a problem because the subflow cannot have it's own exception strategy. The implication is that if an exception is thrown by the jdbc insert how will it be handled?

For the flow below, it will be a problem if the jdbc insert fails.

I have the flow-ref in the default exception strategy because if the http endpoint throws an exception because the service is unavailable, then the subflow will be invoked, as you suggested. As an aside, is the a message-property-filter the correct filter to use to check the status of the http response? Is my usage correct?

Main flow
<flow>
<http:outbound-endpoint address="$server.path}" method="POST" exchange-pattern="request-response" ...../>
<message-property-filter pattern="http.status !=201">
<flow-ref name="insertFlow"/>
</message-property-filter>
<default-exception-strategy>
<flow-ref name="insertFlow"/>
</default-exception-strategy>
</flow>

<subflow name="insertFlow">
<jdbc:outbound-endpoint connector-ref="myconnector" key="insertProcess" ...>
</subflow>

Many thanks for your book, it's quite helpful
David Dossot (233) [Avatar] Offline
#4
Re: Flow Implementation question
> the second flow has a jdbc outbound-endpoint which a private flow is not allowed to have

Why do you say that? It should totally be allowed. What error do you get?
OrBee (61) [Avatar] Offline
#5
Re: Flow Implementation question
On page 44 of the book, here's what it says
The
primary reason for using a private flow instead of a sub-flow is to define in it a
different exception strategy from the calling flow (something that is impossible
with a sub-flow).
OrBee (61) [Avatar] Offline
#6
Re: Flow Implementation question
Sorry, that was in connection with the exception strategy. However, page 42 says the following about a private flow:

Basically it's just a regular flow, but
without any message source.

Is an outbound-endpoint not considered a message source?
David Dossot (233) [Avatar] Offline
#7
Re: Flow Implementation question
No, message sources are inbound endpoints, pollers and custom ones created with DevKit (ie in Cloud Connectors).

Edit: See 2.2.1 for a discussion about message sources. We are missing a line about DevKit created message sources though, thanks for asking this question!