GitHub user Praveenstein added a comment to the discussion: OPC UA Query
Multiple Nodes
So basically any opc ua server will have only these configurations, ip address,
port number, user name, password, (May be some security related settings). So
one way to do is use lru (least recently used ) strategy. In python we have a
built in decorator function lru_cache, what it does, for a given set of input
parameters values, it will give one set of results (only the first time the
results will be computed, after that it will return from the cache) here is a
sample code for connecting to a opc server in python using this method:
from functools import lru_cache
import opcua
@lru_cache(maxsize=None)
def get_connection(host, port, user, password):
return opcua.Client(host, port, user, password)
conn1 = get_connection('localhost', 4840, 'user1', 'password1')
conn2 = get_connection('localhost', 4840, 'user2', 'password2')
conn3 = get_connection('localhost', 4840, 'user1', 'password1')
# conn1 and conn3 will be the same connection object,
# because they have the same host, port, user, and password.
# conn2 will be a different connection object.
I guess apache streampipes in built in Java, i don't much proficiency in Java,
but i tried using chatGpt, you can check it out:
import org.eclipse.milo.opcua.sdk.client.OpcUaClient;
import org.eclipse.milo.opcua.stack.client.UaTcpStackClient;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
@Service
public class OPCUAService {
@Cacheable(value = "opcua_connections", key = "#host + ':' + #port + ':' +
#user + ':' + #password")
public OpcUaClient getConnection(String host, int port, String user, String
password) throws Exception {
return UaTcpStackClient.create(host, port)
.setApplicationName(user)
.setApplicationUri("urn:localhost:ua:client")
.setCertificate(null)
.setKeyPair(null)
.setEndpointUrl(String.format("opc.tcp://%s:%d", host, port))
.build();
}
}
Hope this helps
GitHub link:
https://github.com/apache/streampipes/discussions/888#discussioncomment-4502976
----
This is an automatically sent email for [email protected].
To unsubscribe, please send an email to: [email protected]