Docker化服务未接收Orion Context Broker通知的问题排查
问题:Orion显示通知发送成功,但Docker化服务未收到消息
我搞不懂为什么Orion明明显示已成功发送TrafficFlowObserved实体更新,但我的Docker化服务就是收不到消息。按预期应该出现以下两种情况之一:
- 若无法连接服务(如URL错误),Orion应打印错误信息;
- 我的服务处理请求并将负载打印至控制台。
但这两种情况均未发生。
Orion 日志
2023-01-18 14:16:50 time=Wednesday 18 Jan 13:16:50 2023.790Z | lvl=TMP | corr=N/A | trans=1674046401-299-00000017019 | from=pending | srv=pending | subsrv=pending | comp=Orion | op=httpRequestSend.cpp[564]:httpRequestSendWithCurl | msg=Sending message 16973 to HTTP server: sending message of 994 bytes to HTTP server 2023-01-18 14:16:50 time=Wednesday 18 Jan 13:16:50 2023.792Z | lvl=INFO | corr=N/A | trans=1674046401-299-00000017019 | from=pending | srv=pending | subsrv=pending | comp=Orion | op=httpRequestSend.cpp[587]:httpRequestSendWithCurl | msg=Notification Successfully Sent to http://smart-vertical:9090/subscription/traffic-flow/observation?subscriptionId=urn:ngsi-ld:Subscription:59c301f4-972f-11ed-809c-0242ac190006
接收通知的Quarkus资源代码
@Path("/subscription/traffic-flow") public class TrafficFlowResource { @POST @Path("/observation") @Consumes(MediaType.APPLICATION_JSON) public void measurement(@QueryParam("subscriptionId") String id, Payload payload) { logger.info(payload); } }
Orion订阅配置
curl -L -X POST 'http://localhost:1026/ngsi-ld/v1/subscriptions/' \ -H 'Content-Type: application/ld+json' \ -H 'NGSILD-Tenant: openiot' \ --data-raw '{ "description": "Notify me of all traffic flow observation changes", "type": "Subscription", "entities": [{"type": "TrafficFlowObserved"}], "watchedAttributes": [ "averageVehicleSpeed", "intensity", "occupancy", "levelOfService", "roadLoad", "saturationFlow" ], "notification": { "format": "keyValues", "endpoint": { "uri": "http://smart-vertical:9090/subscription/traffic-flow/observation", "accept": "application/json" } }, "@context": "http://ld-context:80/ngsi-context.jsonld" }'
服务的Docker Compose配置
smart-vertical: build: context: ./smart-vertical dockerfile: src/main/docker/Dockerfile.jvm restart: on-failure depends_on: - orion expose: - "9090" ports: - "9090:9090" environment: - CB_HOST=orion - CB_PORT=1026 - SMART_VERTICAL_PORT=9090 - SMART_VERTICAL_HOST=http://smart-vertical:9090/subscription - NGSI_CONTEXT_URL=http://ld-context:80/ngsi-context.jsonld
排查过程与疑问
Orion与所有服务位于Docker自动创建的同一网络中,我怀疑是IP问题,但没有错误信息无法确认。
我尝试过修改订阅中的IP,将smart-vertical替换为localhost、Docker分配的172.30.0.8、0.0.0.0,但情况更糟,出现以下错误日志:
2023-01-18 14:55:44 time=Wednesday 18 Jan 13:55:44 2023.079Z | lvl=ERROR | corr=N/A | trans=1674050062-123-00000000379 | from=pending | srv=pending | subsrv=pending | comp=Orion | op=httpRequestSend.cpp[573]:httpRequestSendWithCurl | msg=curl_easy_perform failed: 7
或
2023-01-18 15:07:43 time=Wednesday 18 Jan 14:07:43 2023.747Z | lvl=ERROR | corr=N/A | trans=1674050827-980-00000000194 | from=pending | srv=pending | subsrv=pending | comp=Orion | op=httpRequestSend.cpp[573]:httpRequestSendWithCurl | msg=curl_easy_perform failed: 28
从Orion的实现代码中得知:
- 错误码7代表消息过大;
- 错误码28对应无效IP+无法初始化libcurl(仅当未提供实际curl作为第一个参数时可能发生)。
Quarkus使用Vertx,默认情况下Vertx使用自身DNS,这会不会是问题所在?但我不理解为何使用配置SMART_VERTICAL_HOST=http://smart-vertical:9090/subscription时没有IP问题,却仍无法接收消息。
内容的提问来源于stack exchange,提问作者Francesco Vignola
相关产品推荐
相关产品推荐

