Skip to content

Commit c8a9e33

Browse files
committed
initial commit
0 parents  commit c8a9e33

File tree

6 files changed

+321
-0
lines changed

6 files changed

+321
-0
lines changed

Diff for: .gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.idea
2+
.venv
3+
.env

Diff for: compose.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: "3.8"
2+
services:
3+
rabbitmq:
4+
image: rabbitmq:3.10.7-management
5+
ports:
6+
- 5672:5672

Diff for: poetry.lock

+248
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: pyproject.toml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[tool.poetry]
2+
name = "tutorial-aiopika"
3+
version = "0.1.0"
4+
description = ""
5+
authors = ["Your Name <[email protected]>"]
6+
readme = "README.md"
7+
packages = [{include = "tutorial_aiopika"}]
8+
9+
[tool.poetry.dependencies]
10+
python = "^3.11"
11+
aio-pika = "^9.4.0"
12+
13+
14+
[build-system]
15+
requires = ["poetry-core"]
16+
build-backend = "poetry.core.masonry.api"

Diff for: receive.py

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import asyncio
2+
3+
from aio_pika import connect
4+
from aio_pika.abc import AbstractIncomingMessage
5+
6+
7+
async def on_message(message: AbstractIncomingMessage) -> None:
8+
print(" [x] Received message %r" % message)
9+
print("Message body is: %r" % message.body)
10+
11+
print("Before sleep!")
12+
await asyncio.sleep(5)
13+
print("After sleep!")
14+
15+
async def main() -> None:
16+
connection = await connect("amqp://guest:guest@localhost/")
17+
async with connection:
18+
channel = await connection.channel()
19+
queue = await channel.declare_queue("hello")
20+
await queue.consume(on_message, no_ack=True)
21+
print(" [x] Waiting for messages. To exit press CTRL + C")
22+
await asyncio.Future()
23+
24+
if __name__ == '__main__':
25+
asyncio.run(main())
26+

Diff for: send.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import asyncio
2+
3+
from aio_pika import Message, connect
4+
5+
6+
async def main() -> None:
7+
connection = await connect("amqp://guest:guest@localhost/")
8+
9+
async with connection:
10+
channel = await connection.channel()
11+
12+
queue = await channel.declare_queue("hello")
13+
14+
await channel.default_exchange.publish(
15+
Message(b"Hello World!"),
16+
routing_key=queue.name,
17+
)
18+
19+
print(" [x] Sent ' HELLO WORLD!'")
20+
21+
if __name__ == '__main__':
22+
asyncio.run(main())

0 commit comments

Comments
 (0)