amqp-client-python 0.1.13__py3-none-any.whl → 0.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. amqp_client_python/__init__.py +1 -0
  2. amqp_client_python/domain/models/config.py +40 -4
  3. amqp_client_python/domain/models/options.py +35 -3
  4. amqp_client_python/domain/models/ssl_options.py +16 -0
  5. amqp_client_python/domain/utils/__init__.py +2 -0
  6. amqp_client_python/domain/utils/connection_type.py +8 -0
  7. amqp_client_python/domain/utils/types.py +7 -0
  8. amqp_client_python/event/__init__.py +4 -0
  9. amqp_client_python/event/async_provider_handler.py +9 -0
  10. amqp_client_python/event/async_subscriber_handler.py +9 -0
  11. amqp_client_python/event/event.py +6 -0
  12. amqp_client_python/event/provider_handler.py +9 -0
  13. amqp_client_python/event/subscriber_handler.py +9 -0
  14. amqp_client_python/exceptions/auto_reconnect_exception.py +2 -2
  15. amqp_client_python/exceptions/blocking_exception.py +3 -3
  16. amqp_client_python/exceptions/eventbus_exception.py +3 -3
  17. amqp_client_python/exceptions/nack_exception.py +2 -2
  18. amqp_client_python/exceptions/publish_timeout_exception.py +2 -2
  19. amqp_client_python/exceptions/response_timeout_exception.py +2 -2
  20. amqp_client_python/exceptions/rpc_provider_exception.py +3 -3
  21. amqp_client_python/exceptions/thread_unsafe_exception.py +3 -3
  22. amqp_client_python/exceptions/timeout_exception.py +2 -2
  23. amqp_client_python/py.typed +0 -0
  24. amqp_client_python/rabbitmq/__init__.py +1 -1
  25. amqp_client_python/rabbitmq/async_channel.py +149 -100
  26. amqp_client_python/rabbitmq/async_channel_factory.py +6 -1
  27. amqp_client_python/rabbitmq/async_connection.py +47 -46
  28. amqp_client_python/rabbitmq/async_connection_factory.py +4 -3
  29. amqp_client_python/rabbitmq/async_eventbus_rabbitmq.py +215 -41
  30. amqp_client_python/rabbitmq/channel_factory_rabbitmq.py +3 -1
  31. amqp_client_python/rabbitmq/channel_rabbitmq.py +32 -21
  32. amqp_client_python/rabbitmq/connection_factory_rabbitmq.py +4 -3
  33. amqp_client_python/rabbitmq/connection_rabbitmq.py +18 -12
  34. amqp_client_python/rabbitmq/eventbus_rabbitmq.py +32 -12
  35. amqp_client_python/rabbitmq/eventbus_wrapper_rabbitmq.py +63 -29
  36. amqp_client_python/rabbitmq/ioloop_factory.py +3 -2
  37. amqp_client_python/signals.py +42 -0
  38. {amqp_client_python-0.1.13.dist-info → amqp_client_python-0.2.0.dist-info}/METADATA +71 -58
  39. amqp_client_python-0.2.0.dist-info/RECORD +45 -0
  40. {amqp_client_python-0.1.13.dist-info → amqp_client_python-0.2.0.dist-info}/WHEEL +1 -1
  41. amqp_client_python-0.1.13.dist-info/RECORD +0 -35
  42. {amqp_client_python-0.1.13.dist-info → amqp_client_python-0.2.0.dist-info}/LICENSE +0 -0
@@ -1,3 +1,4 @@
1
1
  from .rabbitmq import EventbusRabbitMQ, AsyncEventbusRabbitMQ, EventbusWrapperRabbitMQ
2
2
  from .domain.models import Config, Options, SSLOptions
3
+ from .domain.utils import ConnectionType
3
4
  from pika import DeliveryMode
@@ -9,22 +9,58 @@ class Config:
9
9
  def __init__(
10
10
  self, options: Options, ssl_options: Optional[SSLOptions] = None
11
11
  ) -> None:
12
+ """
13
+ Create an Config object thats hold and mount the connection information.
14
+
15
+ Args:
16
+ options: hold information for estabilish connection
17
+ ssl_options: hold information for estabilish SSL connections
18
+
19
+ Returns:
20
+
21
+ Raises:
22
+
23
+ Examples:
24
+ >>> Config(
25
+ Options("example", "example.rpc", "example.rpc", "amqp://admin:admin@localhost:5672/"),
26
+ SSLOptions("./.certs/cert.pem", "./.certs/privkey.pem", "./.certs/ca.pem")
27
+ )
28
+ """
12
29
  self.url = None
13
30
  self.options = options
14
31
  self.ssl_options = ssl_options
15
32
 
16
- def build(self):
33
+ def build(self) -> "Config":
34
+ """
35
+ Create an Config object thats hold and mount the connection information.
36
+
37
+ Args:
38
+
39
+ Returns:
40
+ Config object
41
+
42
+ Raises:
43
+
44
+ Examples:
45
+ >>> config.build()
46
+ """
17
47
  opt = {
18
48
  **self.options.kwargs,
19
49
  "heartbeat": self.options.heartbeat,
20
50
  }
21
- if bool(self.ssl_options):
51
+ if self.ssl_options is not None:
52
+ protocol = "amqps"
53
+ if self.options.port is None:
54
+ self.options.port = 5671
22
55
  opt["ssl_options"] = {
23
- "certfile": self.ssl_options.certfile_path,
24
56
  "keyfile": self.ssl_options.keyfile_path,
57
+ "certfile": self.ssl_options.certfile_path,
25
58
  "ca_certs": self.ssl_options.ca_certs_path,
26
59
  }
27
- protocol = "amqps" if bool(self.ssl_options) else "amqp"
60
+ else:
61
+ protocol = "amqp"
62
+ if self.options.port is None:
63
+ self.options.port = 5672
28
64
  if self.options.uri:
29
65
  url = "{}?{} ".format(self.options.uri, urlencode(opt))
30
66
  else:
@@ -7,16 +7,48 @@ class Options:
7
7
  queue_name: str,
8
8
  rpc_queue_name: str,
9
9
  rpc_exchange_name: str,
10
- uri: str = None,
10
+ uri: Optional[str] = None,
11
11
  login: str = "guest",
12
12
  passwd: str = "guest",
13
13
  domain: str = "localhost",
14
- port: int = 5672,
14
+ port: Optional[int] = None,
15
15
  vhost: str = "/",
16
16
  heartbeat: Optional[int] = 60,
17
- publisher_confirms=False,
17
+ publisher_confirms: bool = False,
18
18
  **kwargs: Dict[str, Any]
19
19
  ) -> None:
20
+ """
21
+ Create an Options object that hold the credentials and configs options.
22
+
23
+ Args:
24
+ queue_name: name of queue that will be used for subscriptions
25
+ rpc_queue_name: name of queue that will be used for provide resources
26
+ rpc_exchange_name: name of exchange that will be used for provide resources
27
+ uri: uri for connection
28
+ login: username
29
+ passwd: password
30
+ domain: domain
31
+ port: port information
32
+ vhost: vhost information
33
+ heartbeat: interval between heartbeat
34
+ publisher_confirms: wait for publisher confirmations
35
+ **kwargs: pika options
36
+
37
+ Returns:
38
+
39
+ Raises:
40
+
41
+ Examples:
42
+ >>> Options("example", "example.rpc", "example.rpc", "amqp://admin:admin@localhost:5672/")
43
+
44
+ >>> Options("example", "example.rpc", "example.rpc", "amqps://admin:admin@localhost:5671/")
45
+
46
+ >>> Options("example", "example.rpc", "example.rpc", login="admin", passwd="admin",
47
+ domain="localhost", port=5672)
48
+
49
+ >>> Options("example", "example.rpc", "example.rpc", login="admin", passwd="admin",
50
+ domain="localhost", port=5671)
51
+ """
20
52
  self.queue_name = queue_name
21
53
  self.rpc_queue_name = rpc_queue_name
22
54
  self.rpc_exchange_name = rpc_exchange_name
@@ -2,6 +2,22 @@ class SSLOptions:
2
2
  def __init__(
3
3
  self, certfile_path: str, keyfile_path: str, ca_certs_path: str
4
4
  ) -> None:
5
+ """
6
+ Create an SslOptions object that hold the certs paths.
7
+
8
+ Args:
9
+ certfile_path: cert file path string
10
+ keyfile_path: private key file path string
11
+ ca_certs_path: ca file path string
12
+
13
+ Returns:
14
+ Um dicionário com as notas da escala e os graus.
15
+
16
+ Raises:
17
+
18
+ Examples:
19
+ >>> SSLOptions("./.certs/cert.pem", "./.certs/privkey.pem", "./.certs/ca.pem")
20
+ """
5
21
  self.certfile_path = certfile_path
6
22
  self.keyfile_path = keyfile_path
7
23
  self.ca_certs_path = ca_certs_path
@@ -0,0 +1,2 @@
1
+ from .connection_type import ConnectionType
2
+ from .types import HandlerType
@@ -0,0 +1,8 @@
1
+ from enum import Enum
2
+
3
+
4
+ class ConnectionType(Enum):
5
+ PUBLISH = "publish"
6
+ SUBSCRIBE = "subscribe"
7
+ RPC_CLIENT = "rpc_client"
8
+ RPC_SERVER = "rpc_server"
@@ -0,0 +1,7 @@
1
+ from typing import TypedDict, Optional, Callable
2
+
3
+
4
+ class HandlerType(TypedDict):
5
+ response_timeout: Optional[int]
6
+ handle: Callable
7
+ content_type: str
@@ -1,2 +1,6 @@
1
1
  from .integration_event import IntegrationEvent
2
2
  from .integration_event_handler import IntegrationEventHandler
3
+ from .async_provider_handler import AsyncProviderHandler
4
+ from .async_subscriber_handler import AsyncSubscriberHandler
5
+ from .provider_handler import ProviderHandler
6
+ from .subscriber_handler import SubscriberHandler
@@ -0,0 +1,9 @@
1
+ from typing import Union, List, Any
2
+ from abc import ABC, abstractmethod
3
+
4
+
5
+ class AsyncProviderHandler(ABC):
6
+
7
+ @abstractmethod
8
+ async def handle(self, body: List[Any]) -> Union[bytes, str]:
9
+ raise NotImplementedError
@@ -0,0 +1,9 @@
1
+ from typing import List, Any
2
+ from abc import ABC, abstractmethod
3
+
4
+
5
+ class AsyncSubscriberHandler(ABC):
6
+
7
+ @abstractmethod
8
+ async def handle(self, body: List[Any]) -> None:
9
+ raise NotImplementedError
@@ -0,0 +1,6 @@
1
+ from enum import Enum
2
+
3
+
4
+ class Event(Enum):
5
+ CONNECTED = "connected"
6
+ CONNECTING_BEFORE = "connecting.before"
@@ -0,0 +1,9 @@
1
+ from typing import Union, List, Any
2
+ from abc import ABC, abstractmethod
3
+
4
+
5
+ class ProviderHandler(ABC):
6
+
7
+ @abstractmethod
8
+ def handle(self, body: List[Any]) -> Union[bytes, str]:
9
+ raise NotImplementedError
@@ -0,0 +1,9 @@
1
+ from typing import List, Any
2
+ from abc import ABC, abstractmethod
3
+
4
+
5
+ class SubscriberHandler(ABC):
6
+
7
+ @abstractmethod
8
+ def handle(self, body: List[Any]) -> None:
9
+ raise NotImplementedError
@@ -2,8 +2,8 @@ from .eventbus_exception import EventBusException
2
2
 
3
3
 
4
4
  class AutoReconnectException(EventBusException):
5
- message: str = None
6
- description: str = None
5
+ message: str = ""
6
+ description: str = ""
7
7
 
8
8
  def __init__(self, message, description="") -> None:
9
9
  self.message = message
@@ -2,9 +2,9 @@ from .eventbus_exception import EventBusException
2
2
 
3
3
 
4
4
  class BlockingException(EventBusException):
5
- message: str = None
6
- description: str = None
5
+ message: str = ""
6
+ description: str = ""
7
7
 
8
- def __init__(self, message, description="") -> None:
8
+ def __init__(self, message: str, description="") -> None:
9
9
  self.message = message
10
10
  self.description = description
@@ -1,7 +1,7 @@
1
1
  class EventBusException(Exception):
2
- message: str = None
3
- description: str = None
2
+ message: str = ""
3
+ description: str = ""
4
4
 
5
- def __init__(self, message, description="") -> None:
5
+ def __init__(self, message: str, description="") -> None:
6
6
  self.message = message
7
7
  self.description = description
@@ -2,8 +2,8 @@ from .eventbus_exception import EventBusException
2
2
 
3
3
 
4
4
  class NackException(EventBusException):
5
- message: str = None
6
- description: str = None
5
+ message: str = ""
6
+ description: str = ""
7
7
 
8
8
  def __init__(self, message, description="") -> None:
9
9
  self.message = message
@@ -2,8 +2,8 @@ from .timeout_exception import TimeoutException
2
2
 
3
3
 
4
4
  class PublishTimeoutException(TimeoutException):
5
- message: str = None
6
- description: str = None
5
+ message: str = ""
6
+ description: str = ""
7
7
 
8
8
  def __init__(self, message, description="") -> None:
9
9
  self.message = message
@@ -2,8 +2,8 @@ from .timeout_exception import TimeoutException
2
2
 
3
3
 
4
4
  class ResponseTimeoutException(TimeoutException):
5
- message: str = None
6
- description: str = None
5
+ message: str = ""
6
+ description: str = ""
7
7
 
8
8
  def __init__(self, message, description="") -> None:
9
9
  self.message = message
@@ -2,9 +2,9 @@ from .eventbus_exception import EventBusException
2
2
 
3
3
 
4
4
  class RpcProviderException(EventBusException):
5
- message: str = None
6
- description: str = None
5
+ message: str = ""
6
+ description: str = ""
7
7
 
8
- def __init__(self, message, description="") -> None:
8
+ def __init__(self, message: str, description="") -> None:
9
9
  self.message = message
10
10
  self.description = description
@@ -2,9 +2,9 @@ from .eventbus_exception import EventBusException
2
2
 
3
3
 
4
4
  class ThreadUnsafeException(EventBusException):
5
- message: str = None
6
- description: str = None
5
+ message: str = ""
6
+ description: str = ""
7
7
 
8
- def __init__(self, message, description="") -> None:
8
+ def __init__(self, message: str, description="") -> None:
9
9
  self.message = message
10
10
  self.description = description
@@ -2,8 +2,8 @@ from .eventbus_exception import EventBusException
2
2
 
3
3
 
4
4
  class TimeoutException(EventBusException):
5
- message: str = None
6
- description: str = None
5
+ message: str = ""
6
+ description: str = ""
7
7
 
8
8
  def __init__(self, message, description="") -> None:
9
9
  self.message = message
File without changes
@@ -1,6 +1,6 @@
1
1
  from .async_eventbus_rabbitmq import AsyncEventbusRabbitMQ
2
2
  from .async_connection_factory import AsyncConnectionFactoryRabbitMQ
3
- from .async_connection import AsyncConnection
3
+ from .async_connection import AsyncConnection, ConnectionType
4
4
  from .async_channel_factory import AsyncChannelFactoryRabbitMQ
5
5
  from .async_channel import AsyncChannel
6
6
  from .eventbus_rabbitmq import EventbusRabbitMQ