Ejemplo n.º 1
0
    def test_open_already(self, blocking):
        url = 'test-url'
        connection = Connection(url)
        connection.is_open = Mock(return_value=True)

        # test
        connection.open()

        # validation
        self.assertFalse(blocking.called)
Ejemplo n.º 2
0
    def test_open_already(self, blocking):
        url = 'test-url'
        connection = Connection(url)
        connection.is_open = Mock(return_value=True)

        # test
        connection.open()

        # validation
        self.assertFalse(blocking.called)
Ejemplo n.º 3
0
class Sender(BaseSender):
    """
    An AMQP message sender.
    :ivar connection: A proton connection.
    :type connection: Connection
    """
    def __init__(self, url):
        """
        :param url: The broker url.
        :type url: str
        """
        BaseSender.__init__(self, url)
        self.connection = Connection(url)

    def is_open(self):
        """
        Get whether the messenger has been opened.
        :return: True if open.
        :rtype bool
        """
        return self.connection.is_open()

    @reliable
    def open(self):
        """
        Open the sender.
        """
        if self.is_open():
            # already opened
            return
        self.connection.open()

    def repair(self):
        """
        Repair the sender.
        """
        self.close()
        self.connection.close()
        self.connection.open()

    def close(self):
        """
        Close the sender.
        """
        pass

    @resend
    def send(self, address, content, ttl=None):
        """
        Send a message.
        :param address: An AMQP address.
        :type address: str
        :param content: The message content
        :type content: buf
        :param ttl: Time to Live (seconds)
        :type ttl: float
        """
        sender = self.connection.sender(address)
        try:
            message = build_message(content, ttl, self.durable)
            sender.send(message)
            log.debug('sent (%s)', address)
        finally:
            sender.close()
Ejemplo n.º 4
0
 def test_is_open(self):
     connection = Connection('')
     self.assertFalse(connection.is_open())
     connection._impl = Mock()
     self.assertTrue(connection.is_open())
Ejemplo n.º 5
0
 def test_is_open(self):
     connection = Connection('')
     self.assertFalse(connection.is_open())
     connection._impl = Mock()
     self.assertTrue(connection.is_open())
Ejemplo n.º 6
0
class Sender(BaseSender):
    """
    An AMQP message sender.
    :ivar connection: A proton connection.
    :type connection: Connection
    """

    def __init__(self, url):
        """
        :param url: The broker url.
        :type url: str
        """
        BaseSender.__init__(self, url)
        self.connection = Connection(url)

    def is_open(self):
        """
        Get whether the messenger has been opened.
        :return: True if open.
        :rtype bool
        """
        return self.connection.is_open()

    @reliable
    def open(self):
        """
        Open the sender.
        """
        if self.is_open():
            # already opened
            return
        self.connection.open()

    def repair(self):
        """
        Repair the sender.
        """
        self.close()
        self.connection.close()
        self.connection.open()

    def close(self):
        """
        Close the sender.
        """
        pass

    @resend
    def send(self, address, content, ttl=None):
        """
        Send a message.
        :param address: An AMQP address.
        :type address: str
        :param content: The message content
        :type content: buf
        :param ttl: Time to Live (seconds)
        :type ttl: float
        """
        sender = self.connection.sender(address)
        try:
            message = build_message(content, ttl, self.durable)
            sender.send(message)
            log.debug('sent (%s)', address)
        finally:
            sender.close()