awcullen / opcua

OPC Unified Architecture (OPC UA) in Go.
MIT License
81 stars 18 forks source link

Mismatch SubscriptionID in NotificationMessages (two subscriptions for the same server) #36

Closed Liviu-Ionel-Anton closed 3 months ago

Liviu-Ionel-Anton commented 3 months ago

Hi Andrew,

I have the following scenario: several subscriptions for the same server and each subscription is handling its monitored items in its own goroutine. The problem is that I'm receiving from one subscription to another subscription (I'm checking this by subscription Id). I've oversimplified the scenario by using the sample from the src and attached the file. I've tested it also using UAExpert demo server and ProSys sim server, and it's the same.

Any suggestions on how to fix this? run.go.zip

awcullen commented 3 months ago

Hi Liviu,

Calling Publish will return a PublishResponse with data changes for any subscription, as you found. You could build a map of channels to communicate the notification messages to the correct handler goroutine. One chan for each subscription.

mu sync.RWMutex  // protect subscribers.
subscribers map[uint32]chan NotificationMessage  //map of channel, indexed by subID.
Liviu-Ionel-Anton commented 3 months ago

Hi Andrew,

It worked by centralising the publish requests/responses.

Thanks!