NUH-38: Implement TelemetryPublisherConsole
This commit is contained in:
parent
5b692a5d74
commit
dcd51ecd3d
5 changed files with 36 additions and 3 deletions
29
NucuCar.Domain.Telemetry/TelemetryPublisherConsole.cs
Normal file
29
NucuCar.Domain.Telemetry/TelemetryPublisherConsole.cs
Normal 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()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
|
@ -47,9 +47,10 @@ namespace NucuCar.Telemetry
|
|||
{
|
||||
return type switch
|
||||
{
|
||||
TelemetryPublisherType.Azure => (TelemetryPublisher) new TelemetryPublisherAzure(opts),
|
||||
TelemetryPublisherType.Azure => new TelemetryPublisherAzure(opts),
|
||||
TelemetryPublisherType.Disk => new TelemetryPublisherDisk(opts),
|
||||
TelemetryPublisherType.Firestore => new TelemetryPublisherFirestore(opts),
|
||||
TelemetryPublisherType.Console => new TelemetryPublisherConsole(opts),
|
||||
_ => throw new ArgumentException($"Invalid TelemetryPublisher type: {type}.")
|
||||
};
|
||||
}
|
||||
|
|
|
@ -10,5 +10,6 @@ namespace NucuCar.Telemetry
|
|||
public const string Azure = "Azure";
|
||||
public const string Disk = "Disk";
|
||||
public const string Firestore = "Firestore";
|
||||
public const string Console = "Console";
|
||||
}
|
||||
}
|
|
@ -37,6 +37,7 @@ namespace NucuCar.Domain.Telemetry
|
|||
/// </summary>
|
||||
public TelemetryPublisher()
|
||||
{
|
||||
RegisteredTelemeters = new List<ITelemeter>(10);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -88,7 +89,7 @@ namespace NucuCar.Domain.Telemetry
|
|||
ConnectionString = opts.ConnectionString;
|
||||
TelemetrySource = opts.TelemetrySource;
|
||||
Logger = opts.Logger;
|
||||
RegisteredTelemeters = new List<ITelemeter>(5);
|
||||
RegisteredTelemeters = new List<ITelemeter>(10);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -9,7 +9,8 @@
|
|||
"NucuCar.Sensors.Development": {
|
||||
"commandName": "Project",
|
||||
"environmentVariables": {
|
||||
"DOTNET_ENVIRONMENT": "Development"
|
||||
"DOTNET_ENVIRONMENT": "Development",
|
||||
"Telemetry:Publisher": "Console"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue