envoy_cluster_upstream_cx_destroy_local_with_active_rq 是 Ambassador 中用于清理本地使劲的连接(即本地主动建立的 TCP 连接),并关闭具有活跃请求数的连接的函数。通常在关闭连接时,如果连接上有正在执行中的请求,则会等待这些请求完成后再关闭连接。但是如果连接上的请求无法正常结束(如连接超时等),则这些请求会被清除并关闭连接。以下是一个使用 envoy_cluster_upstream_cx_destroy_local_with_active_rq 函数的 Python 代码示例:
from ambassador import EnvoyHTTPFilter
from ambassador.envoy.exceptions import MappingError
class MyEnvoyHTTPFilter(EnvoyHTTPFilter):
def on_request_headers(self, headers, **kwargs):
# some code here
return headers
def on_destroy(self):
# clean up local active connections
self.logger.debug("Cleaning up local connections")
self._filter_root_context.destroy_local_with_active_rq()
在以上代码中,我们可以看到在调用 on_destroy 方法时,使用了 envoy_cluster_upstream_cx_destroy_local_with_active_rq 函数,以清除本地建立的连接。