JonasH-munters opened a new issue, #2238:
URL: https://github.com/apache/plc4x/issues/2238

   ### What happened?
   
   When creating a PlcSubscriptionRequest and adding a Consumer, either to the 
whole request or to each Tag, that consumer will never be called even though 
the OPC UA server correctly accepts the subscription and sends responses. This 
is quick example of a code snippet that demonstrates this behavior, but the 
same thing happens for Event and Cyclic instead of ChangeOfState and if the 
Consumer is added to the Tag instead of the Request.
   
   ```
   PlcConnection plcConnection = 
plcConnectionManager.getConnection(connectionString);
   PlcSubscriptionRequest plcRequest = 
plcConnection.subscriptionRequestBuilder()
                                                                     
.setConsumer(event -> {log.info("Got event")})
                                                                     
.addChangeOfStateTag("someName", 
plcConnection.parseTagAddress(tagAddress).get())
                                                                     .build();
   plcRequest.execute();
   ```
   
   After debugging a bit it seems like that the intent is for the consumers 
added to the request to then be added to the OpcuaSubscriptionHandle's Set of 
Consumers under the hood. However, in the subscribe method in the 
OpcuaProtocolLogic class where the handle is created based on the request those 
consumers are just never referenced and so will just be quietly ignored. As a 
quick verification of this theory I tried adding a line to the lambda creating 
the handle so that the handle's register method is called and that does result 
in my consumer being called as expected:
   
   ```
               onSubscribeCreateSubscription(cycleTime).thenApply(response -> {
                   long subscriptionId = response.getSubscriptionId();
                   OpcuaSubscriptionHandle handle = new 
OpcuaSubscriptionHandle(this, tm,
                       conversation, subscriptionRequest, subscriptionId, 
cycleTime);
                   handle.register(subscriptionRequest.getConsumer()); // ADDED 
THIS LINE
                   subscriptions.put(handle.getSubscriptionId(), handle);
                   return handle;
               })
   ```
   
   This is obviously not a complete fix since it doesn't cover Consumers added 
to the individual Tags, but I'd be up for  contributing a complete fix to the 
project with some guidance on requirements for a PR in case no one else wants 
to fix this. If this is not the intent of the code and I've missed something 
please let me know and I'd be happy to fix it in the intended way as well.
   
   ### Version
   
   v0.13.0
   
   ### Programming Languages
   
   - [ ] plc4c
   - [ ] plc4go
   - [x] plc4j
   - [ ] plc4net
   - [ ] plc4py
   
   ### Protocols
   
   - [ ] AB-Ethernet
   - [ ] ADS /AMS
   - [ ] BACnet/IP
   - [ ] C-Bus
   - [ ] CANopen
   - [ ] EtherNet/IP
   - [ ] Firmata
   - [ ] IEC-69870
   - [ ] KNXnet/IP
   - [ ] Modbus
   - [x] OPC-UA
   - [ ] Profinet
   - [ ] S7
   - [ ] S7-light


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to