Skip to content

Commit 818ea5f

Browse files
author
DanielePalaia
committed
WIP
1 parent c15a1a4 commit 818ea5f

File tree

13 files changed

+357
-22
lines changed

13 files changed

+357
-22
lines changed

examples/getting_started/Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.PHONY: main all
2+
3+
main:
4+
@echo "running excample"
5+
venv/bin/python3 ./main.py
6+
7+
init-python:
8+
@echo "init python venv"
9+
rm -rf venv
10+
python3 -m venv venv
11+
venv/bin/pip install -r requirements.txt

examples/getting_started/main.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# from proton import Message
2+
3+
from rabbitmq_amqp_python_client import (
4+
Connection,
5+
ExchangeSpecification,
6+
)
7+
8+
9+
def main():
10+
exchange_name = "example-exchange"
11+
connection = Connection("amqp://guest:guest@localhost:5672/")
12+
13+
connection.dial()
14+
15+
management = connection.management()
16+
17+
exchange_info = management.declare_exchange(
18+
ExchangeSpecification(name=exchange_name, arguments={})
19+
)
20+
21+
"""
22+
queue_info = management.declare_queue(QueueSpecification{
23+
name: queue_name,
24+
queue_type: QueueType{type: Quorum},
25+
})
26+
"""
27+
28+
"""
29+
#management.bind(BindingSpecification{
30+
source_exchange: exchange_name,
31+
destination_queue: queue_name,
32+
binding_key: routing_key,
33+
})
34+
"""
35+
36+
"""
37+
addr = exchange_address(exchange_name, routing_key)
38+
"""
39+
40+
"""
41+
publisher = connection.publisher(addr, "getting-started-publisher")
42+
"""
43+
44+
"""
45+
message = Message(
46+
body='test',
47+
address='/queues/getting-started-exchangemessage',
48+
)
49+
50+
publisher.Publish(message)
51+
publisher.close()
52+
"""
53+
54+
"""
55+
management.unbind(binding_path)
56+
"""
57+
58+
"""
59+
management.purge_queue(queue_info.name)
60+
"""
61+
62+
"""
63+
management.delete_queue(queue_info.name)
64+
"""
65+
66+
"""
67+
management.delete_exchange(exchange_info.name)
68+
"""
69+
70+
# connection.close()
71+
72+
73+
if __name__ == "__main__":
74+
main()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/Users/dpalaia/projects/rabbitmq-amqp-python-client

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "rabbitmq-amqp-python-client"
3-
version = "0.1.0"
3+
version = "0.0.1"
44
description = "Python RabbitMQ client for AMQP 1.0 protocol"
55
authors = ["RabbitMQ team"]
66
license = "Apache-2.0 license"
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from importlib import metadata
2+
3+
from .connection import Connection
4+
from .entities import ExchangeSpecification
5+
6+
try:
7+
__version__ = metadata.version(__package__)
8+
__license__ = metadata.metadata(__package__)["license"]
9+
except metadata.PackageNotFoundError:
10+
__version__ = "dev"
11+
__license__ = None
12+
13+
del metadata
14+
15+
__all__ = [
16+
"Connection",
17+
"ExchangeSpecification",
18+
]
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
def exchange_address(name: str) -> str:
2+
path = "/exchanges/" + name
3+
4+
return path

rabbitmq_amqp_python_client/amqp_connection.py

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import enum
2+
3+
4+
class CommonValues(enum.Enum):
5+
response_code_200 = 200
6+
response_code_201 = 201
7+
response_code_204 = 204
8+
response_code_404 = 404
9+
response_code_409 = 409
10+
command_put = "PUT"
11+
command_get = "GET"
12+
command_post = "POST"
13+
command_delete = "DELETE"
14+
command_reply_to = "$me"
15+
management_node_address = "/management"
16+
link_pair_name = "management-link-pair"
17+
exchanges = "exchanges"
18+
key = "key"
19+
queue = "queues"
20+
bindings = "bindings"
21+
22+
23+
class ExchangeTypes(enum.Enum):
24+
direct = "direct"
25+
topic = "topic"
26+
fanout = "fanout"
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from proton._data import PropertyDict, symbol # noqa: E402
2+
from proton._endpoints import Link # noqa: E402
3+
from proton.reactor import LinkOption # noqa: E402
4+
5+
6+
class SenderOption(LinkOption):
7+
def __init__(self, addr: str):
8+
self._addr = addr
9+
10+
def apply(self, link: Link) -> None:
11+
link.source.address = self._addr
12+
link.snd_settle_mode = Link.SND_SETTLED
13+
link.rcv_settle_mode = Link.RCV_FIRST
14+
link.properties = PropertyDict({symbol("paired"): True})
15+
link.source.dynamic = False
16+
17+
def test(self, link: Link) -> bool:
18+
return bool(link.is_sender)
19+
20+
21+
class ReceiverOption(LinkOption):
22+
def __init__(self, addr: str):
23+
self._addr = addr
24+
25+
def apply(self, link: Link) -> None:
26+
link.target.address = self._addr
27+
link.snd_settle_mode = Link.SND_SETTLED
28+
link.rcv_settle_mode = Link.RCV_FIRST
29+
link.properties = PropertyDict({symbol("paired"): True})
30+
link.source.dynamic = False
31+
32+
def test(self, link: Link) -> bool:
33+
return bool(link.is_receiver)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from proton.utils import (
2+
BlockingConnection,
3+
BlockingReceiver,
4+
BlockingSender,
5+
)
6+
7+
from .configuration_options import (
8+
ReceiverOption,
9+
SenderOption,
10+
)
11+
from .management import Management
12+
13+
14+
class Connection:
15+
def __init__(self, addr: str):
16+
self._addr: str = addr
17+
self._conn: BlockingConnection
18+
self._management: Management
19+
20+
def dial(self) -> None:
21+
self._conn = BlockingConnection(self._addr)
22+
self._open()
23+
24+
def _open(self) -> None:
25+
self._management = Management(self._conn)
26+
self._management.open()
27+
28+
def management(self) -> Management:
29+
return self._management
30+
31+
# closes the connection to the AMQP 1.0 server.
32+
def close(self) -> None:
33+
self._conn.close()
34+
35+
# TODO: returns the current status of the connection.
36+
# def status(self) -> int:
37+
# pass

0 commit comments

Comments
 (0)