本文整理匯總了Python中gnsq.Nsqd.ready方法的典型用法代碼示例。如果您正苦於以下問題:Python Nsqd.ready方法的具體用法?Python Nsqd.ready怎麽用?Python Nsqd.ready使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類gnsq.Nsqd
的用法示例。
在下文中一共展示了Nsqd.ready方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_sync_receive_messages
# 需要導入模塊: from gnsq import Nsqd [as 別名]
# 或者: from gnsq.Nsqd import ready [as 別名]
def test_sync_receive_messages():
@mock_server
def handle(socket, address):
assert socket.recv(4) == ' V2'
assert socket.recv(9) == 'IDENTIFY\n'
size = nsq.unpack_size(socket.recv(4))
data = json.loads(socket.recv(size))
assert isinstance(data, dict)
socket.send(mock_response(nsq.FRAME_TYPE_RESPONSE, 'OK'))
msg = 'SUB topic channel\n'
assert socket.recv(len(msg)) == msg
socket.send(mock_response(nsq.FRAME_TYPE_RESPONSE, 'OK'))
for i in xrange(10):
assert socket.recv(6) == 'RDY 1\n'
body = json.dumps({'data': {'test_key': i}})
ts = i * 1000 * 1000
socket.send(mock_response_message(ts, i, i, body))
with handle as server:
conn = Nsqd(address='127.0.0.1', tcp_port=server.server_port)
conn.connect()
assert conn.identify() is None
conn.subscribe('topic', 'channel')
frame, data = conn.read_response()
assert frame == nsq.FRAME_TYPE_RESPONSE
assert data == 'OK'
for i in xrange(10):
conn.ready(1)
frame, msg = conn.read_response()
assert frame == nsq.FRAME_TYPE_MESSAGE
assert isinstance(msg, Message)
assert msg.timestamp == i * 1000 * 1000
assert msg.id == '%016d' % i
assert msg.attempts == i
assert json.loads(msg.body)['data']['test_key'] == i
示例2: test_socket_upgrades
# 需要導入模塊: from gnsq import Nsqd [as 別名]
# 或者: from gnsq.Nsqd import ready [as 別名]
def test_socket_upgrades(tls, deflate, snappy):
with NsqdIntegrationServer() as server:
options = {
'address': server.address,
'tcp_port': server.tcp_port,
'deflate': deflate,
'snappy': snappy,
}
if tls:
options.update({
'tls_v1': True,
'tls_options': {
'keyfile': server.tls_key,
'certfile': server.tls_cert,
}
})
conn = Nsqd(**options)
conn.connect()
assert conn.state == states.CONNECTED
if deflate and snappy:
with pytest.raises(errors.NSQErrorCode):
conn.identify()
return
if tls and BAD_GEVENT:
with pytest.raises(AttributeError):
conn.identify()
return
if tls and server.version < (0, 2, 28):
with pytest.raises(ssl.SSLError):
conn.identify()
return
resp = conn.identify()
assert isinstance(resp, dict)
assert resp['tls_v1'] is tls
assert resp['deflate'] is deflate
assert resp['snappy'] is snappy
if tls and (deflate or snappy):
assert isinstance(conn.stream.socket._socket, SSLSocket)
elif tls:
assert isinstance(conn.stream.socket, SSLSocket)
if deflate:
assert isinstance(conn.stream.socket, DefalteSocket)
if snappy:
assert isinstance(conn.stream.socket, SnappySocket)
conn.publish('topic', 'sup')
frame, data = conn.read_response()
assert frame == nsq.FRAME_TYPE_RESPONSE
assert data == 'OK'
conn.subscribe('topic', 'channel')
frame, data = conn.read_response()
assert frame == nsq.FRAME_TYPE_RESPONSE
assert data == 'OK'
conn.ready(1)
frame, data = conn.read_response()
assert frame == nsq.FRAME_TYPE_MESSAGE
assert data.body == 'sup'
conn.close_stream()