Skip to content

Commit

Permalink
Merge branch 'hotfix/readme1' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
aohan237 committed Nov 4, 2018
2 parents 731c389 + 9c1e0eb commit 98cf3dc
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pip install asyncnsq

--------------

All you need is a loop, then enjoy
All you need is a loop, then enjoy. you can refer to examples, as well.

Consumer:

Expand All @@ -62,11 +62,11 @@ from asyncnsq.utils import get_logger
loop = asyncio.get_event_loop()
async def go():
try:
nsq_consumer = await create_reader(
reader = await create_reader(
nsqd_tcp_addresses=['127.0.0.1:4150'],
max_in_flight=200)
await nsq_consumer.subscribe('test_async_nsq', 'nsq')
async for message in nsq_consumer.messages():
await reader.subscribe('test_async_nsq', 'nsq')
async for message in reader.messages():
print(message.body)
await message.fin()
except Exception as tmp:
Expand All @@ -79,7 +79,7 @@ Producer:
from asyncnsq import create_writer
loop = asyncio.get_event_loop()
async def go():
nsq_producer = await create_writer(host='127.0.0.1', port=4150,
writer = await create_writer(host='127.0.0.1', port=4150,
heartbeat_interval=30000,
feature_negotiation=True,
tls_v1=True,
Expand All @@ -88,8 +88,8 @@ async def go():
deflate_level=0,
loop=loop)
for i in range(100):
await nsq_producer.pub('test_async_nsq', 'test_async_nsq:{i}'.format(i=i))
await nsq_producer.dpub('test_async_nsq', i * 1000,
await writer.pub('test_async_nsq', 'test_async_nsq:{i}'.format(i=i))
await writer.dpub('test_async_nsq', i * 1000,
'test_delay_async_nsq:{i}'.format(i=i))
loop.run_until_complete(go())
```
Expand Down
12 changes: 6 additions & 6 deletions examples/consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ def main():

async def go():
try:
nsq_consumer = await create_reader(
reader = await create_reader(
lookupd_http_addresses=[
('127.0.0.1', 4161)],
max_in_flight=200)
await nsq_consumer.subscribe('test_async_nsq', 'nsq')
async for message in nsq_consumer.messages():
await reader.subscribe('test_async_nsq', 'nsq')
async for message in reader.messages():
print(message.body)
await message.fin()
except Exception as tmp:
Expand All @@ -34,11 +34,11 @@ def tcp_main():

async def go():
try:
nsq_consumer = await create_reader(
reader = await create_reader(
nsqd_tcp_addresses=['127.0.0.1:4150'],
max_in_flight=200)
await nsq_consumer.subscribe('test_async_nsq', 'nsq')
async for message in nsq_consumer.messages():
await reader.subscribe('test_async_nsq', 'nsq')
async for message in reader.messages():
print(message.body)
await message.fin()
except Exception as tmp:
Expand Down
22 changes: 11 additions & 11 deletions examples/producer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ def main():
loop = asyncio.get_event_loop()

async def go():
nsq_producer = await create_writer(host='127.0.0.1', port=4150,
heartbeat_interval=30000,
feature_negotiation=True,
tls_v1=True,
snappy=False,
deflate=False,
deflate_level=0,
loop=loop)
writer = await create_writer(host='127.0.0.1', port=4150,
heartbeat_interval=30000,
feature_negotiation=True,
tls_v1=True,
snappy=False,
deflate=False,
deflate_level=0,
loop=loop)
for i in range(100):
await nsq_producer.pub('test_async_nsq', 'test_async_nsq:{i}'.format(i=i))
await nsq_producer.dpub('test_async_nsq', i * 1000,
'test_delay_async_nsq:{i}'.format(i=i))
await writer.pub('test_async_nsq', 'test_async_nsq:{i}'.format(i=i))
await writer.dpub('test_async_nsq', i * 1000,
'test_delay_async_nsq:{i}'.format(i=i))

loop.run_until_complete(go())

Expand Down

0 comments on commit 98cf3dc

Please sign in to comment.