DoFn 中的 HTTP 客户端 [英] HTTP Client in DoFn
问题描述
我想通过 DoFn 为在 Dataflow 上运行的 Apache Beam Pipeline 发出 POST 请求.
I would like to make POST request through a DoFn for a Apache Beam Pipeline running on Dataflow.
为此,我创建了一个客户端,它实例化了在 PoolingHttpClientConnectionManager 上配置的 HttpClosableClient.
For that, I have created a client which instanciate an HttpClosableClient configured on a PoolingHttpClientConnectionManager.
但是,我为我处理的每个元素实例化了一个客户端.
However, I instanciate a client for each element that I process.
如何设置一个供我所有元素使用的持久客户端?
How could I setup a persistent client used by all my elements?
还有我应该使用的并行和高速 HTTP 请求的其他类吗?
And is there other class for parallel and high-speed HTTP requests that I should use?
推荐答案
可以把客户端放入成员变量中,使用@Setup
方法打开,@Teardown
关闭它.Beam 中几乎所有 IO 的实现都使用这种模式,例如见 JdbcIO.
You can put the client into a member variable, use the @Setup
method to open it, and @Teardown
to close it. Implementation of almost all IOs in Beam uses this pattern, e.g. see JdbcIO.
这篇关于DoFn 中的 HTTP 客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!