Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Clojure 如何从环形web应用程序使用'clj http'连接池?_Clojure_Connection Pooling_Clj Http - Fatal编程技术网

Clojure 如何从环形web应用程序使用'clj http'连接池?

Clojure 如何从环形web应用程序使用'clj http'连接池?,clojure,connection-pooling,clj-http,Clojure,Connection Pooling,Clj Http,我使用clojure web应用程序作为代理web服务器 我的所有请求都进入这个clojure ring web应用程序,然后我使用它将请求发送到最终目的地 因此,到目前为止,我将此作为一个简单的解决方案,只需为每个请求调用cljhttp/request 但这还不够好,因为每次发出请求时,都会初始化一个新的http客户端。我需要连接池,以便正确地重用http客户端 声明您重复使用连接,如下所示: (with-connection-pool {:timeout 5 :threads 4 :inse

我使用clojure web应用程序作为代理web服务器

我的所有请求都进入这个clojure ring web应用程序,然后我使用它将请求发送到最终目的地

因此,到目前为止,我将此作为一个简单的解决方案,只需为每个请求调用
cljhttp/request

但这还不够好,因为每次发出请求时,都会初始化一个新的http客户端。我需要连接池,以便正确地重用http客户端

声明您重复使用连接,如下所示:

(with-connection-pool {:timeout 5 :threads 4 :insecure? false :default-per-route 10}
  (get "http://example.org/1")
  (post "http://example.org/2")
  (get "http://example.org/3")
  ...
  (get "http://example.org/999"))

也许我还不能很好地使用clojure,但是有人会如何处理这个连接池中的所有请求呢

实现一个中间件,将连接管理器添加到请求映射中


您需要自己处理连接管理器的生命周期,而不是使用表单。请参阅clj http文档关于持久连接的最后一部分。

嘿,皮特,是的,我的一位同事看到这个问题时也这么说。我对clojure不是很在行,你知道有什么例子可以说明这一点吗?可惜的是,
cljhttp
文档的这一部分没有提供示例。如果可以的话,我会创建一个pr。您所说的
是什么意思?您需要自己处理连接管理器的生命周期,而不是使用-form-
我不明白这一点哦,该死,我现在看到了。正如你所说,我错过了持久连接区域的最后一部分。知道了!