updated based on feedback from Serkant and Jesse

This commit is contained in:
spelluru 2020-01-09 16:17:16 -05:00 коммит произвёл Serkant Karaca
Родитель 9b08cd3d35
Коммит 6b6182b250
19 изменённых файлов: 166 добавлений и 120 удалений

Просмотреть файл

@ -7,7 +7,7 @@
<ItemGroup>
<PackageReference Include="Azure.Messaging.EventHubs" Version="5.0.0-preview.6" />
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
</ItemGroup>
</Project>

Просмотреть файл

@ -11,22 +11,17 @@ namespace Producer
using System.IO;
public class Program
{
private const string EventHubConnectionString = "<EVENT HUBS NAMESPACE CONNECTION STRING>";
{
private const string EventHubNamespaceConnectionString = "<EVENT HUBS NAMESPACE CONNECTION STRING>";
private const string EventHubName = "<EVENT HUB NAME>";
private const string TransactionsDumpFile = "mocktransactions.csv";
private static EventHubProducerClient producerClient;
public static int Main()
{
return MainAsync().GetAwaiter().GetResult();
}
private static async Task<int> MainAsync()
static async Task Main()
{
// create an Event Hubs Producer client using the namespace connection string and the event hub name
producerClient = new EventHubProducerClient(EventHubConnectionString, EventHubName);
producerClient = new EventHubProducerClient(EventHubNamespaceConnectionString, EventHubName);
// send messages to the event hub
await SendMessagesToEventHubAsync(1000);
@ -35,8 +30,6 @@ namespace Producer
Console.WriteLine("Press [enter] to exit.");
Console.ReadLine();
return 0;
}
// Creates an Event Hub client and sends messages to the event hub.
@ -52,19 +45,22 @@ namespace Producer
File.Delete(TransactionsDumpFile);
}
File.AppendAllText(
await File.AppendAllTextAsync(
TransactionsDumpFile,
$"CreditCardId,Timestamp,Location,Amount,Type{Environment.NewLine}");
foreach (var t in transactions)
int numSuccessfulMessages = 0;
try
{
try
// create a batch using the producer client
EventDataBatch eventBatch = await producerClient.CreateBatchAsync();
foreach (var t in transactions)
{
// we don't send the transaction type as part of the message.
// that is up to the downstream analytics to figure out!
// we just pretty print them here so they can easily be compared with the downstream
// analytics results.
var message = t.Data.ToJson();
var message = t.Data.ToJson();
if (t.Type == TransactionType.Suspect)
{
@ -84,22 +80,21 @@ namespace Producer
File.AppendAllText(TransactionsDumpFile, line);
// prepare a batch of events to send to the event hub. only one event in this case.
EventDataBatch eventBatch = await producerClient.CreateBatchAsync();
// add the message to the batch
eventBatch.TryAdd(new EventData(Encoding.UTF8.GetBytes(message)));
// send the message to the event hub using the producer object
await producerClient.SendAsync(eventBatch);
}
catch (Exception ex)
{
Console.WriteLine($"{t.ToJson()}{Environment.NewLine}Exception: {ex.Message}");
numSuccessfulMessages++;
}
// send the batch of messages to the event hub using the producer object
await producerClient.SendAsync(eventBatch);
await Task.Delay(10);
}
Console.WriteLine($"{numMessagesToSend} messages sent.");
catch (Exception ex)
{
Console.WriteLine($"{Environment.NewLine}Exception: {ex.Message}");
}
Console.WriteLine();
Console.WriteLine($"{numSuccessfulMessages} messages sent successfully.");
}
}
}

Просмотреть файл

@ -7,7 +7,19 @@
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
<bindingRedirect oldVersion="0.0.0.0-10.0.0.0" newVersion="10.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Numerics.Vectors" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.1.4.0" newVersion="4.1.4.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.1" newVersion="4.0.1.1" />
</dependentAssembly>
</assemblyBinding>
</runtime>

Просмотреть файл

@ -35,12 +35,24 @@
<Reference Include="Avro, Version=0.9.0.0, Culture=neutral, PublicKeyToken=b1248d7eeb9d0814, processorArchitecture=MSIL">
<HintPath>..\packages\Apache.Avro.1.7.7.2\lib\Avro.dll</HintPath>
</Reference>
<Reference Include="Azure.Core, Version=1.0.1.0, Culture=neutral, PublicKeyToken=92742159e12e44c8, processorArchitecture=MSIL">
<HintPath>..\packages\Azure.Core.1.0.1\lib\netstandard2.0\Azure.Core.dll</HintPath>
</Reference>
<Reference Include="Azure.Storage.Blobs, Version=12.1.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8, processorArchitecture=MSIL">
<HintPath>..\packages\Azure.Storage.Blobs.12.1.0\lib\netstandard2.0\Azure.Storage.Blobs.dll</HintPath>
</Reference>
<Reference Include="Azure.Storage.Common, Version=12.1.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8, processorArchitecture=MSIL">
<HintPath>..\packages\Azure.Storage.Common.12.1.0\lib\netstandard2.0\Azure.Storage.Common.dll</HintPath>
</Reference>
<Reference Include="log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821, processorArchitecture=MSIL">
<HintPath>..\packages\log4net.1.2.10\lib\2.0\log4net.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Azure.KeyVault.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Azure.KeyVault.Core.1.0.0\lib\net40\Microsoft.Azure.KeyVault.Core.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Bcl.AsyncInterfaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Bcl.AsyncInterfaces.1.0.0\lib\net461\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Data.Edm, Version=5.8.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Data.Edm.5.8.2\lib\net40\Microsoft.Data.Edm.dll</HintPath>
</Reference>
@ -50,18 +62,36 @@
<Reference Include="Microsoft.Data.Services.Client, Version=5.8.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Data.Services.Client.5.8.2\lib\net40\Microsoft.Data.Services.Client.dll</HintPath>
</Reference>
<Reference Include="Microsoft.WindowsAzure.Storage, Version=8.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\WindowsAzure.Storage.8.3.0\lib\net45\Microsoft.WindowsAzure.Storage.dll</HintPath>
<Reference Include="Microsoft.WindowsAzure.Storage, Version=9.3.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\WindowsAzure.Storage.9.3.3\lib\net45\Microsoft.WindowsAzure.Storage.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.10.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Buffers.4.5.0\lib\netstandard2.0\System.Buffers.dll</HintPath>
</Reference>
<Reference Include="System.Core" />
<Reference Include="System.Diagnostics.DiagnosticSource, Version=4.0.4.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Diagnostics.DiagnosticSource.4.6.0\lib\net46\System.Diagnostics.DiagnosticSource.dll</HintPath>
</Reference>
<Reference Include="System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Memory.4.5.3\lib\netstandard2.0\System.Memory.dll</HintPath>
</Reference>
<Reference Include="System.Numerics" />
<Reference Include="System.Numerics.Vectors, Version=4.1.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
</Reference>
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.5.2\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
</Reference>
<Reference Include="System.Spatial, Version=5.8.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\System.Spatial.5.8.2\lib\net40\System.Spatial.dll</HintPath>
</Reference>
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.2\lib\netstandard2.0\System.Threading.Tasks.Extensions.dll</HintPath>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />

Просмотреть файл

@ -1,17 +1,18 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Avro.File;
using Avro.Generic;
using Newtonsoft.Json;
using Microsoft.WindowsAzure.Storage;
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
namespace DWDumper
{
using System;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using Avro.File;
using Avro.Generic;
using Newtonsoft.Json;
using Azure.Storage.Blobs;
using System.IO;
/// <summary>
/// A simple test program to dump a single Avro blob file created by EventHubs Capture into a SQL data warehouse (DW).
/// This is useful for testing connections with your SQL DW before integrating this DW dumping code with Azure Functions
@ -19,9 +20,11 @@ namespace DWDumper
class Program
{
private const string StorageConnectionString = "[provide your storage connection string]";
private const string EventHubsCaptureAvroBlobUri = "[provide the blob path to a single blob file just to test if it can be parsed and dumped to the DW]";
private const string EventHubsCaptureAvroBlobContainer = "<< Blobs container>>";
private const string EventHubsCaptureAvroBlobName = "<<Blob name>>";
private const string SqlDwConnection = "[provide the SQL DW connection string]";
private static int Main(string[] args)
{
var p = new Program();
@ -33,14 +36,17 @@ namespace DWDumper
public void Dump()
{
// Get the blob reference
var storageAccount = CloudStorageAccount.Parse(StorageConnectionString);
var blobClient = storageAccount.CreateCloudBlobClient();
var blob = blobClient.GetBlobReferenceFromServer(new Uri(EventHubsCaptureAvroBlobUri));
BlobContainerClient blobContainer = new BlobContainerClient(StorageConnectionString, EventHubsCaptureAvroBlobContainer);
BlobClient blob = blobContainer.GetBlobClient(EventHubsCaptureAvroBlobName);
// Download the content to a memory stream
Stream blobStream = new MemoryStream();
blob.DownloadToAsync(blobStream);
using (var dataTable = GetWindTurbineMetricsTable())
{
// Parse the Avro File
using (var avroReader = DataFileReader<GenericRecord>.OpenReader(blob.OpenRead()))
using (var avroReader = DataFileReader<GenericRecord>.OpenReader(blobStream))
{
while (avroReader.HasNext())
{

Просмотреть файл

@ -1,7 +1,9 @@
using System;
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
namespace DWDumper
{
using System;
// TODO, move this class to a Contracts assembly that is shared across different projects
class WindTurbineMeasure
{

Просмотреть файл

@ -1,16 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Apache.Avro" version="1.7.7.2" targetFramework="net461" />
<package id="Azure.Core" version="1.0.1" targetFramework="net461" />
<package id="Azure.Storage.Blobs" version="12.1.0" targetFramework="net461" />
<package id="Azure.Storage.Common" version="12.1.0" targetFramework="net461" />
<package id="log4net" version="1.2.10" targetFramework="net461" />
<package id="Microsoft.Azure.KeyVault.Core" version="1.0.0" targetFramework="net461" />
<package id="Microsoft.Bcl.AsyncInterfaces" version="1.0.0" targetFramework="net461" />
<package id="Microsoft.Data.Edm" version="5.8.2" targetFramework="net461" />
<package id="Microsoft.Data.OData" version="5.8.2" targetFramework="net461" />
<package id="Microsoft.Data.Services.Client" version="5.8.2" targetFramework="net461" />
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net461" />
<package id="Newtonsoft.Json" version="10.0.2" targetFramework="net461" />
<package id="System.Buffers" version="4.5.0" targetFramework="net461" />
<package id="System.ComponentModel.EventBasedAsync" version="4.0.11" targetFramework="net461" />
<package id="System.Diagnostics.DiagnosticSource" version="4.6.0" targetFramework="net461" />
<package id="System.Dynamic.Runtime" version="4.0.0" targetFramework="net461" />
<package id="System.Linq.Queryable" version="4.0.0" targetFramework="net461" />
<package id="System.Memory" version="4.5.3" targetFramework="net461" />
<package id="System.Net.Requests" version="4.0.11" targetFramework="net461" />
<package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net461" />
<package id="System.Runtime.CompilerServices.Unsafe" version="4.5.2" targetFramework="net461" />
<package id="System.Spatial" version="5.8.2" targetFramework="net461" />
<package id="WindowsAzure.Storage" version="8.3.0" targetFramework="net461" />
<package id="System.Threading.Tasks.Extensions" version="4.5.2" targetFramework="net461" />
<package id="WindowsAzure.Storage" version="9.3.3" targetFramework="net461" />
</packages>

Просмотреть файл

@ -1,3 +1,6 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
namespace FunctionEGDWDumper
{
/// <summary>

Просмотреть файл

@ -8,20 +8,22 @@ using System.Globalization;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Avro.File;
using Avro.Generic;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.EventGrid;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.WindowsAzure.Storage;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
namespace FunctionEGDWDumper
{
using System.Text;
using Avro.File;
using Avro.Generic;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.EventGrid;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.WindowsAzure.Storage;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
public static class Function1
{

Просмотреть файл

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net461</TargetFramework>
</PropertyGroup>
@ -6,7 +6,7 @@
<PackageReference Include="Apache.Avro" Version="1.7.7.2" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.EventGrid" Version="1.0.0-beta4" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.13" />
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
</ItemGroup>
<ItemGroup>
<Reference Include="Microsoft.CSharp" />

Просмотреть файл

@ -1,7 +1,11 @@
using System;
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
namespace FunctionEGDWDumper
{
using System;
// TODO, move this class to a Contracts assembly that is shared across different projects
class WindTurbineMeasure
{

Просмотреть файл

@ -1,22 +1,22 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Azure.Messaging.EventHubs;
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
namespace WindTurbineDataGenerator
{
using System;
using System.Diagnostics;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Azure.Messaging.EventHubs;
internal class Program
{
private const string EventHubConnectionString =
"<EVENT HUBS NAMESPACE CONNECTION STRING>";
private const string EventHubNamespaceConnectionString = "<EVENT HUBS NAMESPACE CONNECTION STRING>";
private const string EventHubName = "<EVENT HUB NAME>";
private static int Main()
{
Console.WriteLine("Starting wind turbine generator. Press <ENTER> to exit");
@ -40,7 +40,7 @@ namespace WindTurbineDataGenerator
var random = new Random((int)DateTimeOffset.UtcNow.Ticks);
// create an Event Hubs Producer client using the namespace connection string and the event hub name
EventHubProducerClient producerClient = new EventHubProducerClient(EventHubConnectionString, EventHubName);
EventHubProducerClient producerClient = new EventHubProducerClient(EventHubNamespaceConnectionString, EventHubName);
while (!cancellationToken.IsCancellationRequested)
{
@ -55,7 +55,8 @@ namespace WindTurbineDataGenerator
var windTurbineMeasure = GenerateTurbineMeasure("Turbine_" + i, scaleFactor);
EventData evData = SerializeWindTurbineToEventData(windTurbineMeasure);
// add the event to the batch
eventBatch.TryAdd(evData);
if (eventBatch.TryAdd(evData) == false)
break;
}
Console.Write(".");

Просмотреть файл

@ -47,8 +47,8 @@
<Reference Include="Microsoft.Bcl.AsyncInterfaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Bcl.AsyncInterfaces.1.0.0\lib\net461\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">

Просмотреть файл

@ -1,7 +1,10 @@
using System;
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
namespace WindTurbineDataGenerator
{
using System;
// TODO, move this class to a Contracts assembly that is shared across different projects
class WindTurbineMeasure
{

Просмотреть файл

@ -5,7 +5,7 @@
<package id="Microsoft.Azure.Amqp" version="2.4.2" targetFramework="net461" />
<package id="Microsoft.Azure.EventHubs" version="1.0.2" targetFramework="net461" />
<package id="Microsoft.Bcl.AsyncInterfaces" version="1.0.0" targetFramework="net461" />
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net461" />
<package id="Newtonsoft.Json" version="12.0.3" targetFramework="net461" />
<package id="System.Buffers" version="4.5.0" targetFramework="net461" />
<package id="System.Diagnostics.DiagnosticSource" version="4.6.0" targetFramework="net461" />
<package id="System.Memory" version="4.5.3" targetFramework="net461" />

Просмотреть файл

@ -58,9 +58,6 @@
<Reference Include="Microsoft.Azure.Amqp, Version=2.4.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>packages\Microsoft.Azure.Amqp.2.4.3\lib\net45\Microsoft.Azure.Amqp.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Azure.Services.AppAuthentication, Version=1.3.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>packages\Microsoft.Azure.Services.AppAuthentication.1.3.1\lib\net472\Microsoft.Azure.Services.AppAuthentication.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Bcl.AsyncInterfaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>packages\Microsoft.Bcl.AsyncInterfaces.1.1.0\lib\net461\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
</Reference>
@ -71,18 +68,6 @@
<Reference Include="Microsoft.Identity.Client, Version=4.7.1.0, Culture=neutral, PublicKeyToken=0a613f4dd989e8ae, processorArchitecture=MSIL">
<HintPath>packages\Microsoft.Identity.Client.4.7.1\lib\net45\Microsoft.Identity.Client.dll</HintPath>
</Reference>
<Reference Include="Microsoft.IdentityModel.Clients.ActiveDirectory, Version=5.2.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>packages\Microsoft.IdentityModel.Clients.ActiveDirectory.5.2.4\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll</HintPath>
</Reference>
<Reference Include="Microsoft.IdentityModel.JsonWebTokens, Version=5.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>packages\Microsoft.IdentityModel.JsonWebTokens.5.6.0\lib\net461\Microsoft.IdentityModel.JsonWebTokens.dll</HintPath>
</Reference>
<Reference Include="Microsoft.IdentityModel.Logging, Version=5.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>packages\Microsoft.IdentityModel.Logging.5.6.0\lib\net461\Microsoft.IdentityModel.Logging.dll</HintPath>
</Reference>
<Reference Include="Microsoft.IdentityModel.Tokens, Version=5.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>packages\Microsoft.IdentityModel.Tokens.5.6.0\lib\net461\Microsoft.IdentityModel.Tokens.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
@ -95,9 +80,6 @@
<HintPath>packages\System.Diagnostics.DiagnosticSource.4.7.0\lib\net46\System.Diagnostics.DiagnosticSource.dll</HintPath>
</Reference>
<Reference Include="System.IdentityModel" />
<Reference Include="System.IdentityModel.Tokens.Jwt, Version=5.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>packages\System.IdentityModel.Tokens.Jwt.5.6.0\lib\net461\System.IdentityModel.Tokens.Jwt.dll</HintPath>
</Reference>
<Reference Include="System.IO, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>packages\System.IO.4.3.0\lib\net462\System.IO.dll</HintPath>
<Private>True</Private>

Просмотреть файл

@ -11,7 +11,7 @@
<form id="form1" runat="server">
<div style="white-space: pre">
<div>
<label>Event Hubs Namespace</label><asp:TextBox ID="txtNamespace" runat="server" Text="" />
<label>Event Hubs Namespace - Fully qualified </label><asp:TextBox ID="txtNamespace" runat="server" Text="" />
</div>
<div>
<label>Event Hub Name</label><asp:TextBox ID="txtEventHub" runat="server" Text=""/>

Просмотреть файл

@ -1,15 +1,18 @@
using System;
using System.Linq;
using System.Text;
using System.Threading;
using Azure.Messaging.EventHubs;
using Azure.Identity;
using System.Threading.Tasks;
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
// Always add app to IAM roles
// Don't use on deployment slots but only on root
namespace ManagedIdentityWebApp
{
using System;
using System.Text;
using System.Threading;
using Azure.Messaging.EventHubs;
using Azure.Identity;
using System.Threading.Tasks;
public partial class SendReceive : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
@ -19,7 +22,7 @@ namespace ManagedIdentityWebApp
protected async void btnSend_Click(object sender, EventArgs e)
{
await using (EventHubProducerClient producerClient = new EventHubProducerClient($"{txtNamespace.Text}.servicebus.windows.net", txtEventHub.Text, new DefaultAzureCredential()))
await using (EventHubProducerClient producerClient = new EventHubProducerClient(txtNamespace.Text, txtEventHub.Text, new DefaultAzureCredential()))
{
// create a batch
EventDataBatch eventBatch = await producerClient.CreateBatchAsync();
@ -30,7 +33,7 @@ namespace ManagedIdentityWebApp
// send the batch to the event hub
await producerClient.SendAsync(eventBatch);
txtOutput.Text = $"{DateTime.Now} - SENT{Environment.NewLine}" + txtOutput.Text;
txtOutput.Text = $"{DateTime.Now} - SENT{Environment.NewLine}{txtOutput.Text}";
}
}
protected async void btnReceive_Click(object sender, EventArgs e)

Просмотреть файл

@ -4,19 +4,12 @@
<package id="Azure.Identity" version="1.1.0" targetFramework="net472" />
<package id="Azure.Messaging.EventHubs" version="5.0.0-preview.6" targetFramework="net472" />
<package id="Microsoft.Azure.Amqp" version="2.4.3" targetFramework="net472" />
<package id="Microsoft.Azure.EventHubs" version="4.1.0" targetFramework="net472" />
<package id="Microsoft.Azure.Services.AppAuthentication" version="1.3.1" targetFramework="net472" />
<package id="Microsoft.Bcl.AsyncInterfaces" version="1.1.0" targetFramework="net472" />
<package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="2.0.1" targetFramework="net472" />
<package id="Microsoft.Identity.Client" version="4.7.1" targetFramework="net472" />
<package id="Microsoft.IdentityModel.Clients.ActiveDirectory" version="5.2.4" targetFramework="net472" />
<package id="Microsoft.IdentityModel.JsonWebTokens" version="5.6.0" targetFramework="net472" />
<package id="Microsoft.IdentityModel.Logging" version="5.6.0" targetFramework="net472" />
<package id="Microsoft.IdentityModel.Tokens" version="5.6.0" targetFramework="net472" />
<package id="Newtonsoft.Json" version="12.0.3" targetFramework="net472" />
<package id="System.Buffers" version="4.5.0" targetFramework="net472" />
<package id="System.Diagnostics.DiagnosticSource" version="4.7.0" targetFramework="net472" />
<package id="System.IdentityModel.Tokens.Jwt" version="5.6.0" targetFramework="net472" />
<package id="System.IO" version="4.3.0" targetFramework="net472" />
<package id="System.Memory" version="4.5.3" targetFramework="net472" />
<package id="System.Net.Http" version="4.3.4" targetFramework="net472" />