当前位置: 首页>>代码示例>>Python>>正文


Python ServiceBusService.create_subscription方法代码示例

本文整理汇总了Python中azure.servicebus.ServiceBusService.create_subscription方法的典型用法代码示例。如果您正苦于以下问题:Python ServiceBusService.create_subscription方法的具体用法?Python ServiceBusService.create_subscription怎么用?Python ServiceBusService.create_subscription使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在azure.servicebus.ServiceBusService的用法示例。


在下文中一共展示了ServiceBusService.create_subscription方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: AzureWorker

# 需要导入模块: from azure.servicebus import ServiceBusService [as 别名]
# 或者: from azure.servicebus.ServiceBusService import create_subscription [as 别名]
class AzureWorker(Thread):
    def __init__(self):
        Thread.__init__(self)
        self._quit = Event()

        settings = Settings()
        settings.configure_logging('../logs/task_manager.log', 'TaskManagerAzureWorker')

        self.job_manager_url = 'http://' + settings.job_manager_api_connect + ':5000'

        self.unfinished = []
        self.finished = []
        self.executor = Executor(self.unfinished, self.finished)

        self.outgoing_topic = 'finished_jobs'
        self.incoming_topic = 'pending_jobs'

        self.bus_service = ServiceBusService(
            service_namespace=settings.azure_topic_namespace,
            shared_access_key_name=settings.azure_topic_keyname,
            shared_access_key_value=settings.azure_topic_key
        )
        self.bus_service.create_topic(self.incoming_topic)
        self.bus_service.create_topic(self.outgoing_topic)
        self.incoming_topic_subscription = 'AllMessages'
        self.bus_service.create_subscription(self.incoming_topic, self.incoming_topic_subscription)

    def quit(self):
        self._quit.set()

    def run(self):
        self.executor.start()

        # dislike of unstoppable threads
        while not self._quit.is_set():
            msg = self.bus_service.receive_subscription_message(self.incoming_topic, self.incoming_topic_subscription,
                                                                peek_lock=True)
            if msg.body is not None:
                # New job for us!
                job_id = msg.custom_properties['job_id']
                logging.info('getting job with id: ' + job_id + ' from the API')

                r = requests.get(self.job_manager_url + '/jobs/' + job_id)
                job = r.json()

                msg.delete()

                logging.info('appending tasks from job with id: ' + job['id'] + ' and name: ' + job['name'])
                self.unfinished.append(job['name'])

            sleep(3)

        # stop executor
        self.executor.quit()
        self.executor.join()
开发者ID:witlox,项目名称:cumulonimbi,代码行数:57,代码来源:azureworker.py

示例2: AzureBroker

# 需要导入模块: from azure.servicebus import ServiceBusService [as 别名]
# 或者: from azure.servicebus.ServiceBusService import create_subscription [as 别名]
class AzureBroker(Thread):
    def __init__(self):
        Thread.__init__(self)
        self._quit = Event()
        self.daemon = True
        self.log = logging.getLogger(__name__)

        self.outgoing_topic = 'pending_jobs'
        self.incoming_topic = 'finished_jobs'
        self.notification_topic = 'jobs_changed'
        self.subscription = 'AllMessages'

        settings = Settings()
        self.bus_service = ServiceBusService(
            service_namespace=settings.azure_topic_namespace,
            shared_access_key_name=settings.azure_topic_keyname,
            shared_access_key_value=settings.azure_topic_key
        )

        self.bus_service.create_topic(self.incoming_topic)
        self.bus_service.create_topic(self.outgoing_topic)
        self.bus_service.create_topic(self.notification_topic)
        self.bus_service.create_subscription(self.incoming_topic, self.subscription)

    def run(self):
        # dislike of unstoppable threads
        while not self._quit.is_set():
            msg = self.bus_service.receive_subscription_message(self.incoming_topic, self.subscription,
                                                                peek_lock=False, timeout=0.1)
            if msg.body is not None:
                self.log.info(msg.body + ":" + msg.custom_properties['job_id'])
                notification_msg = Message('Finished'.encode('utf-8'), custom_properties={'job_id': msg.custom_properties['job_id']})
                self.bus_service.send_topic_message(self.notification_topic, notification_msg)

            sleep(3)

    def transmit_job_created(self, job_id):
        msg = Message('Created'.encode('utf-8'), custom_properties={'job_id': job_id})
        self.bus_service.send_topic_message(self.outgoing_topic, msg)
        self.bus_service.send_topic_message(self.notification_topic, msg)

        self.log.info("Adding job " + job_id + " created to service bus.")

    def transmit_job_assigned(self, job_id, machine_id):
        msg = Message('Assigned'.encode('utf-8'), custom_properties={'job_id': job_id, 'machine_id': machine_id})
        self.bus_service.send_topic_message(self.outgoing_topic, msg)
        self.bus_service.send_topic_message(self.notification_topic, msg)

        self.log.info("Adding job " + job_id + " assigned to " + machine_id + " to the service bus.")

    def quit(self):
        self._quit.set()
开发者ID:witlox,项目名称:cumulonimbi,代码行数:54,代码来源:azurebroker.py

示例3: AzureListener

# 需要导入模块: from azure.servicebus import ServiceBusService [as 别名]
# 或者: from azure.servicebus.ServiceBusService import create_subscription [as 别名]
class AzureListener(Thread):
    def __init__(self, machine_manager_logic):
        Thread.__init__(self)
        self._quit = Event()
        self.daemon = True
        self.log = logging.getLogger(__name__)
        self.notification_topic = 'jobs_changed'
        self.subscription = 'AllMessages'
        self.machine_manager_logic = machine_manager_logic

        settings = Settings()
        self.bus_service = ServiceBusService(
            service_namespace=settings.azure_topic_namespace,
            shared_access_key_name=settings.azure_topic_keyname,
            shared_access_key_value=settings.azure_topic_key
        )
        self.bus_service.create_topic(self.notification_topic)
        self.bus_service.create_subscription(self.notification_topic, self.subscription)

    def quit(self):
        self._quit.set()

    def run(self):
        # dislike of unstoppable threads
        while not self._quit.is_set():
            msg = self.bus_service.receive_subscription_message(self.notification_topic, self.subscription,
                                                                peek_lock=False, timeout=0.1)
            if msg.body is not None:
                self.log.info(msg.body + ":" + json.dumps(msg.custom_properties))

                if "Created" in msg.body:
                    self.machine_manager_logic.job_added(msg.custom_properties['job_id'])

                if "Assigned" in msg.body:
                    self.machine_manager_logic.job_assigned(msg.custom_properties['job_id'], msg.custom_properties['machine_id'])

                if "Finished" in msg.body:
                    self.machine_manager_logic.job_removed(msg.custom_properties['job_id'])

            self.machine_manager_logic.check_machines()
            sleep(10)
开发者ID:witlox,项目名称:cumulonimbi,代码行数:43,代码来源:azurelistener.py

示例4: ServiceBusTest

# 需要导入模块: from azure.servicebus import ServiceBusService [as 别名]
# 或者: from azure.servicebus.ServiceBusService import create_subscription [as 别名]
class ServiceBusTest(AzureTestCase):

    def setUp(self):
        self.sbs = ServiceBusService(credentials.getServiceBusNamespace(),
                                     credentials.getServiceBusKey(),
                                     'owner')

        self.sbs.set_proxy(credentials.getProxyHost(),
                           credentials.getProxyPort(),
                           credentials.getProxyUser(),
                           credentials.getProxyPassword())

        __uid = getUniqueTestRunID()

        queue_base_name = u'mytestqueue%s' % (__uid)
        topic_base_name = u'mytesttopic%s' % (__uid)

        self.queue_name = getUniqueNameBasedOnCurrentTime(queue_base_name)
        self.topic_name = getUniqueNameBasedOnCurrentTime(topic_base_name)

        self.additional_queue_names = []
        self.additional_topic_names = []

    def tearDown(self):
        self.cleanup()
        return super(ServiceBusTest, self).tearDown()

    def cleanup(self):
        try:
            self.sbs.delete_queue(self.queue_name)
        except:
            pass

        for name in self.additional_queue_names:
            try:
                self.sbs.delete_queue(name)
            except:
                pass

        try:
            self.sbs.delete_topic(self.topic_name)
        except:
            pass

        for name in self.additional_topic_names:
            try:
                self.sbs.delete_topic(name)
            except:
                pass

    #--Helpers-----------------------------------------------------------------
    def _create_queue(self, queue_name):
        self.sbs.create_queue(queue_name, None, True)

    def _create_queue_and_send_msg(self, queue_name, msg):
        self._create_queue(queue_name)
        self.sbs.send_queue_message(queue_name, msg)

    def _create_topic(self, topic_name):
        self.sbs.create_topic(topic_name, None, True)

    def _create_topic_and_subscription(self, topic_name, subscription_name):
        self._create_topic(topic_name)
        self._create_subscription(topic_name, subscription_name)

    def _create_subscription(self, topic_name, subscription_name):
        self.sbs.create_subscription(topic_name, subscription_name, None, True)

    #--Test cases for service bus service -------------------------------------
    def test_create_service_bus_missing_arguments(self):
        # Arrange
        if os.environ.has_key(AZURE_SERVICEBUS_NAMESPACE):
            del os.environ[AZURE_SERVICEBUS_NAMESPACE]
        if os.environ.has_key(AZURE_SERVICEBUS_ACCESS_KEY):
            del os.environ[AZURE_SERVICEBUS_ACCESS_KEY]
        if os.environ.has_key(AZURE_SERVICEBUS_ISSUER):
            del os.environ[AZURE_SERVICEBUS_ISSUER]

        # Act
        with self.assertRaises(WindowsAzureError):
            sbs = ServiceBusService()

        # Assert

    def test_create_service_bus_env_variables(self):
        # Arrange
        os.environ[
            AZURE_SERVICEBUS_NAMESPACE] = credentials.getServiceBusNamespace()
        os.environ[
            AZURE_SERVICEBUS_ACCESS_KEY] = credentials.getServiceBusKey()
        os.environ[AZURE_SERVICEBUS_ISSUER] = 'owner'

        # Act
        sbs = ServiceBusService()

        if os.environ.has_key(AZURE_SERVICEBUS_NAMESPACE):
            del os.environ[AZURE_SERVICEBUS_NAMESPACE]
        if os.environ.has_key(AZURE_SERVICEBUS_ACCESS_KEY):
            del os.environ[AZURE_SERVICEBUS_ACCESS_KEY]
        if os.environ.has_key(AZURE_SERVICEBUS_ISSUER):
#.........这里部分代码省略.........
开发者ID:slick666,项目名称:azure-sdk-for-python,代码行数:103,代码来源:test_servicebusservice.py

示例5: ServiceBusService

# 需要导入模块: from azure.servicebus import ServiceBusService [as 别名]
# 或者: from azure.servicebus.ServiceBusService import create_subscription [as 别名]
namespace = config.get("ServiceBus", "Namespace")
key_name = config.get("ServiceBus", "KeyName")
key_value = config.get("ServiceBus", "KeyValue")
arduino_username = config.get("Arduino", "Username")
arduino_password = config.get("Arduino", "Password")

pwd_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
pwd_mgr.add_password("arduino", "http://localhost/mailbox/", arduino_username, arduino_password)
handler = urllib2.HTTPBasicAuthHandler(pwd_mgr)
opener = urllib2.build_opener(handler)
urllib2.install_opener(opener)

try:
    sbs = ServiceBusService(namespace, shared_access_key_name=key_name, shared_access_key_value=key_value)

    sbs.create_subscription("commands", "arduino")

    while True:
        try:
            msg = sbs.receive_subscription_message("commands", "arduino")

            if msg.body:

                displayType = msg.custom_properties["messagetype"]

                logger.info("Received " + displayType + ": " + msg.body)

                url = "http://localhost/mailbox/" + msg.body

                logger.debug("Mailbox message: " + str(url))
开发者ID:photomoose,项目名称:xmas-leds,代码行数:32,代码来源:durrylights.py


注:本文中的azure.servicebus.ServiceBusService.create_subscription方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。