barnstee / UA-CloudPublisher

A cross-platform OPC UA cloud publisher reference implementation leveraging OPC UA PubSub over MQTT or Kafka. It runs in a Docker container on standard Docker hosts or on Kubernetes and comes with an easy-to-use web user interface.
Other
36 stars 10 forks source link

Error / Behaviour running the Publisher in a Docker-Compose setup #9

Open AndreasHeine opened 2 months ago

AndreasHeine commented 2 months ago

Hey,

i am currently testing around OPC UA Pub Sub with some Products. As soon as i start up the service the could-publisher fails to connect (which is ok i guess) i set the depends_on to define the start order but the ua server takes longer to startup due to some larger initialization. in order to use it in a docker-compose environment its important that the container either tries to connect again after some seconds or to crash the container so the restart-policy can take care of the restart.

the relevant compose part (just a subsection):

  opcua-server:
    hostname: opcua-server
    image: <image>
    restart: unless-stopped
    ports:
      - 4840:4840
    expose:
      - 4840
    networks:
      net0: {}
  cloud-publisher:
    image: ghcr.io/barnstee/ua-cloudpublisher:main
    volumes:
      - /home/andreas/Compose-Services/test1/cloud-publisher/settings:/app/settings
      - /home/andreas/Compose-Services/test1/cloud-publisher/logs:/app/logs
    ports:
      - 8080:80
    expose:
      - 8080
    restart: unless-stopped
    depends_on: 
      - opcua-server
    networks:
      net0: {}
info: PublishedNodesFileHandler[0]
      Loaded 1 config file entry/entries.
fail: UAClient[0]
      Cannot reach server on endpoint opc.tcp://opcua-server:4840/UA. Please make sure your OPC UA server is running and accessible.
      Opc.Ua.ServiceResultException: Error establishing a connection: BadNotConnected
         at Opc.Ua.Bindings.ChannelAsyncOperation`1.End(Int32 timeout, Boolean throwOnError)
         at Opc.Ua.Bindings.UaSCUaBinaryClientChannel.EndSendRequest(IAsyncResult result)
         at Opc.Ua.Bindings.UaSCUaBinaryTransportChannel.EndSendRequest(IAsyncResult result)
         at Opc.Ua.Bindings.UaSCUaBinaryTransportChannel.SendRequest(IServiceRequest request)
         at Opc.Ua.DiscoveryClient.GetEndpoints(RequestHeader requestHeader, String endpointUrl, StringCollection localeIds, StringCollection profileUris, EndpointDescriptionCollection& endpoints)
         at Opc.Ua.DiscoveryClient.GetEndpoints(StringCollection profileUris)
         at Opc.Ua.Client.CoreClientUtils.SelectEndpoint(String discoveryUrl, Boolean useSecurity, Int32 discoverTimeout)
         at Opc.Ua.Cloud.Publisher.UAClient.FindSession(String endpointUrl) in /src/UAClient.cs:line 75
fail: Statup[0]
      Persistency file not loaded!
      Opc.Ua.ServiceResultException: Error establishing a connection: BadNotConnected
         at Opc.Ua.Bindings.ChannelAsyncOperation`1.End(Int32 timeout, Boolean throwOnError)
         at Opc.Ua.Bindings.UaSCUaBinaryClientChannel.EndSendRequest(IAsyncResult result)
         at Opc.Ua.Bindings.UaSCUaBinaryTransportChannel.EndSendRequest(IAsyncResult result)
         at Opc.Ua.Bindings.UaSCUaBinaryTransportChannel.SendRequest(IServiceRequest request)
         at Opc.Ua.DiscoveryClient.GetEndpoints(RequestHeader requestHeader, String endpointUrl, StringCollection localeIds, StringCollection profileUris, EndpointDescriptionCollection& endpoints)
         at Opc.Ua.DiscoveryClient.GetEndpoints(StringCollection profileUris)
         at Opc.Ua.Client.CoreClientUtils.SelectEndpoint(String discoveryUrl, Boolean useSecurity, Int32 discoverTimeout)
         at Opc.Ua.Client.CoreClientUtils.SelectEndpoint(String discoveryUrl, Boolean useSecurity)
         at Opc.Ua.Cloud.Publisher.UAClient.ConnectSessionAsync(String endpointUrl, String username, String password) in /src/UAClient.cs:line 150
barnstee commented 2 months ago

This would require an implementation of a retry mechanism during automatic publishednodes.json file loading at startup. Or, you log into localhost:8080, go to the published nodes menu and click on "load previously published nodes" button.

AndreasHeine commented 2 months ago

@barnstee tbh retry sounds much better because it does not involve any manual task!