Changed Windows Dockerfile to 1809
Switched EdgeHub connection to MQTT Implemented default (fallback) direct method callback
This commit is contained in:
Родитель
f5bf5da9fc
Коммит
77efcff1ae
|
@ -1,5 +1,5 @@
|
||||||
ARG runtime_base_tag=2.1-runtime-nanoserver-1803
|
ARG runtime_base_tag=2.1-runtime-nanoserver-1809
|
||||||
ARG build_base_tag=2.1-sdk-nanoserver-1803
|
ARG build_base_tag=2.1-sdk
|
||||||
|
|
||||||
FROM microsoft/dotnet:${build_base_tag} AS build
|
FROM microsoft/dotnet:${build_base_tag} AS build
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
|
@ -139,6 +139,7 @@ namespace OpcPublisher
|
||||||
await _edgeHubClient.SetMethodHandlerAsync("UnpublishAllNodes", HandleUnpublishAllNodesMethodAsync, _edgeHubClient);
|
await _edgeHubClient.SetMethodHandlerAsync("UnpublishAllNodes", HandleUnpublishAllNodesMethodAsync, _edgeHubClient);
|
||||||
await _edgeHubClient.SetMethodHandlerAsync("GetConfiguredEndpoints", HandleGetConfiguredEndpointsMethodAsync, _edgeHubClient);
|
await _edgeHubClient.SetMethodHandlerAsync("GetConfiguredEndpoints", HandleGetConfiguredEndpointsMethodAsync, _edgeHubClient);
|
||||||
await _edgeHubClient.SetMethodHandlerAsync("GetConfiguredNodesOnEndpoint", HandleGetConfiguredNodesOnEndpointMethodAsync, _edgeHubClient);
|
await _edgeHubClient.SetMethodHandlerAsync("GetConfiguredNodesOnEndpoint", HandleGetConfiguredNodesOnEndpointMethodAsync, _edgeHubClient);
|
||||||
|
await _edgeHubClient.SetMethodDefaultHandlerAsync(DefaultMethodHandlerAsync, _edgeHubClient);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -165,6 +166,7 @@ namespace OpcPublisher
|
||||||
await _iotHubClient.SetMethodHandlerAsync("UnpublishAllNodes", HandleUnpublishAllNodesMethodAsync, _iotHubClient);
|
await _iotHubClient.SetMethodHandlerAsync("UnpublishAllNodes", HandleUnpublishAllNodesMethodAsync, _iotHubClient);
|
||||||
await _iotHubClient.SetMethodHandlerAsync("GetConfiguredEndpoints", HandleGetConfiguredEndpointsMethodAsync, _iotHubClient);
|
await _iotHubClient.SetMethodHandlerAsync("GetConfiguredEndpoints", HandleGetConfiguredEndpointsMethodAsync, _iotHubClient);
|
||||||
await _iotHubClient.SetMethodHandlerAsync("GetConfiguredNodesOnEndpoint", HandleGetConfiguredNodesOnEndpointMethodAsync, _iotHubClient);
|
await _iotHubClient.SetMethodHandlerAsync("GetConfiguredNodesOnEndpoint", HandleGetConfiguredNodesOnEndpointMethodAsync, _iotHubClient);
|
||||||
|
await _edgeHubClient.SetMethodDefaultHandlerAsync(DefaultMethodHandlerAsync, _iotHubClient);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Logger.Debug($"Init D2C message processing");
|
Logger.Debug($"Init D2C message processing");
|
||||||
|
@ -697,6 +699,24 @@ namespace OpcPublisher
|
||||||
return methodResponse;
|
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>
|
/// <summary>
|
||||||
/// Initializes internal message processing.
|
/// Initializes internal message processing.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -39,7 +39,7 @@ namespace OpcPublisher
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// connect to EdgeHub
|
// connect to EdgeHub
|
||||||
HubProtocol = TransportType.Amqp_Tcp_Only;
|
HubProtocol = TransportType.Mqtt_Tcp_Only;
|
||||||
Logger.Information($"Create IoTEdgeHub module client using '{HubProtocol}' for communication.");
|
Logger.Information($"Create IoTEdgeHub module client using '{HubProtocol}' for communication.");
|
||||||
ModuleClient hubClient = await ModuleClient.CreateFromEnvironmentAsync(HubProtocol);
|
ModuleClient hubClient = await ModuleClient.CreateFromEnvironmentAsync(HubProtocol);
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче