コード例 #1
0
 def __init__(self, *args, **kwargs):
     """
     Simulate partition pump
     """
     super(EventProcessorHostTestCase, self).__init__(*args, **kwargs)
     _credentials = MockCredentials()
     self._storage_clm = AzureStorageCheckpointLeaseManager(
         _credentials.storage_account, _credentials.storage_key,
         _credentials.lease_container)
     self._loop = asyncio.get_event_loop()
     eh_config = EventHubConfig(_credentials.sb_name,
                                _credentials.eh_name,
                                _credentials.eh_policy,
                                _credentials.eh_key,
                                consumer_group='$default')
     self._host = EventProcessorHost(MockEventProcessor,
                                     eh_config,
                                     self._storage_clm,
                                     loop=self._loop)
     logging.basicConfig(filename='eph.log',
                         level=logging.INFO,
                         format='%(asctime)s:%(msecs)03d, \'%(message)s\' ',
                         datefmt='%Y-%m-%d:%H:%M:%S')
     logging.getLogger().addHandler(
         logging.StreamHandler(stream=sys.stdout))
コード例 #2
0
    def __init__(self, *args, **kwargs):
        """
        Simulate partition pump
        """
        super(PartitionPumpTestCase, self).__init__(*args, **kwargs)
        self._credentials = MockCredentials()
        self._consumer_group = "$Default"
        self._storage_clm = AzureStorageCheckpointLeaseManager(
            self._credentials.storage_account, self._credentials.storage_key,
            self._credentials.lease_container)
        self._host = EventProcessorHost(MockEventProcessor,
                                        self._credentials.eh_address,
                                        self._consumer_group,
                                        storage_manager=self._storage_clm)

        self._lease = AzureBlobLease()
        self._lease.with_partition_id("1")
        self._partition_pump = EventHubPartitionPump(self._host, self._lease)

        logging.basicConfig(filename='eph.log',
                            level=logging.INFO,
                            format='%(asctime)s:%(msecs)03d, \'%(message)s\' ',
                            datefmt='%Y-%m-%d:%H:%M:%S')

        self._loop = asyncio.get_event_loop()
コード例 #3
0
 def __init__(self, *args, **kwargs):
     """
     Simulate partition pump
     """
     super(PartitionManagerTestCase, self).__init__(*args, **kwargs)
     self._credentials = MockCredentials()
     self._consumer_group = "$Default"
     self._host = EventProcessorHost(MockEventProcessor, self._credentials.eh_address,
                                     self._consumer_group, eh_rest_auth=self._credentials.eh_auth)
     self._partition_manager = PartitionManager(self._host)
     self._loop = asyncio.get_event_loop()
コード例 #4
0
 def __init__(self, *args, **kwargs):
     """
     Simulate partition pump
     """
     super(PartitionPumpTestCase, self).__init__(*args, **kwargs)
     self._host = EventProcessorHost(MockEventProcessor, "fake eventHubPath",
                                     "fake consumerGroupName")
     self._lease = Lease()
     self._lease.with_partition_id("1")
     self._partition_pump = PartitionPump(self._host, self._lease)
     self._loop = asyncio.get_event_loop()
コード例 #5
0
class EventProcessorHostTestCase(unittest.TestCase):
    """Tests for `partition_manager.py`."""
    def __init__(self, *args, **kwargs):
        """
        Simulate partition pump
        """
        super(EventProcessorHostTestCase, self).__init__(*args, **kwargs)
        _credentials = MockCredentials()
        self._storage_clm = AzureStorageCheckpointLeaseManager(
            _credentials.storage_account, _credentials.storage_key,
            _credentials.lease_container)
        self._loop = asyncio.get_event_loop()
        eh_config = EventHubConfig(_credentials.sb_name,
                                   _credentials.eh_name,
                                   _credentials.eh_policy,
                                   _credentials.eh_key,
                                   consumer_group='$default')
        self._host = EventProcessorHost(MockEventProcessor,
                                        eh_config,
                                        self._storage_clm,
                                        loop=self._loop)
        logging.basicConfig(filename='eph.log',
                            level=logging.INFO,
                            format='%(asctime)s:%(msecs)03d, \'%(message)s\' ',
                            datefmt='%Y-%m-%d:%H:%M:%S')
        logging.getLogger().addHandler(
            logging.StreamHandler(stream=sys.stdout))

    def test_start(self):
        """
        Test that the processing host starts correctly
        """
        try:
            self._loop.run_until_complete(self._host.open_async())
            self._loop.run_until_complete(self._host.close_async())
        finally:
            self._loop.stop()
    def __init__(self, *args, **kwargs):
        """
        Simulate AzureStorageCheckpointLeaseManager
        """
        super(AzureStorageCheckpointLeaseManagerTestCase,
              self).__init__(*args, **kwargs)
        self._loop = None
        self._credentials = MockCredentials()
        self._consumer_group = "$Default"
        self._host = EventProcessorHost(MockEventProcessor,
                                        self._credentials.eh_address,
                                        self._consumer_group)

        self._storage_clm = AzureStorageCheckpointLeaseManager(
            self._credentials.storage_account, self._credentials.storage_key,
            self._credentials.lease_container, "lease")
コード例 #7
0
STORAGE_ACCOUNT_NAME = STORAGE["AccountName"]
STORAGE_KEY = STORAGE["AccountKey"]
LEASE_CONTAINER_NAME = "python-leases"

EVENT_HUB_CONNECTION_STRING = os.environ.get("EVENT_HUB_CONNECTION_STRING")
if not EVENT_HUB_CONNECTION_STRING:
    raise Exception(
        "Please set environment variable EVENT_HUB_CONNECTION_STRING")
EVENT_HUB = dict(
    token.split("=", 1) for token in EVENT_HUB_CONNECTION_STRING.split(";"))
NAMESPACE = urllib.parse.urlparse(EVENT_HUB["Endpoint"]).netloc.split('.')[0]
ENTITY = EVENT_HUB["EntityPath"]
CONSUMER_GROUP = "$Default"
POLICY_NAME = EVENT_HUB["SharedAccessKeyName"]
POLICY_KEY = EVENT_HUB["SharedAccessKey"]

EH_CONFIG = EventHubConfig(NAMESPACE, ENTITY, POLICY_NAME, POLICY_KEY,
                           CONSUMER_GROUP)
STORAGE_MANAGER = AzureStorageCheckpointLeaseManager(STORAGE_ACCOUNT_NAME,
                                                     STORAGE_KEY,
                                                     LEASE_CONTAINER_NAME)

LOOP = asyncio.get_event_loop()
HOST = EventProcessorHost(EventProcessor,
                          EH_CONFIG,
                          STORAGE_MANAGER,
                          ep_params=[TELEMETRY_CLIENT],
                          loop=LOOP)
LOOP.run_until_complete(HOST.open_async())
LOOP.run_until_complete(HOST.close_async())
コード例 #8
0
    async def process_error_async(self, context, error):
        """
        Called when the underlying client experiences an error while receiving.
        EventProcessorHost will take care of recovering from the error and
        continuing to pump messages,so no action is required from
        (Params) Context: Information about the partition, Error: The error that occured.
        """
        logging.error("Event Processor Error %s ", repr(error))

try:
    # Storage Account Credentials
    STORAGE_ACCOUNT_NAME = "<mystorageaccount>"
    STORAGE_KEY = "<storage_key>"
    LEASE_CONTAINER_NAME = "leases"

    # Eventhub config and storage manager 
    EH_CONFIG = EventHubConfig('<mynamespace>', '<myeventhub>','<SAS-policy>', 
                               '<SAS-key>', consumer_group="$default")
    STORAGE_MANAGER = AzureStorageCheckpointLeaseManager(STORAGE_ACCOUNT_NAME, STORAGE_KEY,
                                                         LEASE_CONTAINER_NAME)
    #Event loop and host
    LOOP = asyncio.get_event_loop()
    HOST = EventProcessorHost(EventProcessor, EH_CONFIG, STORAGE_MANAGER,
                              ep_params=["param1","param2"], loop=LOOP)

    LOOP.run_until_complete(HOST.open_async())
    LOOP.run_until_complete(HOST.close_async())

finally:
    LOOP.stop()