NUH-38: Implement TelemetryPublisherConsole

This commit is contained in:
Denis-Cosmin Nutiu 2020-08-01 17:49:20 +03:00
parent 5b692a5d74
commit dcd51ecd3d
5 changed files with 36 additions and 3 deletions

View file

@ -0,0 +1,29 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using NucuCar.Domain.Telemetry;
namespace NucuCar.Telemetry
{
public class TelemetryPublisherConsole : TelemetryPublisher
{
public TelemetryPublisherConsole(TelemetryPublisherBuilderOptions opts) : base(opts)
{
}
public override Task PublishAsync(CancellationToken cancellationToken)
{
var data = GetTelemetry();
var messageString = JsonConvert.SerializeObject(data);
Logger?.LogDebug($"Telemetry message: {messageString}");
Logger?.LogInformation(messageString);
return Task.CompletedTask;
}
public override void Dispose()
{
}
}
}

View file

@ -47,9 +47,10 @@ namespace NucuCar.Telemetry
{ {
return type switch return type switch
{ {
TelemetryPublisherType.Azure => (TelemetryPublisher) new TelemetryPublisherAzure(opts), TelemetryPublisherType.Azure => new TelemetryPublisherAzure(opts),
TelemetryPublisherType.Disk => new TelemetryPublisherDisk(opts), TelemetryPublisherType.Disk => new TelemetryPublisherDisk(opts),
TelemetryPublisherType.Firestore => new TelemetryPublisherFirestore(opts), TelemetryPublisherType.Firestore => new TelemetryPublisherFirestore(opts),
TelemetryPublisherType.Console => new TelemetryPublisherConsole(opts),
_ => throw new ArgumentException($"Invalid TelemetryPublisher type: {type}.") _ => throw new ArgumentException($"Invalid TelemetryPublisher type: {type}.")
}; };
} }

View file

@ -10,5 +10,6 @@ namespace NucuCar.Telemetry
public const string Azure = "Azure"; public const string Azure = "Azure";
public const string Disk = "Disk"; public const string Disk = "Disk";
public const string Firestore = "Firestore"; public const string Firestore = "Firestore";
public const string Console = "Console";
} }
} }

View file

@ -37,6 +37,7 @@ namespace NucuCar.Domain.Telemetry
/// </summary> /// </summary>
public TelemetryPublisher() public TelemetryPublisher()
{ {
RegisteredTelemeters = new List<ITelemeter>(10);
} }
/// <summary> /// <summary>
@ -88,7 +89,7 @@ namespace NucuCar.Domain.Telemetry
ConnectionString = opts.ConnectionString; ConnectionString = opts.ConnectionString;
TelemetrySource = opts.TelemetrySource; TelemetrySource = opts.TelemetrySource;
Logger = opts.Logger; Logger = opts.Logger;
RegisteredTelemeters = new List<ITelemeter>(5); RegisteredTelemeters = new List<ITelemeter>(10);
} }
/// <summary> /// <summary>

View file

@ -9,7 +9,8 @@
"NucuCar.Sensors.Development": { "NucuCar.Sensors.Development": {
"commandName": "Project", "commandName": "Project",
"environmentVariables": { "environmentVariables": {
"DOTNET_ENVIRONMENT": "Development" "DOTNET_ENVIRONMENT": "Development",
"Telemetry:Publisher": "Console"
} }
} }
} }