Eclipse milo:尝试读取数据时会话已关闭

时间:2018-04-12 15:56:49

标签: java opc-ua milo

我有一个外部OPC UA服务器,我想从中读取数据。我使用用户名和密码验证,因此我的客户端初始化如下:

public class MyClient {

    // ...

    public MyClient() throws Exception {
        EndpointDescription[] endpoints =
            UaTcpStackClient.getEndpoints(OPCConstants.OPC_SERVER_URI).get();

        // using the first endpoint
        EndpointDescription endpoint = endpoints[0];

        // client configuration
        OpcUaClientConfig config = OpcUaClientConfig.builder()
            .setApplicationName(LocalizedText.english("Example Client"))
            .setApplicationUri(String.format("some:example-client:%s",
                    UUID.randomUUID()))
            .setIdentityProvider(new UsernameProvider(USERNAME, PWD))
            .setEndpoint(endpoint)
            .build();
    }
}

客户的要求如下:

public CompletableFuture<DataValue> getData(NodeId nodeId) {
    LOGGER.debug("Sending request");
    return client.readValue(60000000.0, TimestampsToReturn.Server, nodeId);
}

在初始化客户端并将其连接到服务器之后,我从main方法调用此请求:

MyClient client = new MyClient();

NodeId requestedData = new NodeId(DATA_ID, DATA_KEY);
LOGGER.info("Sending synchronous TestStackRequest NodeId={}",
       requestedData);
client.connect();
DataValue response = client.getData(requestedData).get();
LOGGER.info("Received response value={}", response.getValue());
client.disconnect();

但是,此代码不起作用(尝试从服务器读取信息时会话关闭)。我得到以下输出:

  

2018-04-12 17:43:27,765 DEBUG --- [ua-netty-event-loop-0] Recycler:-Dio.netty.recycler.maxCapacity.default:262144
  2018-04-12 17:43:27,777 DEBUG --- [ua-netty-event-loop-0] UaTcpClientAcknowledgeHandler:在通道上发送Hello消息= [id:0xfd9519e3,L:/172.20.100.54:55805 - R:/ 172.20.100.135:4840。
  2018-04-12 17:43:27,786 DEBUG --- [ua-netty-event-loop-0] UaTcpClientAcknowledgeHandler:在channel = [id:0xfd9519e3,L:/172.20.100.54:55805 - R:/ 172.20.100.135:4840。
  2018-04-12 17:43:27,793 DEBUG --- [ua-netty-event-loop-0] UaTcpClientMessageHandler:OpenSecureChannel超时计划为+ 5s
  2018-04-12 17:43:27,946 DEBUG --- [ua-shared-pool-0] UaTcpClientMessageHandler:发送OpenSecureChannelRequest(问题,id = 0,currentToken = -1,previousToken = -1)。
  2018-04-12 17:43:27,951 DEBUG --- [ua-netty-event-loop-0] UaTcpClientMessageHandler:OpenSecureChannel超时取消
  2018-04-12 17:43:27,961 DEBUG --- [ua-shared-pool-0] UaTcpClientMessageHandler:收到OpenSecureChannelResponse。
  2018-04-12 17:43:27,967 DEBUG --- [ua-shared-pool-0] UaTcpClientMessageHandler:SecureChannel id = 1698234671,currentTokenId = 1,previousTokenId = -1,lifetime = 3600000ms,createdAt = DateTime {utcTime = 131680285857690000 ,javaDate = Thu Apr 12 19:43:05 CEST 2018}   2018-04-12 17:43:27,968 DEBUG --- [ua-netty-event-loop-0] UaTcpClientMessageHandler:在握手完成之前排队的0条消息;现在发送。
  2018-04-12 17:43:27,968 DEBUG --- [ua-shared-pool-1] ClientChannelManager:通道引导成功:localAddress = / 172.20.100.54:55805,remoteAddress = / 172.20.100.135:4840
  2018-04-12 17:43:27,996 DEBUG --- [ua-shared-pool-0] ClientChannelManager:disconnect(),currentState =已连接
  2018-04-12 17:43:27,997 DEBUG --- [ua-shared-pool-1] ClientChannelManager:发送CloseSecureChannelRequest ...
  2018-04-12 17:43:28,000 DEBUG --- [ua-netty-event-loop-0] ClientChannelManager:channelInactive(),断开完成
  2018-04-12 17:43:28,001 DEBUG --- [ua-netty-event-loop-0] ClientChannelManager:断开完成,状态设置为空闲
  2018-04-12 17:43:28,011 INFO --- [主要] OpcUaClient:Eclipse Milo OPC UA Stack版本:0.2.1
  2018-04-12 17:43:28,011 INFO --- [main] OpcUaClient:Eclipse Milo OPC UA Client SDK版本:0.2.1
  2018-04-12 17:43:28,056 DEBUG --- [main] OpcUaClient:添加了ServiceFaultListener:org.eclipse.milo.opcua.sdk.client.session.SessionFsm$FaultListener@46d59067
  2018-04-12 17:43:28,066 DEBUG --- [main] OpcUaClient:添加了SessionActivityListener:org.eclipse.milo.opcua.sdk.client.subscriptions.OpcUaSubscriptionManager $ 1 @ 78452606
  2018-04-12 17:43:28,189 INFO --- [main] CommunicationMain:发送同步TestStackRequest NodeId = NodeId {ns = 6,id = :: opcua:opcData.outGoing.basic.cycleStep}
  2018-04-12 17:43:28,189 DEBUG --- [main] ClientChannelManager:connect(),currentState = NotConnected
  2018-04-12 17:43:28,190 DEBUG --- [main] ClientChannelManager:connect()而NotConnected
  java.lang.Exception的
    在org.eclipse.milo.opcua.stack.client.ClientChannelManager.connect(ClientChannelManager.java:67)
    在org.eclipse.milo.opcua.stack.client.UaTcpStackClient.connect(UaTcpStackClient.java:127)
    在org.eclipse.milo.opcua.sdk.client.OpcUaClient.connect(OpcUaClient.java:313)
    在com.mycompany.opcua.participants.MyClient.connect(MyClient.java:147)
    在com.mycompany.opcua.participants.CommunicationMain.testClient(CommunicationMain.java:69)
    在com.mycompany.opcua.participants.CommunicationMain.main(CommunicationMain.java:51)
  2018-04-12 17:43:28,190 DEBUG --- [主要] MyClient:发送请求
  2018-04-12 17:43:28,197 DEBUG --- [ua-netty-event-loop-1] UaTcpClientAcknowledgeHandler:在通道上发送Hello消息= [id:0xd9b3f832,L:/172.20.100.54:55806 - R:/ 172.20.100.135:4840。
  2018-04-12 17:43:28,204 DEBUG --- [ua-netty-event-loop-1] UaTcpClientAcknowledgeHandler:在channel = [id:0xd9b3f832,L:/172.20.100.54:55806 - R:/ 172.20.100.135:4840。
  2018-04-12 17:43:28,205 DEBUG --- [ua-netty-event-loop-1] UaTcpClientMessageHandler:OpenSecureChannel超时计划为+ 5s
  2018-04-12 17:43:28,205 DEBUG --- [ua-shared-pool-0] UaTcpClientMessageHandler:发送OpenSecureChannelRequest(问题,id = 0,currentToken = -1,previousToken = -1)。
  2018-04-12 17:43:28,208 DEBUG --- [ua-netty-event-loop-1] UaTcpClientMessageHandler:OpenSecureChannel超时取消
  2018-04-12 17:43:28,208 DEBUG --- [ua-shared-pool-0] UaTcpClientMessageHandler:收到OpenSecureChannelResponse。
  2018-04-12 17:43:28,209 DEBUG --- [ua-shared-pool-0] UaTcpClientMessageHandler:SecureChannel id = 1698234672,currentTokenId = 1,previousTokenId = -1,lifetime = 3600000ms,createdAt = DateTime {utcTime = 131680285860260000 ,javaDate = Thu Apr 12 19:43:06 CEST 2018}   2018-04-12 17:43:28,209 DEBUG --- [ua-netty-event-loop-1] UaTcpClientMessageHandler:在握手完成之前排队的0条消息;现在发送。
  2018-04-12 17:43:28,209 DEBUG --- [ua-shared-pool-1] ClientChannelManager:通道引导程序成功:localAddress = / 172.20.100.54:55806,remoteAddress = / 172.20.100.135:4840
  2018-04-12 17:43:28,210 DEBUG --- [ua-shared-pool-0] SessionFsm:S(非活动)x E(CreateSessionEvent)= S&#39;(创建)
  线程&#34; main&#34;中的例外情况java.util.concurrent.ExecutionException:UaException:status = Bad_SessionClosed,message =会话已被客户端关闭。
    at java.base / java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:395)2018-04-12 17:43:28,212 DEBUG --- [ua-shared-pool-1] SessionFsm:发送CreateSessionRequest .. 。

     

at java.base / java.util.concurrent.CompletableFuture.get(CompletableFuture.java:1999)
    在com.mycompany.opcua.participants.CommunicationMain.testClient(CommunicationMain.java:70)
    在com.mycompany.opcua.participants.CommunicationMain.main(CommunicationMain.java:51)
  引起:UaException:status = Bad_SessionClosed,message =会话由客户端关闭     在org.eclipse.milo.opcua.stack.core.util.FutureUtils.failedUaFuture(FutureUtils.java:100)
    在org.eclipse.milo.opcua.stack.core.util.FutureUtils.failedUaFuture(FutureUtils.java:88)
    在org.eclipse.milo.opcua.sdk.client.session.states.Inactive。(Inactive.java:28)
    在org.eclipse.milo.opcua.sdk.client.session.SessionFsm。(SessionFsm.java:69)
    在org.eclipse.milo.opcua.sdk.client.OpcUaClient。(OpcUaClient.java:159)2018-04-12 17:43:28,212 INFO --- [NonceUtilSecureRandom] NonceUtil:SecureRandom以0ms播种。

     

at com.mycompany.opcua.participants.MyClient。(MyClient.java:112)
    在com.mycompany.opcua.participants.CommunicationMain.testClient(CommunicationMain.java:60)
    ......还有1个

我使用Eclipse milo 0.2.1作为OPC UA库。

你能否告诉我帽子会导致这个问题以及如何解决?这可能是与this相关的竞争条件吗?

我可以使用其他客户端(UaExpert)连接到同一台服务器。

提前谢谢。

1 个答案:

答案 0 :(得分:0)

您正在进行的所有通话(connect()disconnect()readValues())都是异步的,因此您可能会在这里发生的事情是&#39;尝试阅读时没有连接。

请确保在转到下一步之前阻止这些示例。 (您未在connect())上执行此操作