def delete_topic(self, topic_name, fail_not_exist=False):
     '''
     Deletes an existing topic. This operation will also remove all associated state 
     including associated subscriptions.
     
     topic_name: name of the topic.
     fail_not_exist: specify whether throw exception when topic doesn't exist.
     '''
     _validate_not_none('topic_name', topic_name)
     request = HTTPRequest()
     request.method = 'DELETE'
     request.host = self.service_namespace + SERVICE_BUS_HOST_BASE
     request.path = '/' + str(topic_name) + ''
     request.path, request.query = _update_request_uri_query(request)
     request.headers = _update_service_bus_header(request, self.account_key, self.issuer)
     if not fail_not_exist:
         try:
             self._perform_request(request)
             return True
         except WindowsAzureError as e:
             _dont_fail_not_exist(e)
             return False
     else:
         self._perform_request(request)
         return True
    def delete_topic(self, topic_name, fail_not_exist=False):
        '''
        Deletes an existing topic. This operation will also remove all
        associated state including associated subscriptions.

        topic_name:
            Name of the topic to delete.
        fail_not_exist:
            Specify whether throw exception when topic doesn't exist.
        '''
        _validate_not_none('topic_name', topic_name)
        request = HTTPRequest()
        request.method = 'DELETE'
        request.host = self._get_host()
        request.path = '/' + _str(topic_name) + ''
        request.path, request.query = _update_request_uri_query(request)
        request.headers = self._update_service_bus_header(request)
        if not fail_not_exist:
            try:
                self._perform_request(request)
                return True
            except WindowsAzureError as ex:
                _dont_fail_not_exist(ex)
                return False
        else:
            self._perform_request(request)
            return True
Exemple #3
0
 def delete_rule(self, topic_name, subscription_name, rule_name, fail_not_exist=False):
     '''
     Deletes an existing rule.
     
     topic_name: Name of the topic.
     subscription_name: Name of the subscription.
     rule_name:
         Name of the rule to delete.  DEFAULT_RULE_NAME=$Default. 
         Use DEFAULT_RULE_NAME to delete default rule for the subscription.
     fail_not_exist:
         Specify whether throw exception when rule doesn't exist.
     '''
     _validate_not_none('topic_name', topic_name)
     _validate_not_none('subscription_name', subscription_name)
     _validate_not_none('rule_name', rule_name)
     request = HTTPRequest()
     request.method = 'DELETE'
     request.host = self._get_host()
     request.path = '/' + _str(topic_name) + '/subscriptions/' + _str(subscription_name) + '/rules/' + _str(rule_name) + ''
     request.path, request.query = _update_request_uri_query(request)
     request.headers = self._update_service_bus_header(request)
     if not fail_not_exist:
         try:
             self._perform_request(request)
             return True
         except WindowsAzureError as e:
             _dont_fail_not_exist(e)
             return False
     else:
         self._perform_request(request)
         return True
 def delete_subscription(self, topic_name, subscription_name, fail_not_exist=False):
     '''
     Deletes an existing subscription.
     
     topic_name: the name of the topic
     subscription_name: the name of the subscription
     fail_not_exist: specify whether to throw an exception when the subscription doesn't exist.
     '''
     _validate_not_none('topic_name', topic_name)
     _validate_not_none('subscription_name', subscription_name)
     request = HTTPRequest()
     request.method = 'DELETE'
     request.host = self.service_namespace + SERVICE_BUS_HOST_BASE
     request.path = '/' + str(topic_name) + '/subscriptions/' + str(subscription_name) + ''
     request.path, request.query = _update_request_uri_query(request)
     request.headers = _update_service_bus_header(request, self.account_key, self.issuer)
     if not fail_not_exist:
         try:
             self._perform_request(request)
             return True
         except WindowsAzureError as e:
             _dont_fail_not_exist(e)
             return False
     else:
         self._perform_request(request)
         return True
 def create_rule(self, topic_name, subscription_name, rule_name, rule=None, fail_on_exist=False):
     '''
     Creates a new rule. Once created, this rule's resource manifest is immutable.
     
     topic_name: the name of the topic
     subscription_name: the name of the subscription
     rule_name: name of the rule.
     fail_on_exist: specify whether to throw an exception when the rule exists.
     '''
     _validate_not_none('topic_name', topic_name)
     _validate_not_none('subscription_name', subscription_name)
     _validate_not_none('rule_name', rule_name)
     request = HTTPRequest()
     request.method = 'PUT'
     request.host = self._get_host()
     request.path = '/' + str(topic_name) + '/subscriptions/' + str(subscription_name) + '/rules/' + str(rule_name) + ''
     request.body = _get_request_body(convert_rule_to_xml(rule))
     request.path, request.query = _update_request_uri_query(request)
     request.headers = _update_service_bus_header(request, self.account_key, self.issuer)
     if not fail_on_exist:
         try:
             self._perform_request(request)
             return True
         except WindowsAzureError as e:
             _dont_fail_on_exist(e)
             return False
     else:
         self._perform_request(request)
         return True
    def create_subscription(self, topic_name, subscription_name,
                            subscription=None, fail_on_exist=False):
        '''
        Creates a new subscription. Once created, this subscription resource
        manifest is immutable.

        topic_name:
            Name of the topic.
        subscription_name:
            Name of the subscription.
        fail_on_exist:
            Specify whether throw exception when subscription exists.
        '''
        _validate_not_none('topic_name', topic_name)
        _validate_not_none('subscription_name', subscription_name)
        request = HTTPRequest()
        request.method = 'PUT'
        request.host = self._get_host()
        request.path = '/' + \
            _str(topic_name) + '/subscriptions/' + _str(subscription_name) + ''
        request.body = _get_request_body(
            _convert_subscription_to_xml(subscription))
        request.path, request.query = _update_request_uri_query(request)
        request.headers = self._update_service_bus_header(request)
        if not fail_on_exist:
            try:
                self._perform_request(request)
                return True
            except WindowsAzureError as ex:
                _dont_fail_on_exist(ex)
                return False
        else:
            self._perform_request(request)
            return True
    def create_event_hub(self, hub_name, hub=None, fail_on_exist=False):
        '''
        Creates a new Event Hub.

        hub_name:
            Name of event hub.
        hub:
            Optional. Event hub properties. Instance of EventHub class.
        hub.message_retention_in_days:
            Number of days to retain the events for this Event Hub.
        hub.status: Status of the Event Hub (enabled or disabled).
        hub.user_metadata: User metadata.
        hub.partition_count: Number of shards on the Event Hub.
        fail_on_exist:
            Specify whether to throw an exception when the event hub exists.
        '''
        _validate_not_none('hub_name', hub_name)
        request = HTTPRequest()
        request.method = 'PUT'
        request.host = self._get_host()
        request.path = '/' + _str(hub_name) + '?api-version=2014-01'
        request.body = _get_request_body(_convert_event_hub_to_xml(hub))
        request.path, request.query = _update_request_uri_query(request)
        request.headers = self._update_service_bus_header(request)
        if not fail_on_exist:
            try:
                self._perform_request(request)
                return True
            except WindowsAzureError as ex:
                _dont_fail_on_exist(ex)
                return False
        else:
            self._perform_request(request)
            return True
 def delete_queue(self, queue_name, fail_not_exist=False):
     '''
     Deletes an existing queue. This operation will also remove all 
     associated state including messages in the queue.
     
     queue_name: Name of the queue to delete.
     fail_not_exist:
         Specify whether to throw an exception if the queue doesn't exist.
     '''
     _validate_not_none('queue_name', queue_name)
     request = HTTPRequest()
     request.method = 'DELETE'
     request.host = self._get_host()
     request.path = '/' + _str(queue_name) + ''
     request.path, request.query = _update_request_uri_query(request)
     request.headers = _update_service_bus_header(request, self.account_key, self.issuer)
     if not fail_not_exist:
         try:
             self._perform_request(request)
             return True
         except WindowsAzureError as e:
             _dont_fail_not_exist(e)
             return False
     else:
         self._perform_request(request)
         return True
 def unlock_subscription_message(self, topic_name, subscription_name, sequence_number, lock_token):
     '''
     Unlock a message for processing by other receivers on a given subscription. 
     This operation deletes the lock object, causing the message to be unlocked. 
     A message must have first been locked by a receiver before this operation 
     is called.
     
     topic_name: the name of the topic
     subscription_name: the name of the subscription
     sequence_name: The sequence number of the message to be unlocked as returned 
     		in BrokerProperties['SequenceNumber'] by the Peek Message operation.
     lock_token: The ID of the lock as returned by the Peek Message operation in 
     		BrokerProperties['LockToken']
     '''
     _validate_not_none('topic_name', topic_name)
     _validate_not_none('subscription_name', subscription_name)
     _validate_not_none('sequence_number', sequence_number)
     _validate_not_none('lock_token', lock_token)
     request = HTTPRequest()
     request.method = 'PUT'
     request.host = self.service_namespace + SERVICE_BUS_HOST_BASE
     request.path = '/' + str(topic_name) + '/subscriptions/' + str(subscription_name) + '/messages/' + str(sequence_number) + '/' + str(lock_token) + ''
     request.path, request.query = _update_request_uri_query(request)
     request.headers = _update_service_bus_header(request, self.account_key, self.issuer)
     response = self._perform_request(request)
 def create_rule(self, topic_name, subscription_name, rule_name, rule=None, fail_on_exist=False):
     '''
     Creates a new rule. Once created, this rule's resource manifest is immutable.
     
     topic_name: the name of the topic
     subscription_name: the name of the subscription
     rule_name: name of the rule.
     fail_on_exist: specify whether to throw an exception when the rule exists.
     '''
     _validate_not_none('topic_name', topic_name)
     _validate_not_none('subscription_name', subscription_name)
     _validate_not_none('rule_name', rule_name)
     request = HTTPRequest()
     request.method = 'PUT'
     request.host = self.service_namespace + SERVICE_BUS_HOST_BASE
     request.path = '/' + str(topic_name) + '/subscriptions/' + str(subscription_name) + '/rules/' + str(rule_name) + ''
     request.body = _get_request_body(convert_rule_to_xml(rule))
     request.path, request.query = _update_request_uri_query(request)
     request.headers = _update_service_bus_header(request, self.account_key, self.issuer)
     if not fail_on_exist:
         try:
             self._perform_request(request)
             return True
         except WindowsAzureError as e:
             _dont_fail_on_exist(e)
             return False
     else:
         self._perform_request(request)
         return True
 def delete_rule(self, topic_name, subscription_name, rule_name, fail_not_exist=False):
     '''
     Deletes an existing rule.
     
     topic_name: the name of the topic
     subscription_name: the name of the subscription
     rule_name: the name of the rule.  DEFAULT_RULE_NAME=$Default. Use DEFAULT_RULE_NAME
     		to delete default rule for the subscription.
     fail_not_exist: specify whether throw exception when rule doesn't exist.
     '''
     _validate_not_none('topic_name', topic_name)
     _validate_not_none('subscription_name', subscription_name)
     _validate_not_none('rule_name', rule_name)
     request = HTTPRequest()
     request.method = 'DELETE'
     request.host = self._get_host()
     request.path = '/' + str(topic_name) + '/subscriptions/' + str(subscription_name) + '/rules/' + str(rule_name) + ''
     request.path, request.query = _update_request_uri_query(request)
     request.headers = _update_service_bus_header(request, self.account_key, self.issuer)
     if not fail_not_exist:
         try:
             self._perform_request(request)
             return True
         except WindowsAzureError as e:
             _dont_fail_not_exist(e)
             return False
     else:
         self._perform_request(request)
         return True
 def create_queue(self, queue_name, queue=None, fail_on_exist=False):
     '''
     Creates a new queue. Once created, this queue's resource manifest is immutable. 
     
     queue: queue object to create. 
     queue_name: the name of the queue.
     fail_on_exist: specify whether to throw an exception when the queue exists.
     '''
     _validate_not_none('queue_name', queue_name)
     request = HTTPRequest()
     request.method = 'PUT'
     request.host = self._get_host()
     request.path = '/' + str(queue_name) + ''
     request.body = _get_request_body(convert_queue_to_xml(queue))
     request.path, request.query = _update_request_uri_query(request)
     request.headers = _update_service_bus_header(request, self.account_key, self.issuer)
     if not fail_on_exist:
         try:
             self._perform_request(request)
             return True
         except WindowsAzureError as e:
             _dont_fail_on_exist(e)
             return False
     else:
         self._perform_request(request)
         return True
    def peek_lock_queue_message(self, queue_name, timeout='60'):
        '''
        Automically retrieves and locks a message from a queue for processing.
        The message is guaranteed not to be delivered to other receivers (on
        the same subscription only) during the lock duration period specified
        in the queue description. Once the lock expires, the message will be
        available to other receivers. In order to complete processing of the
        message, the receiver should issue a delete command with the lock ID
        received from this operation. To abandon processing of the message and
        unlock it for other receivers, an Unlock Message command should be
        issued, or the lock duration period can expire.

        queue_name: Name of the queue.
        timeout: Optional. The timeout parameter is expressed in seconds.
        '''
        _validate_not_none('queue_name', queue_name)
        request = HTTPRequest()
        request.method = 'POST'
        request.host = self._get_host()
        request.path = '/' + _str(queue_name) + '/messages/head'
        request.query = [('timeout', _int_or_none(timeout))]
        request.path, request.query = _update_request_uri_query(request)
        request.headers = self._update_service_bus_header(request)
        response = self._perform_request(request)

        return _create_message(response, self)
    def send_queue_message(self, queue_name, message=None):
        '''
        Sends a message into the specified queue. The limit to the number of
        messages which may be present in the topic is governed by the message
        size the MaxTopicSizeInMegaBytes. If this message will cause the queue
        to exceed its quota, a quota exceeded error is returned and the
        message will be rejected.

        queue_name:
            Name of the queue.
        message:
            Message object containing message body and properties.
        '''
        _validate_not_none('queue_name', queue_name)
        _validate_not_none('message', message)
        request = HTTPRequest()
        request.method = 'POST'
        request.host = self._get_host()
        request.path = '/' + _str(queue_name) + '/messages'
        request.headers = message.add_headers(request)
        request.body = _get_request_body_bytes_only('message.body',
                                                    message.body)
        request.path, request.query = _update_request_uri_query(request)
        request.headers = self._update_service_bus_header(request)
        self._perform_request(request)
    def unlock_queue_message(self, queue_name, sequence_number, lock_token):
        '''
        Unlocks a message for processing by other receivers on a given
        subscription. This operation deletes the lock object, causing the
        message to be unlocked. A message must have first been locked by a
        receiver before this operation is called.

        queue_name: Name of the queue.
        sequence_number:
            The sequence number of the message to be unlocked as returned in
            BrokerProperties['SequenceNumber'] by the Peek Message operation.
        lock_token:
            The ID of the lock as returned by the Peek Message operation in
            BrokerProperties['LockToken']
        '''
        _validate_not_none('queue_name', queue_name)
        _validate_not_none('sequence_number', sequence_number)
        _validate_not_none('lock_token', lock_token)
        request = HTTPRequest()
        request.method = 'PUT'
        request.host = self._get_host()
        request.path = '/' + _str(queue_name) + \
                       '/messages/' + _str(sequence_number) + \
                       '/' + _str(lock_token) + ''
        request.path, request.query = _update_request_uri_query(request)
        request.headers = self._update_service_bus_header(request)
        self._perform_request(request)
    def delete_subscription(self,
                            topic_name,
                            subscription_name,
                            fail_not_exist=False):
        '''
        Deletes an existing subscription.

        topic_name: Name of the topic.
        subscription_name: Name of the subscription to delete.
        fail_not_exist:
            Specify whether to throw an exception when the subscription
            doesn't exist.
        '''
        _validate_not_none('topic_name', topic_name)
        _validate_not_none('subscription_name', subscription_name)
        request = HTTPRequest()
        request.method = 'DELETE'
        request.host = self._get_host()
        request.path = '/' + \
            _str(topic_name) + '/subscriptions/' + _str(subscription_name) + ''
        request.path, request.query = _update_request_uri_query(request)
        request.headers = self._update_service_bus_header(request)
        if not fail_not_exist:
            try:
                self._perform_request(request)
                return True
            except WindowsAzureError as ex:
                _dont_fail_not_exist(ex)
                return False
        else:
            self._perform_request(request)
            return True
    def read_delete_subscription_message(self, topic_name, subscription_name,
                                         timeout='60'):
        '''
        Read and delete a message from a subscription as an atomic operation.
        This operation should be used when a best-effort guarantee is
        sufficient for an application; that is, using this operation it is
        possible for messages to be lost if processing fails.

        topic_name:
            Name of the topic.
        subscription_name:
            Name of the subscription.
        timeout:
            Optional. The timeout parameter is expressed in seconds.
        '''
        _validate_not_none('topic_name', topic_name)
        _validate_not_none('subscription_name', subscription_name)
        request = HTTPRequest()
        request.method = 'DELETE'
        request.host = self._get_host()
        request.path = '/' + _str(topic_name) + \
                       '/subscriptions/' + _str(subscription_name) + \
                       '/messages/head'
        request.query = [('timeout', _int_or_none(timeout))]
        request.path, request.query = _update_request_uri_query(request)
        request.headers = self._update_service_bus_header(request)
        response = self._perform_request(request)

        return _create_message(response, self)
    def delete_topic(self, topic_name, fail_not_exist=False):
        '''
        Deletes an existing topic. This operation will also remove all
        associated state including associated subscriptions.

        topic_name: Name of the topic to delete.
        fail_not_exist:
            Specify whether throw exception when topic doesn't exist.
        '''
        _validate_not_none('topic_name', topic_name)
        request = HTTPRequest()
        request.method = 'DELETE'
        request.host = self._get_host()
        request.path = '/' + _str(topic_name) + ''
        request.path, request.query = _update_request_uri_query(request)
        request.headers = self._update_service_bus_header(request)
        if not fail_not_exist:
            try:
                self._perform_request(request)
                return True
            except WindowsAzureError as ex:
                _dont_fail_not_exist(ex)
                return False
        else:
            self._perform_request(request)
            return True
Exemple #19
0
    def send_queue_message(self, queue_name, message=None):
        '''
        Sends a message into the specified queue. The limit to the number of
        messages which may be present in the topic is governed by the message
        size the MaxTopicSizeInMegaBytes. If this message will cause the queue
        to exceed its quota, a quota exceeded error is returned and the
        message will be rejected.

        queue_name:
            Name of the queue.
        message:
            Message object containing message body and properties.
        '''
        _validate_not_none('queue_name', queue_name)
        _validate_not_none('message', message)
        request = HTTPRequest()
        request.method = 'POST'
        request.host = self._get_host()
        request.path = '/' + _str(queue_name) + '/messages'
        request.headers = message.add_headers(request)
        request.body = _get_request_body_bytes_only('message.body',
                                                    message.body)
        request.path, request.query = _update_request_uri_query(request)
        request.headers = self._update_service_bus_header(request)
        self._perform_request(request)
Exemple #20
0
    def create_event_hub(self, hub_name, hub=None, fail_on_exist=False):
        '''
        Creates a new Event Hub.

        hub_name:
            Name of event hub.
        hub:
            Optional. Event hub properties. Instance of EventHub class.
        hub.message_retention_in_days:
            Number of days to retain the events for this Event Hub.
        hub.status: Status of the Event Hub (enabled or disabled).
        hub.user_metadata: User metadata.
        hub.partition_count: Number of shards on the Event Hub.
        fail_on_exist:
            Specify whether to throw an exception when the event hub exists.
        '''
        _validate_not_none('hub_name', hub_name)
        request = HTTPRequest()
        request.method = 'PUT'
        request.host = self._get_host()
        request.path = '/' + _str(hub_name) + '?api-version=2014-01'
        request.body = _get_request_body(_convert_event_hub_to_xml(hub))
        request.path, request.query = _update_request_uri_query(request)
        request.headers = self._update_service_bus_header(request)
        if not fail_on_exist:
            try:
                self._perform_request(request)
                return True
            except WindowsAzureError as ex:
                _dont_fail_on_exist(ex)
                return False
        else:
            self._perform_request(request)
            return True
    def unlock_queue_message(self, queue_name, sequence_number, lock_token):
        '''
        Unlocks a message for processing by other receivers on a given
        subscription. This operation deletes the lock object, causing the
        message to be unlocked. A message must have first been locked by a
        receiver before this operation is called.

        queue_name:
            Name of the queue.
        sequence_number:
            The sequence number of the message to be unlocked as returned in
            BrokerProperties['SequenceNumber'] by the Peek Message operation.
        lock_token:
            The ID of the lock as returned by the Peek Message operation in
            BrokerProperties['LockToken']
        '''
        _validate_not_none('queue_name', queue_name)
        _validate_not_none('sequence_number', sequence_number)
        _validate_not_none('lock_token', lock_token)
        request = HTTPRequest()
        request.method = 'PUT'
        request.host = self._get_host()
        request.path = '/' + _str(queue_name) + \
                       '/messages/' + _str(sequence_number) + \
                       '/' + _str(lock_token) + ''
        request.path, request.query = _update_request_uri_query(request)
        request.headers = self._update_service_bus_header(request)
        self._perform_request(request)
Exemple #22
0
    def get_rule(self, topic_name, subscription_name, rule_name):
        '''
        Retrieves the description for the specified rule.

        topic_name:
            Name of the topic.
        subscription_name:
            Name of the subscription.
        rule_name:
            Name of the rule.
        '''
        _validate_not_none('topic_name', topic_name)
        _validate_not_none('subscription_name', subscription_name)
        _validate_not_none('rule_name', rule_name)
        request = HTTPRequest()
        request.method = 'GET'
        request.host = self._get_host()
        request.path = '/' + _str(topic_name) + '/subscriptions/' + \
            _str(subscription_name) + \
            '/rules/' + _str(rule_name) + ''
        request.path, request.query = _update_request_uri_query(request)
        request.headers = self._update_service_bus_header(request)
        response = self._perform_request(request)

        return _convert_response_to_rule(response)
Exemple #23
0
    def delete_event_hub(self, hub_name, fail_not_exist=False):
        '''
        Deletes an Event Hub. This operation will also remove all associated
        state.

        hub_name:
            Name of the event hub to delete.
        fail_not_exist:
            Specify whether to throw an exception if the event hub doesn't exist.
        '''
        _validate_not_none('hub_name', hub_name)
        request = HTTPRequest()
        request.method = 'DELETE'
        request.host = self._get_host()
        request.path = '/' + _str(hub_name) + '?api-version=2014-01'
        request.path, request.query = _update_request_uri_query(request)
        request.headers = self._update_service_bus_header(request)
        if not fail_not_exist:
            try:
                self._perform_request(request)
                return True
            except WindowsAzureError as ex:
                _dont_fail_not_exist(ex)
                return False
        else:
            self._perform_request(request)
            return True
 def delete_queue(self, queue_name, fail_not_exist=False):
     '''
     Deletes an existing queue. This operation will also remove all 
     associated state including messages in the queue.
     
     queue_name: Name of the queue to delete.
     fail_not_exist:
         Specify whether to throw an exception if the queue doesn't exist.
     '''
     _validate_not_none('queue_name', queue_name)
     request = HTTPRequest()
     request.method = 'DELETE'
     request.host = self._get_host()
     request.path = '/' + _str(queue_name) + ''
     request.path, request.query = _update_request_uri_query(request)
     request.headers = _update_service_bus_header(request, self.account_key,
                                                  self.issuer)
     if not fail_not_exist:
         try:
             self._perform_request(request)
             return True
         except WindowsAzureError as e:
             _dont_fail_not_exist(e)
             return False
     else:
         self._perform_request(request)
         return True
 def create_queue(self, queue_name, queue=None, fail_on_exist=False):
     '''
     Creates a new queue. Once created, this queue's resource manifest is 
     immutable. 
     
     queue_name: Name of the queue to create.
     queue: Queue object to create. 
     fail_on_exist:
         Specify whether to throw an exception when the queue exists.
     '''
     _validate_not_none('queue_name', queue_name)
     request = HTTPRequest()
     request.method = 'PUT'
     request.host = self._get_host()
     request.path = '/' + _str(queue_name) + ''
     request.body = _get_request_body(_convert_queue_to_xml(queue))
     request.path, request.query = _update_request_uri_query(request)
     request.headers = _update_service_bus_header(request, self.account_key,
                                                  self.issuer)
     if not fail_on_exist:
         try:
             self._perform_request(request)
             return True
         except WindowsAzureError as e:
             _dont_fail_on_exist(e)
             return False
     else:
         self._perform_request(request)
         return True
    def delete_queue_message(self, queue_name, sequence_number, lock_token):
        '''
        Completes processing on a locked message and delete it from the queue.
        This operation should only be called after processing a previously
        locked message is successful to maintain At-Least-Once delivery
        assurances.

        queue_name:
            Name of the queue.
        sequence_number:
            The sequence number of the message to be deleted as returned in
            BrokerProperties['SequenceNumber'] by the Peek Message operation.
        lock_token:
            The ID of the lock as returned by the Peek Message operation in
            BrokerProperties['LockToken']
        '''
        _validate_not_none('queue_name', queue_name)
        _validate_not_none('sequence_number', sequence_number)
        _validate_not_none('lock_token', lock_token)
        request = HTTPRequest()
        request.method = 'DELETE'
        request.host = self._get_host()
        request.path = '/' + _str(queue_name) + \
                       '/messages/' + _str(sequence_number) + \
                       '/' + _str(lock_token) + ''
        request.path, request.query = _update_request_uri_query(request)
        request.headers = self._update_service_bus_header(request)
        self._perform_request(request)
    def delete_event_hub(self, hub_name, fail_not_exist=False):
        '''
        Deletes an Event Hub. This operation will also remove all associated
        state.

        hub_name:
            Name of the event hub to delete.
        fail_not_exist:
            Specify whether to throw an exception if the event hub doesn't exist.
        '''
        _validate_not_none('hub_name', hub_name)
        request = HTTPRequest()
        request.method = 'DELETE'
        request.host = self._get_host()
        request.path = '/' + _str(hub_name) + '?api-version=2014-01'
        request.path, request.query = _update_request_uri_query(request)
        request.headers = self._update_service_bus_header(request)
        if not fail_not_exist:
            try:
                self._perform_request(request)
                return True
            except WindowsAzureError as ex:
                _dont_fail_not_exist(ex)
                return False
        else:
            self._perform_request(request)
            return True
    def delete_queue_message(self, queue_name, sequence_number, lock_token):
        '''
        Completes processing on a locked message and delete it from the queue.
        This operation should only be called after processing a previously
        locked message is successful to maintain At-Least-Once delivery
        assurances.

        queue_name: Name of the queue.
        sequence_number:
            The sequence number of the message to be deleted as returned in
            BrokerProperties['SequenceNumber'] by the Peek Message operation.
        lock_token:
            The ID of the lock as returned by the Peek Message operation in
            BrokerProperties['LockToken']
        '''
        _validate_not_none('queue_name', queue_name)
        _validate_not_none('sequence_number', sequence_number)
        _validate_not_none('lock_token', lock_token)
        request = HTTPRequest()
        request.method = 'DELETE'
        request.host = self._get_host()
        request.path = '/' + _str(queue_name) + \
                       '/messages/' + _str(sequence_number) + \
                       '/' + _str(lock_token) + ''
        request.path, request.query = _update_request_uri_query(request)
        request.headers = self._update_service_bus_header(request)
        self._perform_request(request)
    def peek_lock_queue_message(self, queue_name, timeout='60'):
        '''
        Automically retrieves and locks a message from a queue for processing.
        The message is guaranteed not to be delivered to other receivers (on
        the same subscription only) during the lock duration period specified
        in the queue description. Once the lock expires, the message will be
        available to other receivers. In order to complete processing of the
        message, the receiver should issue a delete command with the lock ID
        received from this operation. To abandon processing of the message and
        unlock it for other receivers, an Unlock Message command should be
        issued, or the lock duration period can expire.

        queue_name:
            Name of the queue.
        timeout:
            Optional. The timeout parameter is expressed in seconds.
        '''
        _validate_not_none('queue_name', queue_name)
        request = HTTPRequest()
        request.method = 'POST'
        request.host = self._get_host()
        request.path = '/' + _str(queue_name) + '/messages/head'
        request.query = [('timeout', _int_or_none(timeout))]
        request.path, request.query = _update_request_uri_query(request)
        request.headers = self._update_service_bus_header(request)
        response = self._perform_request(request)

        return _create_message(response, self)
    def create_topic(self, topic_name, topic=None, fail_on_exist=False):
        '''
        Creates a new topic. Once created, this topic resource manifest is
        immutable.

        topic_name: Name of the topic to create.
        topic: Topic object to create.
        fail_on_exist:
            Specify whether to throw an exception when the topic exists.
        '''
        _validate_not_none('topic_name', topic_name)
        request = HTTPRequest()
        request.method = 'PUT'
        request.host = self._get_host()
        request.path = '/' + _str(topic_name) + ''
        request.body = _get_request_body(_convert_topic_to_xml(topic))
        request.path, request.query = _update_request_uri_query(request)
        request.headers = self._update_service_bus_header(request)
        if not fail_on_exist:
            try:
                self._perform_request(request)
                return True
            except WindowsAzureError as ex:
                _dont_fail_on_exist(ex)
                return False
        else:
            self._perform_request(request)
            return True
    def get_rule(self, topic_name, subscription_name, rule_name):
        '''
        Retrieves the description for the specified rule.

        topic_name:
            Name of the topic.
        subscription_name:
            Name of the subscription.
        rule_name:
            Name of the rule.
        '''
        _validate_not_none('topic_name', topic_name)
        _validate_not_none('subscription_name', subscription_name)
        _validate_not_none('rule_name', rule_name)
        request = HTTPRequest()
        request.method = 'GET'
        request.host = self._get_host()
        request.path = '/' + _str(topic_name) + '/subscriptions/' + \
            _str(subscription_name) + \
            '/rules/' + _str(rule_name) + ''
        request.path, request.query = _update_request_uri_query(request)
        request.headers = self._update_service_bus_header(request)
        response = self._perform_request(request)

        return _convert_response_to_rule(response)
    def delete_subscription(self, topic_name, subscription_name,
                            fail_not_exist=False):
        '''
        Deletes an existing subscription.

        topic_name:
            Name of the topic.
        subscription_name:
            Name of the subscription to delete.
        fail_not_exist:
            Specify whether to throw an exception when the subscription
            doesn't exist.
        '''
        _validate_not_none('topic_name', topic_name)
        _validate_not_none('subscription_name', subscription_name)
        request = HTTPRequest()
        request.method = 'DELETE'
        request.host = self._get_host()
        request.path = '/' + \
            _str(topic_name) + '/subscriptions/' + _str(subscription_name) + ''
        request.path, request.query = _update_request_uri_query(request)
        request.headers = self._update_service_bus_header(request)
        if not fail_not_exist:
            try:
                self._perform_request(request)
                return True
            except WindowsAzureError as ex:
                _dont_fail_not_exist(ex)
                return False
        else:
            self._perform_request(request)
            return True
    def create_topic(self, topic_name, topic=None, fail_on_exist=False):
        '''
        Creates a new topic. Once created, this topic resource manifest is
        immutable.

        topic_name:
            Name of the topic to create.
        topic:
            Topic object to create.
        fail_on_exist:
            Specify whether to throw an exception when the topic exists.
        '''
        _validate_not_none('topic_name', topic_name)
        request = HTTPRequest()
        request.method = 'PUT'
        request.host = self._get_host()
        request.path = '/' + _str(topic_name) + ''
        request.body = _get_request_body(_convert_topic_to_xml(topic))
        request.path, request.query = _update_request_uri_query(request)
        request.headers = self._update_service_bus_header(request)
        if not fail_on_exist:
            try:
                self._perform_request(request)
                return True
            except WindowsAzureError as ex:
                _dont_fail_on_exist(ex)
                return False
        else:
            self._perform_request(request)
            return True
    def create_subscription(self,
                            topic_name,
                            subscription_name,
                            subscription=None,
                            fail_on_exist=False):
        '''
        Creates a new subscription. Once created, this subscription resource
        manifest is immutable.

        topic_name: Name of the topic.
        subscription_name: Name of the subscription.
        fail_on_exist:
            Specify whether throw exception when subscription exists.
        '''
        _validate_not_none('topic_name', topic_name)
        _validate_not_none('subscription_name', subscription_name)
        request = HTTPRequest()
        request.method = 'PUT'
        request.host = self._get_host()
        request.path = '/' + \
            _str(topic_name) + '/subscriptions/' + _str(subscription_name) + ''
        request.body = _get_request_body(
            _convert_subscription_to_xml(subscription))
        request.path, request.query = _update_request_uri_query(request)
        request.headers = self._update_service_bus_header(request)
        if not fail_on_exist:
            try:
                self._perform_request(request)
                return True
            except WindowsAzureError as ex:
                _dont_fail_on_exist(ex)
                return False
        else:
            self._perform_request(request)
            return True
    def peek_lock_subscription_message(self, topic_name, subscription_name, timeout='60'):
        '''
        This operation is used to atomically retrieve and lock a message for processing. 
        The message is guaranteed not to be delivered to other receivers during the lock 
        duration period specified in buffer description. Once the lock expires, the 
        message will be available to other receivers (on the same subscription only) 
        during the lock duration period specified in the topic description. Once the lock
        expires, the message will be available to other receivers. In order to complete 
        processing of the message, the receiver should issue a delete command with the 
        lock ID received from this operation. To abandon processing of the message and 
        unlock it for other receivers, an Unlock Message command should be issued, or 
        the lock duration period can expire. 
        
        topic_name: the name of the topic
        subscription_name: the name of the subscription
        '''
        _validate_not_none('topic_name', topic_name)
        _validate_not_none('subscription_name', subscription_name)
        request = HTTPRequest()
        request.method = 'POST'
        request.host = self.service_namespace + SERVICE_BUS_HOST_BASE
        request.path = '/' + str(topic_name) + '/subscriptions/' + str(subscription_name) + '/messages/head'
        request.query = [('timeout', _int_or_none(timeout))]
        request.path, request.query = _update_request_uri_query(request)
        request.headers = _update_service_bus_header(request, self.account_key, self.issuer)
        response = self._perform_request(request)

        return _create_message(response, self)
    def read_delete_subscription_message(self,
                                         topic_name,
                                         subscription_name,
                                         timeout='60'):
        '''
        Read and delete a message from a subscription as an atomic operation.
        This operation should be used when a best-effort guarantee is
        sufficient for an application; that is, using this operation it is
        possible for messages to be lost if processing fails.

        topic_name: Name of the topic.
        subscription_name: Name of the subscription.
        timeout: Optional. The timeout parameter is expressed in seconds.
        '''
        _validate_not_none('topic_name', topic_name)
        _validate_not_none('subscription_name', subscription_name)
        request = HTTPRequest()
        request.method = 'DELETE'
        request.host = self._get_host()
        request.path = '/' + _str(topic_name) + \
                       '/subscriptions/' + _str(subscription_name) + \
                       '/messages/head'
        request.query = [('timeout', _int_or_none(timeout))]
        request.path, request.query = _update_request_uri_query(request)
        request.headers = self._update_service_bus_header(request)
        response = self._perform_request(request)

        return _create_message(response, self)
    def peek_lock_subscription_message(self, topic_name, subscription_name, timeout='60'):
        '''
        This operation is used to atomically retrieve and lock a message for processing. 
        The message is guaranteed not to be delivered to other receivers during the lock 
        duration period specified in buffer description. Once the lock expires, the 
        message will be available to other receivers (on the same subscription only) 
        during the lock duration period specified in the topic description. Once the lock
        expires, the message will be available to other receivers. In order to complete 
        processing of the message, the receiver should issue a delete command with the 
        lock ID received from this operation. To abandon processing of the message and 
        unlock it for other receivers, an Unlock Message command should be issued, or 
        the lock duration period can expire. 
        
        topic_name: the name of the topic
        subscription_name: the name of the subscription
        '''
        _validate_not_none('topic_name', topic_name)
        _validate_not_none('subscription_name', subscription_name)
        request = HTTPRequest()
        request.method = 'POST'
        request.host = self._get_host()
        request.path = '/' + str(topic_name) + '/subscriptions/' + str(subscription_name) + '/messages/head'
        request.query = [('timeout', _int_or_none(timeout))]
        request.path, request.query = _update_request_uri_query(request)
        request.headers = _update_service_bus_header(request, self.account_key, self.issuer)
        response = self._perform_request(request)

        return _create_message(response, self)
Exemple #38
0
    def perform_request(self, request):
        ''' Sends request to cloud service server and return the response. '''
        connection = self.get_connection(request)
        try:
            connection.putrequest(request.method, request.path)

            if not self.use_httplib:
                if self.proxy_host and self.proxy_user:
                    connection.set_proxy_credentials(self.proxy_user,
                                                     self.proxy_password)

            self.send_request_headers(connection, request.headers)
            self.send_request_body(connection, request.body)

            if DEBUG_REQUESTS and request.body:
                print('request:')
                try:
                    print(request.body)
                except:
                    pass

            resp = connection.getresponse()
            self.status = int(resp.status)
            self.message = resp.reason
            self.respheader = headers = resp.getheaders()

            # for consistency across platforms, make header names lowercase
            for i, value in enumerate(headers):
                headers[i] = (value[0].lower(), value[1])

            respbody = None
            if resp.length is None:
                respbody = resp.read()
            elif resp.length > 0:
                respbody = resp.read(resp.length)

            if DEBUG_RESPONSES and respbody:
                print('response:')
                try:
                    print(respbody)
                except:
                    pass

            response = HTTPResponse(int(resp.status), resp.reason, headers,
                                    respbody)
            if self.status == 307:
                new_url = urlparse(dict(headers)['location'])
                request.host = new_url.hostname
                request.path = new_url.path
                request.path, request.query = _update_request_uri_query(
                    request)
                return self.perform_request(request)
            if self.status >= 300:
                raise HTTPError(self.status, self.message, self.respheader,
                                respbody)

            return response
        finally:
            connection.close()
    def perform_request(self, request):
        ''' Sends request to cloud service server and return the response. '''
        connection = self.get_connection(request)
        try:
            connection.putrequest(request.method, request.path)

            if not self.use_httplib:
                if self.proxy_host and self.proxy_user:
                    connection.set_proxy_credentials(
                        self.proxy_user, self.proxy_password)

            self.send_request_headers(connection, request.headers)
            self.send_request_body(connection, request.body)

            if DEBUG_REQUESTS and request.body:
                print('request:')
                try:
                    print(request.body)
                except:
                    pass

            resp = connection.getresponse()
            self.status = int(resp.status)
            self.message = resp.reason
            self.respheader = headers = resp.getheaders()

            # for consistency across platforms, make header names lowercase
            for i, value in enumerate(headers):
                headers[i] = (value[0].lower(), value[1])

            respbody = None
            if resp.length is None:
                respbody = resp.read()
            elif resp.length > 0:
                respbody = resp.read(resp.length)

            if DEBUG_RESPONSES and respbody:
                print('response:')
                try:
                    print(respbody)
                except:
                    pass

            response = HTTPResponse(
                int(resp.status), resp.reason, headers, respbody)
            if self.status == 307:
                new_url = urlparse(dict(headers)['location'])
                request.host = new_url.hostname
                request.path = new_url.path
                request.path, request.query = _update_request_uri_query(request)
                return self.perform_request(request)
            if self.status >= 300:
                raise HTTPError(self.status, self.message,
                                self.respheader, respbody)

            return response
        finally:
            connection.close()
    def list_queues(self):
        '''
        Enumerates the queues in the service namespace.
        '''
        request = HTTPRequest()
        request.method = 'GET'
        request.host = self._get_host()
        request.path = '/$Resources/Queues'
        request.path, request.query = _update_request_uri_query(request)
        request.headers = self._update_service_bus_header(request)
        response = self._perform_request(request)

        return _convert_response_to_feeds(response, _convert_xml_to_queue)
    def _perform_get(self, path, response_type):
        request = HTTPRequest()
        request.method = 'GET'
        request.host = self.host
        request.path = path
        request.path, request.query = _update_request_uri_query(request)
        request.headers = _update_management_header(request)
        response = self._perform_request(request)

        if response_type is not None:
            return _parse_response(response, response_type)

        return response
    def list_queues(self):
        '''
        Enumerates the queues in the service namespace.
        '''
        request = HTTPRequest()
        request.method = 'GET'
        request.host = self.service_namespace + SERVICE_BUS_HOST_BASE
        request.path = '/$Resources/Queues'
        request.path, request.query = _update_request_uri_query(request)
        request.headers = _update_service_bus_header(request, self.account_key, self.issuer)
        response = self._perform_request(request)

        return _convert_response_to_feeds(response, _convert_xml_to_queue)
    def list_topics(self):
        '''
        Retrieves the topics in the service namespace.
        '''
        request = HTTPRequest()
        request.method = 'GET'
        request.host = self._get_host()
        request.path = '/$Resources/Topics'
        request.path, request.query = _update_request_uri_query(request)
        request.headers = self._update_service_bus_header(request)
        response = self._perform_request(request)

        return _convert_response_to_feeds(response, _convert_xml_to_topic)
    def list_topics(self):
        '''
        Retrieves the topics in the service namespace.
        '''
        request = HTTPRequest()
        request.method = 'GET'
        request.host = self._get_host()
        request.path = '/$Resources/Topics'
        request.path, request.query = _update_request_uri_query(request)
        request.headers = _update_service_bus_header(request, self.account_key, self.issuer)
        response = self._perform_request(request)

        return _convert_response_to_feeds(response, _convert_xml_to_topic)
    def list_topics(self):
        '''
        Retrieves the topics in the service namespace.
        '''
        request = HTTPRequest()
        request.method = 'GET'
        request.host = self.service_namespace + SERVICE_BUS_HOST_BASE
        request.path = '/$Resources/Topics'
        request.path, request.query = _update_request_uri_query(request)
        request.headers = _update_service_bus_header(request, self.account_key, self.issuer)
        response = self._perform_request(request)

        return _convert_response_to_feeds(response, _convert_xml_to_topic)
    def _perform_get(self, path, response_type):
        request = HTTPRequest()
        request.method = 'GET'
        request.host = self.host
        request.path = path
        request.path, request.query = _update_request_uri_query(request)
        request.headers = _update_management_header(request)
        response = self._perform_request(request)

        if response_type is not None:
            return _parse_response(response, response_type)

        return response
    def list_queues(self):
        '''
        Enumerates the queues in the service namespace.
        '''
        request = HTTPRequest()
        request.method = 'GET'
        request.host = self._get_host()
        request.path = '/$Resources/Queues'
        request.path, request.query = _update_request_uri_query(request)
        request.headers = _update_service_bus_header(request, self.account_key,
                                                     self.issuer)
        response = self._perform_request(request)

        return _convert_response_to_feeds(response, _convert_xml_to_queue)
    def list_topics(self):
        '''
        Retrieves the topics in the service namespace.
        '''
        request = HTTPRequest()
        request.method = 'GET'
        request.host = self._get_host()
        request.path = '/$Resources/Topics'
        request.path, request.query = _update_request_uri_query(request)
        request.headers = self._update_service_bus_header(request)
        response = self._perform_request(request)

        return _ETreeXmlToObject.convert_response_to_feeds(
            response, _convert_etree_element_to_topic)
Exemple #49
0
    def list_queues(self):
        '''
        Enumerates the queues in the service namespace.
        '''
        request = HTTPRequest()
        request.method = 'GET'
        request.host = self._get_host()
        request.path = '/$Resources/Queues'
        request.path, request.query = _update_request_uri_query(request)
        request.headers = self._update_service_bus_header(request)
        response = self._perform_request(request)

        return _ETreeXmlToObject.convert_response_to_feeds(
            response, _convert_etree_element_to_queue)
    def get_queue(self, queue_name):
        '''
        Retrieves an existing queue.
        
        queue_name: name of the queue.
        '''
        _validate_not_none('queue_name', queue_name)
        request = HTTPRequest()
        request.method = 'GET'
        request.host = self._get_host()
        request.path = '/' + str(queue_name) + ''
        request.path, request.query = _update_request_uri_query(request)
        request.headers = _update_service_bus_header(request, self.account_key, self.issuer)
        response = self._perform_request(request)

        return _convert_response_to_queue(response)
    def list_subscriptions(self, topic_name):
        '''
        Retrieves the subscriptions in the specified topic. 
        
        topic_name: the name of the topic
        '''
        _validate_not_none('topic_name', topic_name)
        request = HTTPRequest()
        request.method = 'GET'
        request.host = self.service_namespace + SERVICE_BUS_HOST_BASE
        request.path = '/' + str(topic_name) + '/subscriptions/'
        request.path, request.query = _update_request_uri_query(request)
        request.headers = _update_service_bus_header(request, self.account_key, self.issuer)
        response = self._perform_request(request)

        return _convert_response_to_feeds(response, _convert_xml_to_subscription)
    def get_queue(self, queue_name):
        '''
        Retrieves an existing queue.
        
        queue_name: name of the queue.
        '''
        _validate_not_none('queue_name', queue_name)
        request = HTTPRequest()
        request.method = 'GET'
        request.host = self.service_namespace + SERVICE_BUS_HOST_BASE
        request.path = '/' + str(queue_name) + ''
        request.path, request.query = _update_request_uri_query(request)
        request.headers = _update_service_bus_header(request, self.account_key, self.issuer)
        response = self._perform_request(request)

        return _convert_response_to_queue(response)
    def get_topic(self, topic_name):
        '''
        Retrieves the description for the specified topic.
        
        topic_name: name of the topic.
        '''
        _validate_not_none('topic_name', topic_name)
        request = HTTPRequest()
        request.method = 'GET'
        request.host = self._get_host()
        request.path = '/' + str(topic_name) + ''
        request.path, request.query = _update_request_uri_query(request)
        request.headers = _update_service_bus_header(request, self.account_key, self.issuer)
        response = self._perform_request(request)

        return _convert_response_to_topic(response)
    def list_subscriptions(self, topic_name):
        '''
        Retrieves the subscriptions in the specified topic. 
        
        topic_name: the name of the topic
        '''
        _validate_not_none('topic_name', topic_name)
        request = HTTPRequest()
        request.method = 'GET'
        request.host = self._get_host()
        request.path = '/' + str(topic_name) + '/subscriptions/'
        request.path, request.query = _update_request_uri_query(request)
        request.headers = _update_service_bus_header(request, self.account_key, self.issuer)
        response = self._perform_request(request)

        return _convert_response_to_feeds(response, _convert_xml_to_subscription)
    def get_queue(self, queue_name):
        '''
        Retrieves an existing queue.

        queue_name: Name of the queue.
        '''
        _validate_not_none('queue_name', queue_name)
        request = HTTPRequest()
        request.method = 'GET'
        request.host = self._get_host()
        request.path = '/' + _str(queue_name) + ''
        request.path, request.query = _update_request_uri_query(request)
        request.headers = self._update_service_bus_header(request)
        response = self._perform_request(request)

        return _convert_response_to_queue(response)
    def get_topic(self, topic_name):
        '''
        Retrieves the description for the specified topic.

        topic_name: Name of the topic.
        '''
        _validate_not_none('topic_name', topic_name)
        request = HTTPRequest()
        request.method = 'GET'
        request.host = self._get_host()
        request.path = '/' + _str(topic_name) + ''
        request.path, request.query = _update_request_uri_query(request)
        request.headers = self._update_service_bus_header(request)
        response = self._perform_request(request)

        return _convert_response_to_topic(response)
    def get_event_hub(self, hub_name):
        '''
        Retrieves an existing event hub.

        hub_name:
            Name of the event hub.
        '''
        _validate_not_none('hub_name', hub_name)
        request = HTTPRequest()
        request.method = 'GET'
        request.host = self._get_host()
        request.path = '/' + _str(hub_name) + ''
        request.path, request.query = _update_request_uri_query(request)
        request.headers = self._update_service_bus_header(request)
        response = self._perform_request(request)

        return _convert_response_to_event_hub(response)