Ejemplo n.º 1
0
def _forward_stomp(operation: Operation, target_garden: Garden):
    try:
        conn = stomp_garden_connections[target_garden.name]

        if not conn.is_connected() and not conn.connect():
            raise ConnectFailedException()

        header_list = target_garden.connection_params["stomp"].get(
            "headers", {})
        conn_headers = {}
        for item in header_list:
            if "key" in item and "value" in item:
                conn_headers[item["key"]] = item["value"]

        body, model_headers = process(operation)
        headers = consolidate_headers(model_headers, conn_headers)

        conn.send(body=body, headers=headers)
    except ConnectFailedException:
        _publish_failed_forward(
            operation=operation,
            event_name=Events.GARDEN_UNREACHABLE.name,
            error_message=f"Attempted to forward operation to garden "
            f"'{operation.target_garden_name}' via STOMP but "
            f"failed to connect to STOMP. Please talk to your system "
            f"administrator.",
        )
        raise
Ejemplo n.º 2
0
    def connect(self,
                username=None,
                passcode=None,
                wait=False,
                headers={},
                **keyword_headers):
        """
        Send a STOMP CONNECT frame. Differs from 1.0 and 1.1 versions in that the HOST header is enforced.
        \param username
            optionally specify the login user
        \param passcode
            optionally specify the user password
        \param wait
            wait for the connection to complete before returning
        """
        cmd = CMD_STOMP
        headers = utils.merge_headers([headers, keyword_headers])
        headers[HDR_ACCEPT_VERSION] = self.version
        headers[HDR_HOST] = self.transport.current_host_and_port[0]

        if self.transport.vhost:
            headers[HDR_HOST] = self.transport.vhost

        if username is not None:
            headers[HDR_LOGIN] = username

        if passcode is not None:
            headers[HDR_PASSCODE] = passcode

        self.send_frame(cmd, headers)

        if wait:
            self.transport.wait_for_connection()
            if self.transport.connection_error:
                raise ConnectFailedException()
Ejemplo n.º 3
0
    def connect(self,
                username=None,
                passcode=None,
                wait=False,
                headers={},
                **keyword_headers):
        cmd = CMD_STOMP
        headers = utils.merge_headers([headers, keyword_headers])
        headers[HDR_ACCEPT_VERSION] = self.version

        if self.transport.vhost:
            headers[HDR_HOST] = self.transport.vhost

        if username is not None:
            headers[HDR_LOGIN] = username

        if passcode is not None:
            headers[HDR_PASSCODE] = passcode

        self.send_frame(cmd, headers)

        if wait:
            self.transport.wait_for_connection()
            if self.transport.connection_error:
                raise ConnectFailedException()
Ejemplo n.º 4
0
    def connect(self, username=None, passcode=None, wait=False, headers={}, **keyword_headers):
        """
        Start a connection.

        :param username: the username to connect with
        :param passcode: the password used to authenticate with
        :param wait: if True, wait for the connection to be established/acknowledged
        :param headers: a map of any additional headers the broker requires
        :param keyword_headers: any additional headers the broker requires
        """
        cmd = CMD_CONNECT
        headers = utils.merge_headers([headers, keyword_headers])
        headers[HDR_ACCEPT_VERSION] = self.version

        if username is not None:
            headers[HDR_LOGIN] = username

        if passcode is not None:
            headers[HDR_PASSCODE] = passcode

        self.send_frame(cmd, headers)

        if wait:
            self.transport.wait_for_connection()
            if self.transport.connection_error:
                raise ConnectFailedException()
Ejemplo n.º 5
0
def _forward_stomp(operation: Operation, target_garden: Garden) -> None:
    try:
        conn = stomp_garden_connections[target_garden.name]

        if not conn.is_connected() and not conn.connect():
            raise ConnectFailedException()

        header_list = target_garden.connection_params["stomp"].get(
            "headers", {})
        conn_headers = {}
        for item in header_list:
            if "key" in item and "value" in item:
                conn_headers[item["key"]] = item["value"]

        body, model_headers = process(operation)
        headers = consolidate_headers(model_headers, conn_headers)

        conn.send(body=body, headers=headers)
    except Exception as ex:
        raise ForwardException(
            message=("Failed to forward operation to garden "
                     f"'{operation.target_garden_name}' via STOMP."),
            operation=operation,
            event_name=Events.GARDEN_UNREACHABLE.name,
        ) from ex
Ejemplo n.º 6
0
    def connect(self,
                username=None,
                passcode=None,
                wait=False,
                timeout=None,
                headers=None,
                **keyword_headers):
        """
        Send a STOMP CONNECT frame. Differs from 1.0 and 1.1 versions in that the HOST header is enforced.

        :param str username: optionally specify the login user
        :param str passcode: optionally specify the user password
        :param bool wait: wait for the connection to complete before returning
        :param dict headers: a map of any additional headers to send with the subscription
        :param keyword_headers: any additional headers to send with the subscription
        """
        #        cmd = CMD_STOMP
        cmd = CMD_CONNECT
        headers = utils.merge_headers([headers, keyword_headers])
        headers[HDR_ACCEPT_VERSION] = self.version
        headers[HDR_HOST] = self.transport.current_host_and_port[0]

        if self.transport.vhost:
            headers[HDR_HOST] = self.transport.vhost

        if username is not None:
            headers[HDR_LOGIN] = username

        if passcode is not None:
            headers[HDR_PASSCODE] = passcode

        self.send_frame(cmd, headers)

        if wait:
            self.transport.wait_for_connection(timeout=timeout)
            if self.transport.connection_error:
                raise ConnectFailedException()