簡體   English   中英

無法通過事件中心在Azure流分析上收到輸入

[英]Cant receive an input on Azure Stream Analytics via Event Hub

我試圖使用事件中心將消息發送到Azure流分析。 在Azure上,我可以在監視器上清楚地看到“事件”活動,但是在Stream Analytics Job上,我只是無法測試輸入數據。

我試圖僅測試一個文件,但我的json文件可以正常工作。 在我用來發送消息的C#代碼下面:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;
using System.IO;
using Newtonsoft.Json;
using Microsoft.Azure.EventHubs;

namespace contosorealtimeapplication

{

public class Program
{
    private static Microsoft.Azure.EventHubs.EventHubClient eventHubClient;
    private const string EventHubConnectionString = "Endpoint=sb://***************.servicebus.windows.net/;SharedAccessKeyName=***************;SharedAccessKey=***************";
    private const string EventHubName = "contosorealtime";

    public static void Main(string[] args)
    {
        MainAsync(args).GetAwaiter().GetResult();
    }

    private static async Task MainAsync(string[] args)
    {
        var connectionStringBuilder = new EventHubsConnectionStringBuilder(EventHubConnectionString)
        {
            EntityPath = EventHubName
        };

        eventHubClient = Microsoft.Azure.EventHubs.EventHubClient.CreateFromConnectionString(connectionStringBuilder.ToString());

        await SendMessagesToEventHub();
        await eventHubClient.CloseAsync();

        Console.WriteLine("Press ENTER to exit.");
        Console.ReadLine();
    }

    // Creates an event hub client and sends 100 messages to the event hub.
    private static async Task SendMessagesToEventHub()
    {
        //get JSON file configured on app-setting
        string localFolder = ConfigurationManager.AppSettings["sourcefolder"];
        string[] fileEntries = Directory.GetFiles(localFolder);
        string message = "";
        string serialisedString = "";

        foreach (string filePath in fileEntries)
        {

            try
            {
                serialisedString = JsonConvert.SerializeObject(filePath);
                message = $"Message {serialisedString}";
                Console.WriteLine($"Sending message: {message}");
                await eventHubClient.SendAsync(new Microsoft.Azure.EventHubs.EventData(Encoding.UTF8.GetBytes(serialisedString)));

            }
            catch (Exception exception)
            {
                Console.WriteLine($"{DateTime.Now} > Exception: {exception.Message}");
            }
        }
    }
}

}

我100%肯定它丟失了partitionkey,但是我找不到正確傳遞它的方法。

我從下面得到了這個例子: https : //docs.microsoft.com/zh-cn/azure/event-hubs/event-hubs-dotnet-standard-getstarted-send

在“事件中心”活動下:

活動中心活動

這是輸入詳細信息:

輸入配置:

嘗試從輸入中上傳示例數據時,出現以下消息,我在Azure流分析作業上收到:

Azure錯誤消息

這是我從文件(json文件)上載數據時的結果:

來自文件的結果數據

有誰知道如何解決嗎?

PS。 傑森工作正常。

我假設您選擇輸入數據格式為json。 在示例代碼中,您正在發送字符串作為事件中心有效負載。 ASA僅支持對象數組或空格分隔的對象。 如果filename是您唯一感興趣的字段,請作為json對象發送它-類似於{ "fileName": "value"}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM