Changed Windows Dockerfile to 1809

Switched EdgeHub connection to MQTT
Implemented default (fallback) direct method callback
This commit is contained in:
Sebastian Bader 2018-12-20 11:14:54 +01:00
Родитель f5bf5da9fc
Коммит 77efcff1ae
3 изменённых файлов: 23 добавлений и 3 удалений

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

@ -1,5 +1,5 @@
ARG runtime_base_tag=2.1-runtime-nanoserver-1803
ARG build_base_tag=2.1-sdk-nanoserver-1803
ARG runtime_base_tag=2.1-runtime-nanoserver-1809
ARG build_base_tag=2.1-sdk
FROM microsoft/dotnet:${build_base_tag} AS build
WORKDIR /app

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

@ -139,6 +139,7 @@ namespace OpcPublisher
await _edgeHubClient.SetMethodHandlerAsync("UnpublishAllNodes", HandleUnpublishAllNodesMethodAsync, _edgeHubClient);
await _edgeHubClient.SetMethodHandlerAsync("GetConfiguredEndpoints", HandleGetConfiguredEndpointsMethodAsync, _edgeHubClient);
await _edgeHubClient.SetMethodHandlerAsync("GetConfiguredNodesOnEndpoint", HandleGetConfiguredNodesOnEndpointMethodAsync, _edgeHubClient);
await _edgeHubClient.SetMethodDefaultHandlerAsync(DefaultMethodHandlerAsync, _edgeHubClient);
}
else
{
@ -165,6 +166,7 @@ namespace OpcPublisher
await _iotHubClient.SetMethodHandlerAsync("UnpublishAllNodes", HandleUnpublishAllNodesMethodAsync, _iotHubClient);
await _iotHubClient.SetMethodHandlerAsync("GetConfiguredEndpoints", HandleGetConfiguredEndpointsMethodAsync, _iotHubClient);
await _iotHubClient.SetMethodHandlerAsync("GetConfiguredNodesOnEndpoint", HandleGetConfiguredNodesOnEndpointMethodAsync, _iotHubClient);
await _edgeHubClient.SetMethodDefaultHandlerAsync(DefaultMethodHandlerAsync, _iotHubClient);
}
}
Logger.Debug($"Init D2C message processing");
@ -697,6 +699,24 @@ namespace OpcPublisher
return methodResponse;
}
/// <summary>
/// Method that is called for any unimplemented call. Just returns that info to the caller
/// </summary>
/// <param name="methodRequest"></param>
/// <param name="userContext"></param>
/// <returns></returns>
private async Task<MethodResponse> DefaultMethodHandlerAsync(MethodRequest methodRequest, object userContext)
{
Logger.Information($"Received direct method call for {methodRequest.Name} which is not implemented");
string response = $"Method {methodRequest.Name} successfully received but this method is not implemented";
string resultString = JsonConvert.SerializeObject(response);
byte[] result = Encoding.UTF8.GetBytes(resultString);
MethodResponse methodResponse = new MethodResponse(result, (int)HttpStatusCode.OK);
return methodResponse;
}
/// <summary>
/// Initializes internal message processing.
/// </summary>

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

@ -39,7 +39,7 @@ namespace OpcPublisher
try
{
// connect to EdgeHub
HubProtocol = TransportType.Amqp_Tcp_Only;
HubProtocol = TransportType.Mqtt_Tcp_Only;
Logger.Information($"Create IoTEdgeHub module client using '{HubProtocol}' for communication.");
ModuleClient hubClient = await ModuleClient.CreateFromEnvironmentAsync(HubProtocol);