本文整理汇总了Python中nats.aio.client.Client.publish_request方法的典型用法代码示例。如果您正苦于以下问题:Python Client.publish_request方法的具体用法?Python Client.publish_request怎么用?Python Client.publish_request使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nats.aio.client.Client
的用法示例。
在下文中一共展示了Client.publish_request方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_close
# 需要导入模块: from nats.aio.client import Client [as 别名]
# 或者: from nats.aio.client.Client import publish_request [as 别名]
def test_close(self):
nc = NATS()
disconnected_count = 0
reconnected_count = 0
closed_count = 0
err_count = 0
@asyncio.coroutine
def disconnected_cb():
nonlocal disconnected_count
disconnected_count += 1
@asyncio.coroutine
def reconnected_cb():
nonlocal reconnected_count
reconnected_count += 1
@asyncio.coroutine
def closed_cb():
nonlocal closed_count
closed_count += 1
@asyncio.coroutine
def err_cb():
nonlocal err_count
err_count += 1
options = {
'io_loop': self.loop,
'disconnected_cb': disconnected_cb,
'closed_cb': closed_cb,
'reconnected_cb': reconnected_cb,
'error_cb': err_cb,
}
yield from nc.connect(**options)
yield from nc.close()
with self.assertRaises(ErrConnectionClosed):
yield from nc.publish("foo", b'A')
with self.assertRaises(ErrConnectionClosed):
yield from nc.subscribe("bar", "workers")
with self.assertRaises(ErrConnectionClosed):
yield from nc.publish_request("bar", "inbox", b'B')
with self.assertRaises(ErrConnectionClosed):
yield from nc.flush()
self.assertEqual(1, closed_count)
self.assertEqual(1, disconnected_count)
self.assertEqual(0, reconnected_count)
self.assertEqual(0, err_count)
示例2: Requester
# 需要导入模块: from nats.aio.client import Client [as 别名]
# 或者: from nats.aio.client.Client import publish_request [as 别名]
#.........这里部分代码省略.........
typed_properties = []
for key, value in properties.items():
typed_properties.append(DriverTools.property_params(key, value))
body = my_args['body']
if body:
body = base64.b64encode(b''+bytes(body, 'utf8')).decode("utf-8")
msg_data = json.dumps({
'properties': typed_properties,
'body': body
})
msgb = b''+bytes(msg_data, 'utf8')
split_mid = None
messages = []
if sys.getsizeof(msgb) > self.max_payload:
split_mid = str(uuid.uuid4())
messages = self._split_msg(split_mid, properties, my_args['body'])
else:
messages.append(msgb)
if not self.fire_and_forget:
if split_mid is not None and ('sessionID' not in properties or properties['sessionID'] is None or
not properties['sessionID']):
request_q += "_" + split_mid
self._init_split_msg_group(split_mid, request_q)
for msgb in messages:
try:
LOGGER.debug("natsd.Requester.call - publish splitted request " + str(typed_properties) +
" (size: " + str(sys.getsizeof(msgb)) + " bytes) on " + request_q)
next(self.nc.publish_request(request_q, self.responseQ, msgb))
except StopIteration as e:
pass
LOGGER.debug("natsd.Requester.call - waiting answer from " + self.responseQ)
else:
try:
LOGGER.debug("natsd.Requester.call - publish request " + str(typed_properties) + " on " + request_q)
next(self.nc.publish(request_q, b''+bytes(msg_data, 'utf8')))
except StopIteration as e:
pass
try:
next(self.nc.flush(1))
except StopIteration as e:
pass
start_time = timeit.default_timer()
if not self.fire_and_forget:
# Wait rpc_timeout sec before raising error
if self.rpc_timeout > 0:
exit_count = self.rpc_timeout * 100
else:
exit_count = 1
while self.response is None and exit_count > 0:
time.sleep(0.01)
if self.rpc_timeout > 0:
exit_count -= 1
if self.response is None:
if self.rpc_retry > 0:
if 'retry_count' not in my_args:
my_args['retry_count'] = 1
LOGGER.debug("natsd.Requester.call - Retry (" + str(my_args['retry_count']) + ")")