(转)pika详解(三)SelectConnection及其他Connection
原文:https://blog.csdn.net/comprel/article/details/94661147
pika除了block connection外还提供了其他非阻塞式的连接方式
SelectConnection
定义如下:
class SelectConnection(BaseConnection):
def __init__(
self, # pylint: disable=R0913
parameters=None,
on_open_callback=None,
on_open_error_callback=None,
on_close_callback=None,
custom_ioloop=None,
internal_connection_workflow=True):
"""Create a new instance of the Connection object.
:param pika.connection.Parameters parameters: Connection parameters
:param callable on_open_callback: Method to call on connection open
:param None | method on_open_error_callback: Called if the connection
can't be established or connection establishment is interrupted by
`Connection.close()`: on_open_error_callback(Connection, exception).
:param None | method on_close_callback: Called when a previously fully
open connection is closed:
`on_close_callback(Connection, exception)`, where `exception` is
either an instance of `exceptions.ConnectionClosed` if closed by
user or broker or exception of another type that describes the cause
of connection failure.
:param None | IOLoop | nbio_interface.AbstractIOServices custom_ioloop:
Provide a custom I/O Loop object.
:param bool internal_connection_workflow: True for autonomous connection
establishment which is default; False for externally-managed
connection workflow via the `create_connection()` factory.
:raises: RuntimeError
"""
if isinstance(custom_ioloop, nbio_interface.AbstractIOServices):
nbio = custom_ioloop
else:
nbio = SelectorIOServicesAdapter(custom_ioloop or IOLoop())
super(SelectConnection, self).__init__(
parameters,
on_open_callback,
on_open_error_callback,
on_close_callback,
nbio,
internal_connection_workflow=internal_connection_workflow)
@classmethod
def create_connection(cls,
connection_configs,
on_done,
custom_ioloop=None,
workflow=None):
"""Implement
:py:classmethod:`pika.adapters.BaseConnection.create_connection()`.
"""
nbio = SelectorIOServicesAdapter(custom_ioloop or IOLoop())
def connection_factory(params):
"""Connection factory."""
if params is None:
raise ValueError('Expected pika.connection.Parameters '
'instance, but got None in params arg.')
return cls(
parameters=params,
custom_ioloop=nbio,
internal_connection_workflow=False)
return cls._start_connection_workflow(
connection_configs=connection_configs,
connection_factory=connection_factory,
nbio=nbio,
workflow=workflow,
on_done=on_done)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
SelectConnection继承BaseConnection,只是重写了create_connection
在create_connection 中可以看到:
nbio = SelectorIOServicesAdapter(custom_ioloop or IOLoop())
说明这个类实现的 select IO
提供的函数、方法解析:
add_on_close_callback
关闭时候的回调, callback定义 callback(pika.connection.Connection,exception)
add_on_connection_blocked_callback
阻塞时候回调 回调定义: callback(connection, pika.frame.Method)
add_on_connection_unblocked_callback
解除阻塞时候回调
add_on_open_callback
打开时回调
add_on_open_error_callback
打开异常时候回调
basic_nack
channel(channel_number = None*,*on_open_callback = None )
建立通道
channel_number(int) - 要使用的通道编号,默认为下一个可用通道编号。
on_open_callback(callable)
close
consumer_cancel_notify
定服务器是否支持活动连接上的使用者取消通知 返回bool值
create_connection(connection_configs, on_done, custom_ioloop=None, workflow=None)
建立连接
exchange_exchange_bindings
返回值bool 是否支持交换机修改
ioloop
is_closed
is_closing
is_open
publisher_confirms
是否支持发布确认
Tornado Connection Adapter
方法可参考基类BaseConnection
略
Twisted Connection Adapter
方法可参考基类BaseConnection
略
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· 没有源码,如何修改代码逻辑?
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· 百万级群聊的设计实践
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
2018-10-31 (转)python的ConfigParser模块
2018-10-31 (转)csv — 逗号分隔值文件格式
2018-10-31 (转)Python3之shutil模块
2017-10-31 (转)mysql 备份与恢复mysqlhotcopy
2017-10-31 (转)mysql -prompt选项