-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #225 from nats-io/example-doc-updates
Doc updates and version bump
- Loading branch information
Showing
24 changed files
with
475 additions
and
600 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import asyncio | ||
import nats | ||
from nats.errors import TimeoutError, NoServersError | ||
|
||
async def main(): | ||
async def disconnected_cb(): | ||
print('Got disconnected!') | ||
|
||
async def reconnected_cb(): | ||
print(f'Got reconnected to {nc.connected_url.netloc}') | ||
|
||
async def error_cb(e): | ||
print(f'There was an error: {e}') | ||
|
||
async def closed_cb(): | ||
print('Connection is closed') | ||
|
||
nc = await nats.connect('localhost:4222', | ||
error_cb=error_cb, | ||
reconnected_cb=reconnected_cb, | ||
disconnected_cb=disconnected_cb, | ||
closed_cb=closed_cb, | ||
) | ||
|
||
async def handler(msg): | ||
print(f'Received a message on {msg.subject} {msg.reply}: {msg.data}') | ||
await msg.respond(b'OK') | ||
sub = await nc.subscribe('help.please', cb=handler) | ||
|
||
resp = await nc.request('help.please', b'help') | ||
print('Response:', resp) | ||
|
||
if __name__ == '__main__': | ||
asyncio.run(main()) |
Oops, something went wrong.