FIWARE / context.Orion-LD

Context Broker and CEF building block for context data management which supports both the NGSI-LD and the NGSI-v2 APIs
https://www.etsi.org/deliver/etsi_gs/CIM/001_099/009/01.06.01_60/gs_CIM009v010601p.pdf
GNU Affero General Public License v3.0
51 stars 43 forks source link

MQTT subscriptions disconnected from mqtt broker #1427

Open thinkingmik opened 1 year ago

thinkingmik commented 1 year ago

Hi,

I have some problems with MQTT subscriptions. I'm using Orion-LD:1.4.0 and Mosquitto as MQTT Broker.

I created a subscription on Orion-LD with api call:

POST /ngsi-ld/v1/subscriptions HTTP/1.1
Host: localhost:3626
NGSILD-Tenant: acme
Content-Type: application/json
Content-Length: 545

{
    "description": "Notify MQTT",
    "type": "Subscription",
    "entities": [
        {
            "type": "Vehicle"
        }
    ],
    "watchedAttributes": [
        "vname",
        "latitude",
        "longitude"
    ],
    "notification": {
        "attributes": [
            "vname",
            "latitude",
            "longitude"
        ],
        "format": "normalized",
        "endpoint": {
            "uri": "mqtt://mosquitto:3638/positions",
            "accept": "application/json"
        }
    }
}

When I trigger the subscription on Orion-LD everythings goes well and I see on the MQTT Broker this log:

New client connected from x.x.x.x as Orion-LD (p2, c1, k20).
Received PUBLISH from Orion-LD (d0, q0, r0, m0, 'positions', ... (591 bytes))

So, if the connection stay idle for more than 20 seconds and after I trigger the subscription, the MQTT Broker says (and there is no way to reconnect the subscriptions without restarting Orion-LD):

Client Orion-LD has exceeded timeout, disconnecting.

I think that Orion-LD don't send the PINGREQ to MQTT Broker for keeping alive the connection (in the MQTT Broker logs I don't see any incoming calls of type PINGREQ from Orion-LD like others clients do). I don't find any variable to set the keepalive k20 (seems to be the default). I see in the Orion version that exists a -mqttMaxAge but in the Orion-LD implementations I don't find this property.

Furthermore, if I'm restarting the MQTT Broker, the Orion-LD subscriptions loose the connection to the MQTT Broker and the only way for reconnecting is restarting Orion. I saw in the past issues https://github.com/FIWARE/context.Orion-LD/pull/723 that this was fixed but in this version I encountered the same problem.

Thanks.

kzangeli commented 1 year ago

ok! Thanks for reporting. Seems like you've found a bug indeed. I will look into this asap!