[英]Post multiple requests to an API but without re-using connections
I have a console application which is calling a third party API, basically it takes records from a database and pushes them to the third party via their WCF API.我有一个调用第三方 API 的控制台应用程序,基本上它从数据库中获取记录并通过他们的 WCF API 将它们推送给第三方。
For various reasons (Mainly the third party API being very slow - 7 seconds to respond) we want to post multiple records in parallel so we have started doing this, however we are now seeing some strange behaviour from the third party API where it is duplicating records.由于各种原因(主要是第三方 API 非常慢 - 响应 7 秒),我们希望并行发布多个记录,因此我们已经开始这样做,但是我们现在看到来自第三方 API 的一些奇怪行为,它正在复制记录。
It has been suggested to us by the developers of the API that this is because we are sending the requests over the same connection (which makes sense as .net will reuse connections) and they dont/cant/wont support that, they will only support one request over one connection and then the connection must be closed. API 的开发人员向我们建议,这是因为我们通过同一连接发送请求(这是有道理的,因为 .net 将重用连接)并且他们不/不能/不会支持,他们只会支持一个请求通过一个连接,然后连接必须关闭。
My question is, How do I do this in .net core (2.2) We are currently using a HttpClient which I'd expect to reuse connections where possible - how can I guarantee that we use a new connection for each request?我的问题是,如何在 .net core (2.2) 中执行此操作我们目前正在使用 HttpClient,我希望在可能的情况下重用连接 - 我如何保证我们为每个请求使用新连接?
I have after some digging worked out what the problem is and there is no way to fix it.经过一番挖掘,我发现了问题所在,但没有办法解决。
The process is :过程是:
All fine if you only ever post one record at a time.如果您一次只发布一条记录,那一切都很好。 But as Im executing in parallel what is happening is :
但是当我并行执行时,正在发生的事情是:
Needless to say, we have entered into discussions with the provider of the API, it might be EOL and pretty much out of support but we're paying for licencing of this thing and this is a really stupid process that they need to provide a fix or a workaround for.不用说,我们已经与 API 的提供者进行了讨论,它可能是 EOL 并且几乎没有支持,但我们正在为这个东西的许可付费,这是一个非常愚蠢的过程,他们需要提供修复或解决方法。
So in the end it was nothing to do with reusing connections, dont know why we were told it was.所以最后这与重用连接无关,不知道为什么我们被告知是这样。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.