How to use a single OPC UA client for multiple trigger nodes

I would like to integrate an OPC UA trigger in n8n that returns values of a monitored item when they are available. Each trigger node should listen for a specified OPC UA item and then trigger the workflow.

However, I see a scalability issue for which I cannot find a solution. OPC UA servers only allow a limited number of parallel clients and sessions (normally 50 or 100). For this reason, a single session is usually used for many monitored items (can be more than 100). As far as I can see, in n8n you have to create a client and a session for each trigger node to make it work. This would be very limiting for OPC UA.

Therefore my question: is it possible to share a single client and session object for many n8n trigger nodes?

Thank you for your help

Hey @chr1s!

Welcome to the community :tada:

You can use a single Webhook node to receive data from OPC UA servers. You can use the Switch node to check for the event that makes the webhook call and route them to appropriate branches.

Hi @harshil1712,

thank you for your suggestion. Unfortunately, I’m not quite sure how that works.
The OPC UA server (as far as I know) does not make any http based calls that I could point to a Webhook. That would be a lot of unnecessary traffic as well especially when there are signals with low cycle times. I wanted to use the native UA binary protocol with a library like node-opcua.

Do you have an example for your suggestion?

I just had a quick look at the npm package. You have to create a Trigger node. In case you want to develop it yourself, It should work similarly to the AMQP Trigger (check link below).

The other option it’s to create a feature request so that people can vote for this node. The more votes, the more chances of being developed.

Thank you your response @RicardoE105!

This is exactly the idea that I tried to describe in my initial post. And that leads back to my issue concerning scalability. With that kind of implementation I would have to create a OPC UA session for each trigger node. The session has to stay alive as long as the workflow with the trigger node is active. With only 50 sessions possible for my OPC UA server this is very limiting.

Therefore my question: is it possible to share a single client and session object for many n8n trigger nodes?

That is sadly not possible. Maybe the library lets you listen to multiple subscriptions with a single session? That perhaps solve the issue? Keep in mind that I know nothing about OPC UA.

Yes, the library allows to have multiple subscriptions with a single session. But I would need to have some kind of handle to the session that is already open to use it in other trigger nodes. Maybe it is possible to find some kind of workaround for that.

Could you resolve this issue?

@Zetanova Unfortunately no. With the concept of n8n, it seems quite tricky to achieve that within n8n, especially when looking at instances using multiple workers.

You could build a microservice that communicates with your OPC UA server and use a different interface instead, e.g., REST + MQTT. But I’m aware that this solution is not ideal.

thanks for your replay.

Yes, n8n as currently no recourse manager (object pool)

I tried here with the ‘typedi’ container used internally by n8n core,
but sadly it didn’t work.

n8n post probably starts the workflow in a nodejs sandbox?
It is not an child-process

Here my ‘typedi’ service: