-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSALESS~1.IPY
More file actions
1 lines (1 loc) · 15.5 KB
/
SALESS~1.IPY
File metadata and controls
1 lines (1 loc) · 15.5 KB
1
{"cells":[{"cell_type":"code","source":["pip install azure-eventhub"],"metadata":{"application/vnd.databricks.v1+cell":{"showTitle":false,"cellMetadata":{"rowLimit":10000,"byteLimit":2048000},"nuid":"7e84203a-2435-4a7f-9a66-d3182943093e","inputWidgets":{},"title":""}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"datasetInfos":[],"data":"<div class=\"ansiout\">Python interpreter will be restarted.\nCollecting azure-eventhub\n Downloading azure_eventhub-5.11.1-py3-none-any.whl (305 kB)\nCollecting typing-extensions>=4.0.1\n Downloading typing_extensions-4.5.0-py3-none-any.whl (27 kB)\nCollecting azure-core<2.0.0,>=1.14.0\n Downloading azure_core-1.26.3-py3-none-any.whl (174 kB)\nRequirement already satisfied: requests>=2.18.4 in /databricks/python3/lib/python3.8/site-packages (from azure-core<2.0.0,>=1.14.0->azure-eventhub) (2.25.1)\nRequirement already satisfied: six>=1.11.0 in /databricks/python3/lib/python3.8/site-packages (from azure-core<2.0.0,>=1.14.0->azure-eventhub) (1.15.0)\nRequirement already satisfied: urllib3<1.27,>=1.21.1 in /databricks/python3/lib/python3.8/site-packages (from requests>=2.18.4->azure-core<2.0.0,>=1.14.0->azure-eventhub) (1.25.11)\nRequirement already satisfied: certifi>=2017.4.17 in /databricks/python3/lib/python3.8/site-packages (from requests>=2.18.4->azure-core<2.0.0,>=1.14.0->azure-eventhub) (2020.12.5)\nRequirement already satisfied: chardet<5,>=3.0.2 in /databricks/python3/lib/python3.8/site-packages (from requests>=2.18.4->azure-core<2.0.0,>=1.14.0->azure-eventhub) (4.0.0)\nRequirement already satisfied: idna<3,>=2.5 in /databricks/python3/lib/python3.8/site-packages (from requests>=2.18.4->azure-core<2.0.0,>=1.14.0->azure-eventhub) (2.10)\nInstalling collected packages: typing-extensions, azure-core, azure-eventhub\nSuccessfully installed azure-core-1.26.3 azure-eventhub-5.11.1 typing-extensions-4.5.0\nPython interpreter will be restarted.\n</div>","removedWidgets":[],"addedWidgets":{},"metadata":{},"type":"html","arguments":{}}},"output_type":"display_data","data":{"text/html":["<style scoped>\n .ansiout {\n display: block;\n unicode-bidi: embed;\n white-space: pre-wrap;\n word-wrap: break-word;\n word-break: break-all;\n font-family: \"Source Code Pro\", \"Menlo\", monospace;;\n font-size: 13px;\n color: #555;\n margin-left: 4px;\n line-height: 19px;\n }\n</style>\n<div class=\"ansiout\">Python interpreter will be restarted.\nCollecting azure-eventhub\n Downloading azure_eventhub-5.11.1-py3-none-any.whl (305 kB)\nCollecting typing-extensions>=4.0.1\n Downloading typing_extensions-4.5.0-py3-none-any.whl (27 kB)\nCollecting azure-core<2.0.0,>=1.14.0\n Downloading azure_core-1.26.3-py3-none-any.whl (174 kB)\nRequirement already satisfied: requests>=2.18.4 in /databricks/python3/lib/python3.8/site-packages (from azure-core<2.0.0,>=1.14.0->azure-eventhub) (2.25.1)\nRequirement already satisfied: six>=1.11.0 in /databricks/python3/lib/python3.8/site-packages (from azure-core<2.0.0,>=1.14.0->azure-eventhub) (1.15.0)\nRequirement already satisfied: urllib3<1.27,>=1.21.1 in /databricks/python3/lib/python3.8/site-packages (from requests>=2.18.4->azure-core<2.0.0,>=1.14.0->azure-eventhub) (1.25.11)\nRequirement already satisfied: certifi>=2017.4.17 in /databricks/python3/lib/python3.8/site-packages (from requests>=2.18.4->azure-core<2.0.0,>=1.14.0->azure-eventhub) (2020.12.5)\nRequirement already satisfied: chardet<5,>=3.0.2 in /databricks/python3/lib/python3.8/site-packages (from requests>=2.18.4->azure-core<2.0.0,>=1.14.0->azure-eventhub) (4.0.0)\nRequirement already satisfied: idna<3,>=2.5 in /databricks/python3/lib/python3.8/site-packages (from requests>=2.18.4->azure-core<2.0.0,>=1.14.0->azure-eventhub) (2.10)\nInstalling collected packages: typing-extensions, azure-core, azure-eventhub\nSuccessfully installed azure-core-1.26.3 azure-eventhub-5.11.1 typing-extensions-4.5.0\nPython interpreter will be restarted.\n</div>"]}}],"execution_count":0},{"cell_type":"code","source":["pip install azure-servicebus"],"metadata":{"application/vnd.databricks.v1+cell":{"showTitle":false,"cellMetadata":{"rowLimit":10000,"byteLimit":2048000},"nuid":"96295a21-46c9-4cdf-8824-400b83c538a5","inputWidgets":{},"title":""}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"datasetInfos":[],"data":"<div class=\"ansiout\">Python interpreter will be restarted.\nCollecting azure-servicebus\n Downloading azure_servicebus-7.8.2-py3-none-any.whl (210 kB)\nRequirement already satisfied: azure-core<2.0.0,>=1.14.0 in /local_disk0/.ephemeral_nfs/envs/pythonEnv-1a6b86dc-2ee5-43ce-95aa-16704b5d330f/lib/python3.8/site-packages (from azure-servicebus) (1.26.3)\nCollecting isodate>=0.6.0\n Downloading isodate-0.6.1-py2.py3-none-any.whl (41 kB)\nCollecting uamqp<2.0.0,>=1.6.3\n Downloading uamqp-1.6.4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.0 MB)\nCollecting msrest<2.0.0,>=0.6.17\n Downloading msrest-0.7.1-py3-none-any.whl (85 kB)\nRequirement already satisfied: typing-extensions>=3.7.4.3 in /local_disk0/.ephemeral_nfs/envs/pythonEnv-1a6b86dc-2ee5-43ce-95aa-16704b5d330f/lib/python3.8/site-packages (from azure-servicebus) (4.5.0)\nCollecting azure-common~=1.1\n Downloading azure_common-1.1.28-py2.py3-none-any.whl (14 kB)\nRequirement already satisfied: requests>=2.18.4 in /databricks/python3/lib/python3.8/site-packages (from azure-core<2.0.0,>=1.14.0->azure-servicebus) (2.25.1)\nRequirement already satisfied: six>=1.11.0 in /databricks/python3/lib/python3.8/site-packages (from azure-core<2.0.0,>=1.14.0->azure-servicebus) (1.15.0)\nRequirement already satisfied: certifi>=2017.4.17 in /databricks/python3/lib/python3.8/site-packages (from msrest<2.0.0,>=0.6.17->azure-servicebus) (2020.12.5)\nCollecting requests-oauthlib>=0.5.0\n Downloading requests_oauthlib-1.3.1-py2.py3-none-any.whl (23 kB)\nRequirement already satisfied: urllib3<1.27,>=1.21.1 in /databricks/python3/lib/python3.8/site-packages (from requests>=2.18.4->azure-core<2.0.0,>=1.14.0->azure-servicebus) (1.25.11)\nRequirement already satisfied: chardet<5,>=3.0.2 in /databricks/python3/lib/python3.8/site-packages (from requests>=2.18.4->azure-core<2.0.0,>=1.14.0->azure-servicebus) (4.0.0)\nRequirement already satisfied: idna<3,>=2.5 in /databricks/python3/lib/python3.8/site-packages (from requests>=2.18.4->azure-core<2.0.0,>=1.14.0->azure-servicebus) (2.10)\nCollecting oauthlib>=3.0.0\n Downloading oauthlib-3.2.2-py3-none-any.whl (151 kB)\nInstalling collected packages: oauthlib, requests-oauthlib, isodate, uamqp, msrest, azure-common, azure-servicebus\nSuccessfully installed azure-common-1.1.28 azure-servicebus-7.8.2 isodate-0.6.1 msrest-0.7.1 oauthlib-3.2.2 requests-oauthlib-1.3.1 uamqp-1.6.4\nPython interpreter will be restarted.\n</div>","removedWidgets":[],"addedWidgets":{},"metadata":{},"type":"html","arguments":{}}},"output_type":"display_data","data":{"text/html":["<style scoped>\n .ansiout {\n display: block;\n unicode-bidi: embed;\n white-space: pre-wrap;\n word-wrap: break-word;\n word-break: break-all;\n font-family: \"Source Code Pro\", \"Menlo\", monospace;;\n font-size: 13px;\n color: #555;\n margin-left: 4px;\n line-height: 19px;\n }\n</style>\n<div class=\"ansiout\">Python interpreter will be restarted.\nCollecting azure-servicebus\n Downloading azure_servicebus-7.8.2-py3-none-any.whl (210 kB)\nRequirement already satisfied: azure-core<2.0.0,>=1.14.0 in /local_disk0/.ephemeral_nfs/envs/pythonEnv-1a6b86dc-2ee5-43ce-95aa-16704b5d330f/lib/python3.8/site-packages (from azure-servicebus) (1.26.3)\nCollecting isodate>=0.6.0\n Downloading isodate-0.6.1-py2.py3-none-any.whl (41 kB)\nCollecting uamqp<2.0.0,>=1.6.3\n Downloading uamqp-1.6.4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.0 MB)\nCollecting msrest<2.0.0,>=0.6.17\n Downloading msrest-0.7.1-py3-none-any.whl (85 kB)\nRequirement already satisfied: typing-extensions>=3.7.4.3 in /local_disk0/.ephemeral_nfs/envs/pythonEnv-1a6b86dc-2ee5-43ce-95aa-16704b5d330f/lib/python3.8/site-packages (from azure-servicebus) (4.5.0)\nCollecting azure-common~=1.1\n Downloading azure_common-1.1.28-py2.py3-none-any.whl (14 kB)\nRequirement already satisfied: requests>=2.18.4 in /databricks/python3/lib/python3.8/site-packages (from azure-core<2.0.0,>=1.14.0->azure-servicebus) (2.25.1)\nRequirement already satisfied: six>=1.11.0 in /databricks/python3/lib/python3.8/site-packages (from azure-core<2.0.0,>=1.14.0->azure-servicebus) (1.15.0)\nRequirement already satisfied: certifi>=2017.4.17 in /databricks/python3/lib/python3.8/site-packages (from msrest<2.0.0,>=0.6.17->azure-servicebus) (2020.12.5)\nCollecting requests-oauthlib>=0.5.0\n Downloading requests_oauthlib-1.3.1-py2.py3-none-any.whl (23 kB)\nRequirement already satisfied: urllib3<1.27,>=1.21.1 in /databricks/python3/lib/python3.8/site-packages (from requests>=2.18.4->azure-core<2.0.0,>=1.14.0->azure-servicebus) (1.25.11)\nRequirement already satisfied: chardet<5,>=3.0.2 in /databricks/python3/lib/python3.8/site-packages (from requests>=2.18.4->azure-core<2.0.0,>=1.14.0->azure-servicebus) (4.0.0)\nRequirement already satisfied: idna<3,>=2.5 in /databricks/python3/lib/python3.8/site-packages (from requests>=2.18.4->azure-core<2.0.0,>=1.14.0->azure-servicebus) (2.10)\nCollecting oauthlib>=3.0.0\n Downloading oauthlib-3.2.2-py3-none-any.whl (151 kB)\nInstalling collected packages: oauthlib, requests-oauthlib, isodate, uamqp, msrest, azure-common, azure-servicebus\nSuccessfully installed azure-common-1.1.28 azure-servicebus-7.8.2 isodate-0.6.1 msrest-0.7.1 oauthlib-3.2.2 requests-oauthlib-1.3.1 uamqp-1.6.4\nPython interpreter will be restarted.\n</div>"]}}],"execution_count":0},{"cell_type":"code","source":["import asyncio\n\nfrom azure.eventhub.aio import EventHubProducerClient\nfrom azure.eventhub import EventData"],"metadata":{"application/vnd.databricks.v1+cell":{"showTitle":false,"cellMetadata":{"rowLimit":10000,"byteLimit":2048000},"nuid":"dd9912f8-9faa-491b-a6e1-d49841bee98e","inputWidgets":{},"title":""}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"datasetInfos":[],"data":"<div class=\"ansiout\"></div>","removedWidgets":[],"addedWidgets":{},"metadata":{},"type":"html","arguments":{}}},"output_type":"display_data","data":{"text/html":["<style scoped>\n .ansiout {\n display: block;\n unicode-bidi: embed;\n white-space: pre-wrap;\n word-wrap: break-word;\n word-break: break-all;\n font-family: \"Source Code Pro\", \"Menlo\", monospace;;\n font-size: 13px;\n color: #555;\n margin-left: 4px;\n line-height: 19px;\n }\n</style>\n<div class=\"ansiout\"></div>"]}}],"execution_count":0},{"cell_type":"markdown","source":["async def run():\n \n producer = EventHubProducerClient.from_connection_string(conn_str=\"Endpoint=sb://db-eventhub-namespace.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=86ATi9XElcqYcspgAo8KNdXzMiWsSJbj++AEhA35NY8=\", eventhub_name=\"eventhub-sales\")\n \n async with producer:\n\n event_data_batch = await producer.create_batch()\n \n event_data_batch.add(EventData(\n '{\"State\":\"Kentucky\",\"Category\":\"Furniture\",\"Sub-Category\":\"Bookcases\",\"Sales\":261.96,\"Quantity\":2,\"Profit\":41.9136,\"Timestamp\": \"2021-10-09 07:22:13\"}'))\n event_data_batch.add(EventData(\n '{\"State\":\"Kentucky\",\"Category\":\"Furniture\",\"Sub-Category\":\"Chairs\",\"Sales\":731.94,\"Quantity\":3,\"Profit\":219.582,\"Timestamp\": \"2021-10-09 07:23:34\"}'))\n event_data_batch.add(EventData(\n '{\"State\":\"California\",\"Category\":\"Office Supplies\",\"Sub-Category\":\"Labels\",\"Sales\":14.62,\"Quantity\":2,\"Profit\":6.8714,\"Timestamp\": \"2021-10-09 07:22:45\"}'))\n event_data_batch.add(EventData(\n '{\"State\":\"Florida\",\"Category\":\"Furniture\",\"Sub-Category\":\"Tables\",\"Sales\":957.5775,\"Quantity\":5,\"Profit\":-383.031,\"Timestamp\": \"2021-10-09 07:23:03\"}'))\n event_data_batch.add(EventData(\n '{\"State\":\"Florida\",\"Category\":\"Office Supplies\",\"Sub-Category\":\"Storage\",\"Sales\":22.368,\"Quantity\":2,\"Profit\":2.5164,\"Timestamp\": \"2021-10-09 07:25:55\"}'))\n event_data_batch.add(EventData(\n '{\"State\":\"California\",\"Category\":\"Furniture\",\"Sub-Category\":\"Furnishings\",\"Sales\":48.86,\"Quantity\":7,\"Profit\":14.1694,\"Timestamp\": \"2021-10-09 07:24:37\"}'))\n \n\n await producer.send_batch(event_data_batch)\n\nloop = asyncio.get_event_loop()\nloop.run_until_complete(run())"],"metadata":{"application/vnd.databricks.v1+cell":{"showTitle":false,"cellMetadata":{"rowLimit":10000,"byteLimit":2048000},"nuid":"452584a8-b759-4c6c-9d39-abae7bd6c244","inputWidgets":{},"title":""}}},{"cell_type":"code","source":["async def run():\n \n producer = EventHubProducerClient.from_connection_string(conn_str=\"Endpoint=sb://db-eventhub-namespace.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=86ATi9XElcqYcspgAo8KNdXzMiWsSJbj++AEhA35NY8=\", eventhub_name=\"eventhub-sales\")\n \n async with producer:\n\n event_data_batch = await producer.create_batch()\n \n event_data_batch.add(EventData(\n '{\"State\":\"California\",\"Category\":\"Office Supplies\",\"Sub-Category\":\"Binders\",\"Sales\":18.504,\"Quantity\":3,\"Profit\":5.7825,\"Timestamp\": \"2021-10-09 07:38:26\"}'))\n event_data_batch.add(EventData(\n '{\"State\":\"Kentucky\",\"Category\":\"Office Supplies\",\"Sub-Category\":\"Appliances\",\"Sales\":114.9,\"Quantity\":5,\"Profit\":34.47,\"Timestamp\": \"2021-10-09 07:39:01\"}'))\n \n\n await producer.send_batch(event_data_batch)\n\nloop = asyncio.get_event_loop()\nloop.run_until_complete(run())"],"metadata":{"application/vnd.databricks.v1+cell":{"showTitle":false,"cellMetadata":{"rowLimit":10000,"byteLimit":2048000},"nuid":"6888e364-dd65-4f28-a371-cf04ee326559","inputWidgets":{},"title":""}},"outputs":[{"output_type":"display_data","metadata":{"application/vnd.databricks.v1+output":{"datasetInfos":[],"data":"<div class=\"ansiout\"></div>","removedWidgets":[],"addedWidgets":{},"metadata":{},"type":"html","arguments":{}}},"output_type":"display_data","data":{"text/html":["<style scoped>\n .ansiout {\n display: block;\n unicode-bidi: embed;\n white-space: pre-wrap;\n word-wrap: break-word;\n word-break: break-all;\n font-family: \"Source Code Pro\", \"Menlo\", monospace;;\n font-size: 13px;\n color: #555;\n margin-left: 4px;\n line-height: 19px;\n }\n</style>\n<div class=\"ansiout\"></div>"]}}],"execution_count":0},{"cell_type":"code","source":[""],"metadata":{"application/vnd.databricks.v1+cell":{"showTitle":false,"cellMetadata":{},"nuid":"11f0fb57-38cf-47b9-b9eb-a0edaf4d4a4a","inputWidgets":{},"title":""}},"outputs":[],"execution_count":0}],"metadata":{"application/vnd.databricks.v1+notebook":{"notebookName":"SalesSource(attached to Watermarking (Event Hub as stream source)","dashboards":[],"notebookMetadata":{"pythonIndentUnit":4},"language":"python","widgets":{},"notebookOrigID":582561637694164}},"nbformat":4,"nbformat_minor":0}