iotagent-node-lib icon indicating copy to clipboard operation
iotagent-node-lib copied to clipboard

Subscription id not available in the notification handler

Open MichelSc opened this issue 3 years ago • 8 comments

I use version 2.16 of the iotagent-node-lib library.

The notification handler receives the device (OK) and the subscribed attributes (param data, OK): function mockedHandler(device, data, callback)

But the subscription id is not available: NOK.

This is a problem. I could have for a same device different subscriptions (different conditions and/or different subscribed attributes). These different subscriptions have therefore different meanings and I want to implement a specific behavior for every of these different subscriptions for the same device. As the subscription id, which is present in the http request, is not made available in the notification handler, I cannot identify the subscription responsible for the received notification: NOK.

Note that the workaround of making 1 subscription for all notifications of a given device is not a solution:

  • I must write more code for aggregating the different subscriptions: code without value
  • it is not possible to add a new subscription, as I would need to update the aggregated subscription, and the latter is not possible due to issue #1085

MichelSc avatar Aug 20 '21 10:08 MichelSc

@MichelSc I am interested to work in this issue.

Sunny-NEC avatar Sep 21 '21 07:09 Sunny-NEC

@Sunny-NEC :

  • thank you for your interest
  • I am not the owner of this library, but only a user; so I cannot tell you anything about the possibly integration of your fix
  • but as this issue is quite blocking for me, I will be very happy to test your solution

MichelSc avatar Sep 22 '21 13:09 MichelSc

@Sunny-NEC thanks for your willingness to work on this issue! Please go ahead and create the pull request with your contribution, so we can evaluate and provide feedback.

It should be easy, just to add the subscriptionId to mockHandler() functiona and associated program logic.

fgalan avatar Sep 28 '21 06:09 fgalan

@fgalan According to the Author this issue is related to the issue https://github.com/telefonicaid/iotagent-node-lib/issues/1085. I have done investigation on both the issues and currently i am trying to find out the execution flow of function subscribe(device, triggers, content, callback) .

I request you to share the any usecase in which subscribe method will be called. It would be helpful in my investigation.

@MichelSc unable to find function mockedHandler(device, data, callback) in the source code of iotagent . can you please share some more details.

Sunny-NEC avatar Sep 29 '21 11:09 Sunny-NEC

@Sunny-NEC : this issue is related to issue #1085, in the sense that #1085 could be a work around to this issue; but issue #1085 is not the cause nor the solution of this issue

@Sunny-NEC : suggestion of modifying mockHandler comes from @fgalan ; cannot say anything about it

@Sunny-NEC : the notification handler is called from the function contextServer-NGSI-V2.applyNotificationHandlers (line 302), that needs to be reworked so to add the subscription id in the callback parameters. I see a few difficulties/attention points:

  • how to do that without breaking the previous implementation of the callback (with 1 parameter less)?
  • call back is called at 2 places (line 309 in the waterfall) and line 311, directly: both need to be reworked
  • in principle, the other protocol version implementations should be reworked as well
  • subscription id is lost a few calls deeper, namely in handleNotificationRequests, line 337; so it must be kept along a few method calls
  • whether to return the id or the location of the subscription; subscription-NGSI-v2.createSubscripitionHandlerNgsi2 returns the location:
    • line 89: the id is remembered (OK)
    • line 95: the location is returned (NOK in my sense)

MichelSc avatar Sep 29 '21 12:09 MichelSc

Thankyou for the reply @MichelSc . could you share the any usecase for this function.

Sunny-NEC avatar Oct 01 '21 07:10 Sunny-NEC

@Sunny-NEC , about "could you share the any usecase for this function."

Not too sure what you expect here. The motivation for this new feature is in the issue description. The use case is to build a connector binding assets to models, but this will not help you solving the issue. As it is a new feature and no bug, I have no reproduction scenario. Testing this new feature is not very hard: just receive a notification and check that the subscription id is available in the call back.

MichelSc avatar Oct 05 '21 14:10 MichelSc

@Sunny-NEC any update on the progress on this issue, please? Thanks!

fgalan avatar Jun 08 '22 12:06 fgalan

PR https://github.com/telefonicaid/iotagent-node-lib/pull/1475 should fix this issue.

@MichelSc could you have a look and check if that's correct (or provide additional feedback in negative case), please? Thanks!

fgalan avatar Feb 05 '24 15:02 fgalan

We have waited until releasing 4.3.0 version to close this issue. Of course, if the problem stills, please tell us @MichelSc so we can reopen this issue.

fgalan avatar Feb 27 '24 16:02 fgalan