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


Python ServiceBusService.create_event_hub方法代码示例

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


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

示例1: ServiceBusEventHubTest

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

    def setUp(self):
        super(ServiceBusEventHubTest, self).setUp()

        self.sbs = ServiceBusService(
            self.settings.EVENTHUB_NAME,
            shared_access_key_name=self.settings.EVENTHUB_SAS_KEY_NAME,
            shared_access_key_value=self.settings.EVENTHUB_SAS_KEY_VALUE,
            request_session=Session(),
        )

        self._set_service_options(self.sbs, self.settings)

        self.event_hub_name = self.get_resource_name('uthub')

    def tearDown(self):
        if not self.is_playback():
            try:
                self.sbs.delete_event_hub(self.event_hub_name)
            except:
                pass

        return super(ServiceBusEventHubTest, self).tearDown()

    #--Helpers-----------------------------------------------------------------
    def _create_event_hub(self, hub_name):
        self.sbs.create_event_hub(hub_name, None, True)

    #--Test cases for event hubs ----------------------------------------------
    @record
    def test_create_event_hub_no_options(self):
        # Arrange

        # Act
        created = self.sbs.create_event_hub(self.event_hub_name)

        # Assert
        self.assertTrue(created)

    @record
    def test_create_event_hub_no_options_fail_on_exist(self):
        # Arrange

        # Act
        created = self.sbs.create_event_hub(self.event_hub_name, None, True)

        # Assert
        self.assertTrue(created)

    @record
    def test_create_event_hub_with_options(self):
        # Arrange

        # Act
        hub = EventHub()
        hub.message_retention_in_days = 5
        hub.status = 'Active'
        hub.user_metadata = 'hello world'
        hub.partition_count = 32
        created = self.sbs.create_event_hub(self.event_hub_name, hub)

        # Assert
        self.assertTrue(created)
        created_hub = self.sbs.get_event_hub(self.event_hub_name)
        self.assertEqual(created_hub.name, self.event_hub_name)
        self.assertEqual(created_hub.message_retention_in_days,
                         hub.message_retention_in_days)
        self.assertEqual(created_hub.status, hub.status)
        self.assertEqual(created_hub.partition_count, hub.partition_count)
        self.assertEqual(created_hub.user_metadata, hub.user_metadata)
        self.assertEqual(len(created_hub.partition_ids), hub.partition_count)

    @record
    def test_create_event_hub_with_authorization(self):
        # Arrange

        # Act
        hub = EventHub()
        hub.authorization_rules.append(
            AuthorizationRule(
                claim_type='SharedAccessKey',
                claim_value='None',
                rights=['Manage', 'Send', 'Listen'],
                key_name='Key1',
                primary_key='Wli4rewPGuEsLam95nQEwGR+e8b+ynlupZQ7VfjbQnw=',
                secondary_key='jS+lERPBmbBVGJ5JzIwVRtSGYoFUeunRoADNTjwU3jU=',
            )
        )

        created = self.sbs.create_event_hub(self.event_hub_name, hub)

        # Assert
        self.assertTrue(created)
        created_hub = self.sbs.get_event_hub(self.event_hub_name)
        self.assertEqual(created_hub.name, self.event_hub_name)
        self.assertEqual(len(created_hub.authorization_rules), 1)
        self.assertEqual(created_hub.authorization_rules[0].claim_type,
                         hub.authorization_rules[0].claim_type)
        self.assertEqual(created_hub.authorization_rules[0].claim_value,
#.........这里部分代码省略.........
开发者ID:30mps,项目名称:azure-sdk-for-python,代码行数:103,代码来源:test_servicebus_eventhub.py

示例2: socket

# 需要导入模块: from azure.servicebus import ServiceBusService [as 别名]
# 或者: from azure.servicebus.ServiceBusService import create_event_hub [as 别名]
from httplib import HTTPConnection
from azure.servicebus import ServiceBusService


MCAST_GRP = '224.0.0.251'
MCAST_PORT = 6000

sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)
sock.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)

# bind this to the master node's IP address
sock.setsockopt(SOL_IP, IP_ADD_MEMBERSHIP,
                inet_aton(MCAST_GRP)+inet_aton('10.0.0.1'))

sock.bind((MCAST_GRP, MCAST_PORT))
mreq = pack("4sl", inet_aton(MCAST_GRP), INADDR_ANY)
sock.setsockopt(IPPROTO_IP, IP_ADD_MEMBERSHIP, mreq)

sbs = ServiceBusService(service_namespace='knockknockknock',
                        shared_access_key_name='RootManageSharedAccessKey',
                        shared_access_key_value=environ['ACCESS_KEY]')
sbs.create_event_hub('penny')

while True:
    data, srv_sock = sock.recvfrom(8192)
    srv_addr, srv_srcport = srv_sock[0], srv_sock[1]
    data = loads(data.replace('\0',''))
    data['srv_addr'] = srv_addr
    print data
    sbs.send_event('penny', unicode(dumps(data)))
开发者ID:rcarmo,项目名称:raspi-cluster,代码行数:32,代码来源:multicast_azure.py

示例3: ServiceBusService

# 需要导入模块: from azure.servicebus import ServiceBusService [as 别名]
# 或者: from azure.servicebus.ServiceBusService import create_event_hub [as 别名]
from tweepy.streaming import StreamListener
from tweepy import OAuthHandler
from tweepy import Stream
from azure.servicebus import ServiceBusService
import json
from collections import Counter
import urllib3
import sys


key_value = 'TsPSqYRxHLwMfuZW6C+sMWFlX/NuDDfUzhVT/qQNneM=' # SharedAccessKey from Azure portal
key_name = 'manage' # SharedAccessKeyName from Azure portal
sbs = ServiceBusService('w205Ex2twitter',
                        shared_access_key_name=key_name,
                        shared_access_key_value=key_value)
sbs.create_event_hub('w205ex2twitter')

#Variables that contains the user credentials to access Twitter API 
access_token = "723321852928487424-6DpOhp2IVLdLHcT5xqOyp3ZF6KfD045"
access_token_secret = "k1kTDSQke2oivdYwFOwS0cP6bTC4TLK0nM4qpkxhs3tjQ"
consumer_key = "UazvoPbRP6S6X890BWVk9srj5"
consumer_secret = "6McwA8RuB2ZWoDpYP0TpOsqOp9I0PZRfZoesJfLwFfoGw28QKz"

def word_count(tweet):
    # Split the tweet into words
    words = tweet.split()
    # Filter out the hash tags, RT, @ and urls
    valid_words = []
    for word in words:

        # Filter the hash tags
开发者ID:mmarks13,项目名称:w205,代码行数:33,代码来源:Start_Stream.py

示例4: ServiceBusService

# 需要导入模块: from azure.servicebus import ServiceBusService [as 别名]
# 或者: from azure.servicebus.ServiceBusService import create_event_hub [as 别名]
# GrovePi + Grove Temperature Sensor
import time
import grovepi
from azure.servicebus import ServiceBusService

key_name ='RootManageSharedAccessKey' # SharedAccessKeyName from Azure Portal
key_value='' # SharedAccessKey from Azure Portal
sbs = ServiceBusService('asatestsn', shared_access_key_name=key_name, shared_access_key_value=key_value)
sbs.create_event_hub('hubcreationfromlinux')

# Connect the Grove Temperature Sensor to analog port D4
sensor_port = 4
deviceId = "device-1"
#Declare direction to the pin.
#grovepi.pinMode (Temp_sensor,"INPUT")
while True:
    try:
        [temp,hum] = grovepi.dht(sensor_port,0)
        CurrentTime = str(time.localtime(time.time()).tm_hour) + ":" + str(time.localtime(time.time()).tm_min) + ":"+ str(time.localtime(time.time()).tm_sec)
        print "Temperature : ", temp , "Humidity : ", hum, "RecordTime : ", CurrentTime  
        sbs.send_event('hubcreationfromlinux', '{ "DeviceId":"' + deviceId + '", "Temperature":"' + str(temp) +'", "Humidity":"' + str(hum) +'", "RecordTime":"' + str(CurrentTime) +'"}')
        # sbs.send_event('hubcreationfromlinux', '{ "DeviceId":"' + deviceId + '", "Temperature":"' + temperature +'"}')
        time.sleep(1.0)
    except IOError:
        print "Error"
开发者ID:rawatsudhir,项目名称:firstIOTcode,代码行数:27,代码来源:TempData2EH.py

示例5: Flask

# 需要导入模块: from azure.servicebus import ServiceBusService [as 别名]
# 或者: from azure.servicebus.ServiceBusService import create_event_hub [as 别名]
"""

from flask import Flask, request
import datetime, json
app = Flask(__name__)
app.debug = True
# Make the WSGI interface available at the top level so wfastcgi can get it.
wsgi_app = app.wsgi_app
devices = []

from azure.servicebus import ServiceBusService
srvns = 'iotsample0917ns'
key_name = 'rootSAS'
key_value = 'gTTf0bVKzFz2Ufjts8unUQRFMEsQORHwmTzAHtKwJng='  
sbs = ServiceBusService(service_namespace=srvns, shared_access_key_name=key_name, shared_access_key_value=key_value) 
flag = sbs.create_event_hub('iotsample0917')
print(flag)


@app.route('/')
def hi():
    return 'hello world'

@app.route('/Devices/<devid>', methods=['POST'] )
def create_device(devid):
    curdevice = None
    for device in devices:
        if device['deviceid'] == devid:
            curdevice=device
            break
    if curdevice is not None:
开发者ID:gabiera,项目名称:arduino-basic-iot-sample,代码行数:33,代码来源:app.py

示例6: EventHubServiceTest

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

    def setUp(self):
        self.sbs = ServiceBusService(
            credentials.getEventHubNamespace(),
            shared_access_key_name=credentials.getEventHubSasKeyName(),
            shared_access_key_value=credentials.getEventHubSasKeyValue(),
            )

        set_service_options(self.sbs)

        self.event_hub_name = getUniqueName('uthub')

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

    def cleanup(self):
        try:
            self.sbs.delete_event_hub(self.event_hub_name)
        except:
            pass

    #--Helpers-----------------------------------------------------------------
    def _create_event_hub(self, hub_name):
        self.sbs.create_event_hub(hub_name, None, True)

    #--Test cases for event hubs ----------------------------------------------
    def test_create_event_hub_no_options(self):
        # Arrange

        # Act
        created = self.sbs.create_event_hub(self.event_hub_name)

        # Assert
        self.assertTrue(created)

    def test_create_event_hub_no_options_fail_on_exist(self):
        # Arrange

        # Act
        created = self.sbs.create_event_hub(self.event_hub_name, None, True)

        # Assert
        self.assertTrue(created)

    def test_create_event_hub_with_options(self):
        # Arrange

        # Act
        hub = EventHub()
        hub.message_retention_in_days = 5
        hub.status = 'Active'
        hub.user_metadata = 'hello world'
        hub.partition_count = 32
        created = self.sbs.create_event_hub(self.event_hub_name, hub)

        # Assert
        self.assertTrue(created)
        created_hub = self.sbs.get_event_hub(self.event_hub_name)
        self.assertEqual(created_hub.name, self.event_hub_name)
        self.assertEqual(created_hub.message_retention_in_days,
                         hub.message_retention_in_days)
        self.assertEqual(created_hub.status, hub.status)
        self.assertEqual(created_hub.partition_count, hub.partition_count)
        self.assertEqual(created_hub.user_metadata, hub.user_metadata)
        self.assertEqual(len(created_hub.partition_ids), hub.partition_count)

    def test_create_event_hub_with_authorization(self):
        # Arrange

        # Act
        hub = EventHub()
        hub.authorization_rules.append(
            AuthorizationRule(
                claim_type='SharedAccessKey',
                claim_value='None',
                rights=['Manage', 'Send', 'Listen'],
                key_name='Key1',
                primary_key='Wli4rewPGuEsLam95nQEwGR+e8b+ynlupZQ7VfjbQnw=',
                secondary_key='jS+lERPBmbBVGJ5JzIwVRtSGYoFUeunRoADNTjwU3jU=',
            )
        )

        created = self.sbs.create_event_hub(self.event_hub_name, hub)

        # Assert
        self.assertTrue(created)
        created_hub = self.sbs.get_event_hub(self.event_hub_name)
        self.assertEqual(created_hub.name, self.event_hub_name)
        self.assertEqual(len(created_hub.authorization_rules), 1)
        self.assertEqual(created_hub.authorization_rules[0].claim_type,
                         hub.authorization_rules[0].claim_type)
        self.assertEqual(created_hub.authorization_rules[0].claim_value,
                         hub.authorization_rules[0].claim_value)
        self.assertEqual(created_hub.authorization_rules[0].key_name,
                         hub.authorization_rules[0].key_name)
        self.assertEqual(created_hub.authorization_rules[0].primary_key,
                         hub.authorization_rules[0].primary_key)
        self.assertEqual(created_hub.authorization_rules[0].secondary_key,
#.........这里部分代码省略.........
开发者ID:acht1984,项目名称:azure-sdk-for-python,代码行数:103,代码来源:test_eventhubservice.py


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