Skip to content

Commit

Permalink
some changes
Browse files Browse the repository at this point in the history
  • Loading branch information
vilit1 committed Jul 10, 2024
1 parent c0a9c8f commit 96539bc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
22 changes: 16 additions & 6 deletions azext_iot/monitor/builders/hub_target_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import asyncio
import uamqp

from azure.cli.core.azclierror import CLIInternalError
from azext_iot.common.sas_token_auth import SasTokenAuthentication
from azext_iot.common.utility import parse_entity, unicode_binary_map, url_encode_str
from azext_iot.monitor.builders._common import query_meta_data
Expand Down Expand Up @@ -84,15 +85,24 @@ async def _build_iot_hub_target_async(self, target):
path=target["events"]["path"],
auth=auth,
)
partition_count = meta_data[b"partition_count"]
partition_ids = []
for i in range(int(partition_count)):
partition_ids.append(str(i))
target["events"]["partition_ids"] = partition_ids
partition_count = meta_data.get(b"partition_count")
else:
endpoint = target["events"]["endpoint"]
path = target["events"]["path"]
partitions = target["events"]["partition_ids"]
partition_count = target["events"].get("partitionCount")

# if partition count is None or 0, throw
if not partition_count or not int(partition_count):
raise CLIInternalError(
f"{target['entity'].split('.')[0]} has no partition count. Please check with the IoT "
"Hub service team to fix your IoT Hub."
)

partitions = target["events"].get("partition_ids", [])
if not partitions:
for i in range(int(partition_count)):
partitions.append(str(i))
target["events"]["partition_ids"] = partitions
auth = self._build_auth_container(target)

return Target(hostname=endpoint, path=path, partitions=partitions, auth=auth)
2 changes: 1 addition & 1 deletion azext_iot/monitor/telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ async def _initiate_event_monitor(
target: Target, enqueued_time_utc, on_message_received, timeout=0
):
if not target.partitions:
logger.debug("No Event Hub partitions found to listen on.")
logger.warning("No Event Hub partitions found to listen on.")
return

coroutines = []
Expand Down

0 comments on commit 96539bc

Please sign in to comment.