开发者

Best practice of consuming remote web services reliably in ColdFusion?

How should one carry out web services call in ColdFusion reliably?

How do you handle situations like the remote server is down / busy? and lead to page timeout?

How to implement retry every x seconds?

Should remote calls be called in an Async manner, and if so, how to do callbacks?

Maybe ColdFusion 10 <cfjob> and Closure support will addresses these in a cleaner, more straight forward manner. However, how to address th开发者_运维技巧ese in CF9?

Thank you


We do a lot of integration with third parties usually over REST or SOAP, or ActiveMQ.

Generally we deal with all web service calls in the same way - if they fail (through a timeout or other error) we throw an exception by setting the cfhttp attribute throwOnError=true. This gets caught by high level application exception handling which emails or development team so they can investigate.

The only exception to this approach is when calling a 'trivial' web service from a CFM page that is not critical - for example to get some presentation data. We do not want a timeout on this call to bork the whole page, so we set the throwOnError=false (the default) and check the status message / code for the error. We email the error to the development team to investigate but we just continue with page processing.

We tend to avoid retries, as we know most services will be called again by another request soon, and the where do you draw the line? 1 retry? 100 retries? How is this affecting the user? I also find the logic about retries can be messy at best and usually ugly and repetitious.

Another approach with web services whose results are used on presentation pages is to call them from a scheduled task or cfthread. This is a good approach if you can persist the result in a cache, database or otherwise and get your code to hit the persistent store for the data rather than the web service itself. This has the dual effect of making sure the page is fast (if your web service call is delayed) and that any errors do not affect the user. Again any failure can be reported for investigation.

We've seen a web service on a busy presentation page bring down the server because of timeout that was too long (I would aim for around 1-3 secs max). All the running requests were used up dealing with the web service and then the queuing started. Not pretty. Learn from that mistake and use a very fast timeout or else just don't put the web service there as I mentioned before.

I don't believe it is possible to do asynchronous calls/callbacks. You might be thinking of Node.js :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜