Skip to content

[Bug] Errors using python client. #784

Closed
@yuz10

Description

Before Creating the Bug Report

  • I found a bug, not just asking a question, which should be created in GitHub Discussions.

  • I have searched the GitHub Issues and GitHub Discussions of this repository and believe that this is not a duplicate.

  • I have confirmed that this bug belongs to the current repository, not other repositories of RocketMQ.

Programming Language of the Client

Python

Runtime Platform Environment

Ubuntu

RocketMQ Version of the Client/Server

5.2.0

Run or Compiler Version

Ubuntu

Describe the Bug

python client code:

import asyncio
import sys
import os
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
sys.path.append(os.path.join(os.path.dirname(__file__), '../rocketmq'))

from client_config import ClientConfig
from filter_expression import FilterExpression
from log import logger
from protocol.definition_pb2 import Resource
from rpc_client import Endpoints
from session_credentials import (SessionCredentials,
                                          SessionCredentialsProvider)
from simple_consumer import SimpleConsumer


async def test():
    credentials = SessionCredentials("username", "password")
    credentials_provider = SessionCredentialsProvider(credentials)
    client_config = ClientConfig(
        endpoints=Endpoints("localhost:8080"),
        session_credentials_provider=credentials_provider,
        ssl_enabled=False,
    )
    topic = Resource()
    topic.name = "TopicTest"

    consumer_group = "yourConsumerGroup"
    subscription = {topic.name: FilterExpression("*")}
    simple_consumer = (await SimpleConsumer.Builder()
                       .set_client_config(client_config)
                       .set_consumer_group(consumer_group)
                       .set_await_duration(15)
                       .set_subscription_expression(subscription)
                       .build())
    logger.info(simple_consumer)
    while True:
        message_views = await simple_consumer.receive(16, 15)
        logger.info(message_views)
        for message in message_views:
            logger.info(message.body)
            logger.info(f"Received a message, topic={message.topic}, message-id={message.message_id}, body-size={len(message.body)}")
            await simple_consumer.ack(message)
            logger.info(f"Message is acknowledged successfully, message-id={message.message_id}")

if __name__ == "__main__":
    asyncio.run(test())

errors:
1, importlib.metadata.PackageNotFoundError: No package metadata was found for rocketmq

  File "/root/rocketmq-clients/python/examples/../rocketmq/client.py", line 332, in query_route
    metadata = Signature.sign(self.__client.client_config, self.__client.client_id)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/rocketmq-clients/python/examples/../rocketmq/signature.py", line 48, in sign
    (Signature.__CLIENT_VERSION_KEY, importlib.metadata.version("rocketmq")),
                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/importlib/metadata/__init__.py", line 889, in version
    return distribution(distribution_name).version
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/importlib/metadata/__init__.py", line 862, in distribution
    return Distribution.from_name(distribution_name)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/importlib/metadata/__init__.py", line 399, in from_name
    raise PackageNotFoundError(name)
importlib.metadata.PackageNotFoundError: No package metadata was found for rocketmq
  1. 'FilterExpression' object has no attribute 'Type'. Did you mean: 'type'?
  File "/root/rocketmq-clients/python/examples/../rocketmq/simple_consumer.py", line 289, in build
    await simple_consumer.start()
  File "/root/rocketmq-clients/python/examples/../rocketmq/simple_consumer.py", line 137, in start
    await super().start()
  File "/root/rocketmq-clients/python/examples/../rocketmq/client.py", line 94, in start
    self.topic_route_cache[topic] = await self.fetch_topic_route(topic)
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/rocketmq-clients/python/examples/../rocketmq/client.py", line 249, in fetch_topic_route
    await self.on_topic_route_data_fetched(topic, topic_route_data)
  File "/root/rocketmq-clients/python/examples/../rocketmq/client.py", line 213, in on_topic_route_data_fetched
    await session.sync_settings(True)
  File "/root/rocketmq-clients/python/examples/../rocketmq/session.py", line 54, in sync_settings
    telemetry_command.settings.CopyFrom(settings.to_protobuf())
                                        ^^^^^^^^^^^^^^^^^^^^^^
  File "/root/rocketmq-clients/python/examples/../rocketmq/simple_subscription_settings.py", line 68, in to_protobuf
    logger.warn(f"[Bug] Unrecognized filter type={value.Type} for simple consumer")
                                                  ^^^^^^^^^^
AttributeError: 'FilterExpression' object has no attribute 'Type'. Did you mean: 'type'?

Steps to Reproduce

python client code:

import asyncio
import sys
import os
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
sys.path.append(os.path.join(os.path.dirname(__file__), '../rocketmq'))

from client_config import ClientConfig
from filter_expression import FilterExpression
from log import logger
from protocol.definition_pb2 import Resource
from rpc_client import Endpoints
from session_credentials import (SessionCredentials,
                                          SessionCredentialsProvider)
from simple_consumer import SimpleConsumer


async def test():
    credentials = SessionCredentials("username", "password")
    credentials_provider = SessionCredentialsProvider(credentials)
    client_config = ClientConfig(
        endpoints=Endpoints("localhost:8080"),
        session_credentials_provider=credentials_provider,
        ssl_enabled=False,
    )
    topic = Resource()
    topic.name = "TopicTest"

    consumer_group = "yourConsumerGroup"
    subscription = {topic.name: FilterExpression("*")}
    simple_consumer = (await SimpleConsumer.Builder()
                       .set_client_config(client_config)
                       .set_consumer_group(consumer_group)
                       .set_await_duration(15)
                       .set_subscription_expression(subscription)
                       .build())
    logger.info(simple_consumer)
    while True:
        message_views = await simple_consumer.receive(16, 15)
        logger.info(message_views)
        for message in message_views:
            logger.info(message.body)
            logger.info(f"Received a message, topic={message.topic}, message-id={message.message_id}, body-size={len(message.body)}")
            await simple_consumer.ack(message)
            logger.info(f"Message is acknowledged successfully, message-id={message.message_id}")

if __name__ == "__main__":
    asyncio.run(test())

What Did You Expect to See?

run success

What Did You See Instead?

errors:
1, importlib.metadata.PackageNotFoundError: No package metadata was found for rocketmq

  File "/root/rocketmq-clients/python/examples/../rocketmq/client.py", line 332, in query_route
    metadata = Signature.sign(self.__client.client_config, self.__client.client_id)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/rocketmq-clients/python/examples/../rocketmq/signature.py", line 48, in sign
    (Signature.__CLIENT_VERSION_KEY, importlib.metadata.version("rocketmq")),
                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/importlib/metadata/__init__.py", line 889, in version
    return distribution(distribution_name).version
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/importlib/metadata/__init__.py", line 862, in distribution
    return Distribution.from_name(distribution_name)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/importlib/metadata/__init__.py", line 399, in from_name
    raise PackageNotFoundError(name)
importlib.metadata.PackageNotFoundError: No package metadata was found for rocketmq
  1. 'FilterExpression' object has no attribute 'Type'. Did you mean: 'type'?
  File "/root/rocketmq-clients/python/examples/../rocketmq/simple_consumer.py", line 289, in build
    await simple_consumer.start()
  File "/root/rocketmq-clients/python/examples/../rocketmq/simple_consumer.py", line 137, in start
    await super().start()
  File "/root/rocketmq-clients/python/examples/../rocketmq/client.py", line 94, in start
    self.topic_route_cache[topic] = await self.fetch_topic_route(topic)
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/rocketmq-clients/python/examples/../rocketmq/client.py", line 249, in fetch_topic_route
    await self.on_topic_route_data_fetched(topic, topic_route_data)
  File "/root/rocketmq-clients/python/examples/../rocketmq/client.py", line 213, in on_topic_route_data_fetched
    await session.sync_settings(True)
  File "/root/rocketmq-clients/python/examples/../rocketmq/session.py", line 54, in sync_settings
    telemetry_command.settings.CopyFrom(settings.to_protobuf())
                                        ^^^^^^^^^^^^^^^^^^^^^^
  File "/root/rocketmq-clients/python/examples/../rocketmq/simple_subscription_settings.py", line 68, in to_protobuf
    logger.warn(f"[Bug] Unrecognized filter type={value.Type} for simple consumer")
                                                  ^^^^^^^^^^
AttributeError: 'FilterExpression' object has no attribute 'Type'. Did you mean: 'type'?

Additional Context

No response

Metadata

Assignees

No one assigned

    Labels

    type/bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions