Skip to content

[Bug]: APP can not connect mqtt as native, not Dapr #230

@ley901017

Description

@ley901017

Severity

Critical

What release version, tag or commit-hash did you use?

v0.1.1

Current Behavior

When I run velocita app directly without dapr, the below error message has been appeared.

Exception ignored in: <function Client.__del__ at 0x7f2f7c87c670>
Traceback (most recent call last):
  File "/home/vscode/.local/lib/python3.10/site-packages/paho/mqtt/client.py", line 874, in __del__
    self._reset_sockets()
  File "/home/vscode/.local/lib/python3.10/site-packages/paho/mqtt/client.py", line 1133, in _reset_sockets
    self._sock_close()
  File "/home/vscode/.local/lib/python3.10/site-packages/paho/mqtt/client.py", line 1119, in _sock_close
    if not self._sock:
AttributeError: 'Client' object has no attribute '_sock'
Traceback (most recent call last):
  File "/workspaces/vehicle-app-python-template/app/src/main.py", line 25, in <module>
    from vehicle import Vehicle, vehicle  # type: ignore
  File "/home/vscode/.local/lib/python3.10/site-packages/vehicle/__init__.py", line 8, in <module>
    from velocitas_sdk.model import (
  File "/home/vscode/.local/lib/python3.10/site-packages/velocitas_sdk/model.py", line 24, in <module>
    from velocitas_sdk import config
  File "/home/vscode/.local/lib/python3.10/site-packages/velocitas_sdk/config.py", line 49, in <module>
    _config = Config(__middleware_type)
  File "/home/vscode/.local/lib/python3.10/site-packages/velocitas_sdk/config.py", line 36, in __init__
    self.middleware: Middleware = self.__create_middleware(__middleware)
  File "/home/vscode/.local/lib/python3.10/site-packages/velocitas_sdk/config.py", line 41, in __create_middleware
    _middleware = NativeMiddleware()
  File "/home/vscode/.local/lib/python3.10/site-packages/velocitas_sdk/native/middleware.py", line 34, in __init__
    self.pubsub_client = MqttClient(_port, _hostname)
  File "/home/vscode/.local/lib/python3.10/site-packages/velocitas_sdk/native/mqtt.py", line 42, in __init__
    self._pub_client = mqtt.Client()
TypeError: Client.__init__() missing 1 required positional argument: 'callback_api_version'

Steps to Reproduce

  1. In Dev Container, run task Local Runtime - Up
  2. execute python3 /workspaces/vehicle-app-python-template/app/src/main.py in terminal
  3. then you will see the error message

Expected Behavior

The app can run normally without dapr.

Possible Solution

No response

Additional Information

In velocitas_sdk, the below code may have some bugs, the path is velocitas_sdk/native/mqtt.py the function init of MqttClient, I cannot see any parameters on line 42 when call mqtt,Client()

lass MqttClient(PubSubClient):
    """This class is a wrapper for the on_message callback of the MQTT broker."""

    def __init__(self, port: Optional[int] = None, hostname: Optional[str] = None):
        self._port = port
        self._hostname = hostname
        self._topics_to_subscribe: list[MqttTopicSubscription] = []

        self._pub_client = mqtt.Client()
        self._sub_client = mqtt.Client()
        self._sub_client.on_connect = self.on_connect
        self._sub_client.on_disconnect = self.on_disconnect

        self._sub_client.connect(self._hostname, self._port)
        self._pub_client.connect(self._hostname, self._port)

Code of Conduct

  • I agree to follow this project's "Code of Conduct".

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status

    🏗 In progress

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions