简体   繁体   English

Azure 事件中心 - 如何通过 https 从传感器接收数据?

[英]Azure Event Hub - How to receive data from sensor via https?

I have a sensor that tracks people coming in and out of the building.我有一个传感器可以跟踪进出建筑物的人。 In every event when someone comes in or out, the sensor sends the data via HTTPS to any URL or IP address I specify.在每次有人进出时,传感器都会通过 HTTPS 将数据发送到我指定的任何 URL 或 IP 地址。 If I set up my laptop as a webserver that listens for incoming traffic I can receive the data.如果我将笔记本电脑设置为监听传入流量的网络服务器,我可以接收数据。

What I am trying to do is to go serverless and use Azure Event Hubs.我想要做的是 go 无服务器并使用 Azure 事件中心。 I set up an event hub and run the test by pushing data from my laptop using a python script and I can successfully receive the data.我设置了一个事件中心并通过使用 python 脚本从我的笔记本电脑推送数据来运行测试,我可以成功接收数据。 Here is the sample code I used to test;这是我用来测试的示例代码; I'm using the connection string to authenticate.我正在使用连接字符串进行身份验证。

import time
import os
import uuid
import datetime
import random
import json

from azure.eventhub import EventHubProducerClient, EventData

# This script simulates the production of events for 10 devices.
devices = []
for x in range(0, 10):
    devices.append(str(uuid.uuid4()))

# Create a producer client to produce and publish events to the event hub.
producer = EventHubProducerClient.from_connection_string(conn_str="My End Point String", eventhub_name="my eventhub name")
for y in range(0,20):    # For each device, produce 20 events. 
    event_data_batch = producer.create_batch() # Create a batch. You will add events to the batch later. 
    for dev in devices:
        # Create a dummy reading.
        reading = {'id': dev, 'timestamp': str(datetime.datetime.utcnow()), 'uv': random.random(), 'temperature': random.randint(70, 100), 'humidity': random.randint(70, 100)}
        s = json.dumps(reading) # Convert the reading into a JSON string.
        event_data_batch.add(EventData(s)) # Add event data to the batch.
    producer.send_batch(event_data_batch) # Send the batch of events to the event hub.

# Close the producer.    
producer.close()

On my sensor, I don't have an option for these two things to enter.在我的传感器上,我没有输入这两件事的选项。 I only have the option to enter URL/IP.我只能选择输入 URL/IP。

Any idea how I can set this up?知道如何设置吗?

I suggest moving data this way: Sensor > Azure Functions HTTP trigger > Azure Event Hubs我建议以这种方式移动数据: Sensor > Azure Functions HTTP trigger > Azure Event Hubs

In summary, your sensor will call an HTTP endpoint hosted on Azure Functions and function will check and transform sensor data before forwarding it to an eventhub.总之,您的传感器将调用托管在 Azure 函数上的 HTTP 端点,并且 function 将在将传感器数据转发到 eventhub 之前对其进行检查和转换。

Here is documentation on HTTP trigger - https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-http-webhook-trigger?tabs=csharp这是有关 HTTP 触发器的文档 - https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-http-webhook-trigger?tabs=csharp

Here is the documentation on Event Hubs output binding - https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-event-hubs-output?tabs=csharp这是有关事件中心 output 绑定的文档 - https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-event-hubs-output?tabs=csharp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法通过事件中心在Azure流分析上收到输入 - Cant receive an input on Azure Stream Analytics via Event Hub 如何仅在事件中心接收最近的数据 - How to receive the recent data only in event hub 我们如何在没有存储容器名称、StorageAccountName 和 StorageAccountKey 这些信息的情况下从 Azure 事件中心接收事件 - How We can receive event from Azure event hub without Storage Container Name ,StorageAccountName and StorageAccountKey these information Azure 事件中心的 HTTPS 端点 - HTTPS endpoint of Azure event hub 如何查看Azure Event Hub中的最新数据? 。净 - How to peek recent data from Azure Event Hub? .NET 向 Azure 事件中心中的特定使用者组发送消息和从其接收消息 - Send messages to and receive from a particular Consumer Group in Azure Event Hub Rust:从 Azure 事件中心接收 AMQP 消息 - Rust: Receive AMQP messages from Azure Event Hub 如何使用Azure Notification Hubs从事件中心接收消息并转发到android应用程序? - How to receive messages from event hub and forward to android application using Azure Notification Hubs? 从 Azure 事件中心到 Azure Redis 缓存的数据传输 - Data transfer from Azure event hub to Azure Redis Cache 部分数据从事件中心摄取到 Azure 数据资源管理器 - Partial Data Being Ingested To Azure Data Explorer From Event Hub
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM