Skip to content
Snippets Groups Projects
Commit 3b01321a authored by Piotr Maślanka's avatar Piotr Maślanka
Browse files

Merge branch 'feature-#2' into 'develop'

fixes #2

Closes #2

See merge request !2
parents 1c926ee9 4133a705
No related branches found
No related tags found
1 merge request!2fixes #2
Pipeline #63197 canceled with stages
in 1 minute and 17 seconds
__version__ = '1.4.4a1'
__version__ = '1.5.0a1'
......@@ -348,6 +348,13 @@ class Cluster(object):
raise ConnectionDead(
'[%s] Could not connect within %s seconds' % (self.name, timeout,))
@property
def properties(self):
"""
Return a :class:`coolamqp.object.ServerProperties` if a connection was established
"""
return self.snr.properties
def shutdown(self, wait=True): # type: (bool) -> None
"""
Terminate all connections, release resources - finish the job.
......
......@@ -18,6 +18,10 @@ class SingleNodeReconnector(object):
Connection to one node. It will do it's best to remain alive.
"""
@property
def properties(self):
return self.connection.properties
def __init__(self, node_def, # type: coolamqp.objects.NodeDefinition
attache_group, # type: coolamqp.attaches.AttacheGroup
listener_thread, # type: coolamqp.uplink.ListenerThread
......
......@@ -10,7 +10,6 @@ import warnings
import six
from coolamqp.framing.base import AMQPFrame
from coolamqp.framing.definitions import \
BasicContentPropertyList as MessageProperties
from coolamqp.framing.field_table import get_type_for
......@@ -232,6 +231,37 @@ class Exchange(object):
Exchange.direct = Exchange()
class ServerProperties(object):
"""
An object describing properties of the target server.
:ivar version: tuple of (major version, minor version)
:ivar properties: dictionary of properties (key str, value any)
:ivar mechanisms: a list of strings, supported auth mechanisms
:ivar locales: locale in use
"""
__slots__ = ('version', 'properties', 'mechanisms', 'locales')
def __init__(self, data):
self.version = data.version_major, data.version_minor
self.properties = {}
for prop_name, prop_value in data.server_properties:
prop_name = toutf8(prop_name)
prop_value = prop_value[0]
if isinstance(prop_value, memoryview):
prop_value = prop_value.tobytes().decode('utf-8')
elif isinstance(prop_value, list):
prop_value = [toutf8(prop[0]) for prop in prop_value]
self.properties[prop_name] = prop_value
self.mechanisms = data.mechanisms.tobytes().decode('utf-8').split(' ')
self.locales = data.locales.tobytes().decode('utf-8')
def __str__(self):
return '%s %s %s %s' % (self.version, repr(self.properties), self.mechanisms, self.locales)
class Queue(object):
"""
This object represents a Queue that applications consume from or publish to.
......
......@@ -119,6 +119,7 @@ class Connection(object):
self.frame_max = None
self.heartbeat = None
self.extensions = []
self.properties = None
# To be filled in later
self.listener_socket = None
......
......@@ -13,6 +13,8 @@ from coolamqp.framing.definitions import ConnectionStart, ConnectionStartOk, \
from coolamqp.framing.frames import AMQPMethodFrame
from coolamqp.uplink.connection.states import ST_ONLINE
from coolamqp.uplink.heartbeat import Heartbeater
from coolamqp.objects import ServerProperties
from coolamqp import __version__
PUBLISHER_CONFIRMS = b'publisher_confirms'
......@@ -100,7 +102,7 @@ class Handshaker(object):
if label in SUPPORTED_EXTENSIONS:
if fv[0]:
self.connection.extensions.append(label)
self.connection.properties = ServerProperties(payload)
self.connection.watchdog(WATCHDOG_TIMEOUT, self.on_watchdog)
self.connection.watch_for_method(0, ConnectionTune,
self.on_connection_tune)
......
......@@ -34,3 +34,11 @@ Take care, as :class:`~coolamqp.objects.MessageProperties` will hash the
keys found and store it within non-GCable memory. So each "variant" of message
properties encountered will be compiled as a separate class.
Who am I talking to?
--------------------
:class:`coolamqp.clustering.Cluster` has a nice property, that will return None until the connection is established.
If it is, it will return something like this:
.. autoclass:: coolamqp.objects.ServerProperties
:members:
......@@ -48,7 +48,7 @@ master_doc = 'index'
# General information about the project.
project = u'CoolAMQP'
copyright = u'2016-2020, SMOK sp. z o. o.'
copyright = u'2016-2024, SMOK sp. z o. o.'
author = u'SMOK sp. z o. o.'
# The version info for the project you're documenting, acts as replacement for
......
......@@ -23,11 +23,14 @@ logging.basicConfig(level=logging.DEBUG)
class TestA(unittest.TestCase):
def setUp(self):
self.c = Cluster([NODE])
self.c.start()
self.c.start(timeout=20)
def tearDown(self):
self.c.shutdown()
def test_properties(self):
self.assertEqual(self.c.properties.properties['product'], 'RabbitMQ')
def test_queue_bind(self):
queue = Queue('my-queue')
exchange = Exchange('my-exchange', type='topic')
......
......@@ -77,7 +77,7 @@ class TestConnecting(unittest.TestCase):
def test_start_called_multiple_times(self):
c = Cluster([NODE])
c.start(wait=True)
c.start(wait=True, timeout=20)
self.assertRaises(RuntimeError, lambda: c.start())
c.shutdown(wait=True)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment