Skip to content

Commit

Permalink
[ISSUE #784] fix python client (#783)
Browse files Browse the repository at this point in the history
fix python client
  • Loading branch information
yuz10 committed Jul 4, 2024
1 parent 156784b commit b4a47a9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
6 changes: 5 additions & 1 deletion python/rocketmq/signature.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,18 @@ class Signature:
__CREDENTIAL = "Credential"
__SIGNED_HEADERS = "SignedHeaders"
__SIGNATURE = "Signature"
try:
__CLIENT_VERSION = importlib.metadata.version("rocketmq")
except Exception:
__CLIENT_VERSION = "0.1.0"

@staticmethod
def sign(client_config: ClientConfig, client_id: str):
date_time = datetime.datetime.now().strftime(Signature.__DATE_TIME_FORMAT)
metadata = [
(Signature.__LANGUAGE_KEY, "PYTHON"),
(Signature.__PROTOCOL_VERSION, "v2"),
(Signature.__CLIENT_VERSION_KEY, importlib.metadata.version("rocketmq")),
(Signature.__CLIENT_VERSION_KEY, Signature.__CLIENT_VERSION),
(
Signature.__DATE_TIME_KEY,
date_time,
Expand Down
15 changes: 4 additions & 11 deletions python/rocketmq/simple_subscription_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from typing import Dict

from google.protobuf.duration_pb2 import Duration
from rocketmq.filter_expression import ExpressionType
from rocketmq.filter_expression import ExpressionType, FilterExpression
from rocketmq.log import logger
from rocketmq.protocol.definition_pb2 import \
FilterExpression as ProtoFilterExpression
Expand All @@ -30,13 +30,6 @@
from .settings import ClientType, ClientTypeHelper, Settings


# Assuming a simple representation of FilterExpression for the purpose of this example
class FilterExpression:
def __init__(self, type, expression):
self.Type = type
self.Expression = expression


class SimpleSubscriptionSettings(Settings):

def __init__(self, clientId, endpoints, consumerGroup, requestTimeout, longPollingTimeout,
Expand All @@ -60,12 +53,12 @@ def to_protobuf(self):
subscriptionEntry = ProtoSubscriptionEntry()
filterExpression = ProtoFilterExpression()

if value.type == ExpressionType.Tag:
if value.type.value == ExpressionType.Tag.value:
filterExpression.type = ProtoFilterType.TAG
elif value.type == ExpressionType.Sql92:
elif value.type.value == ExpressionType.Sql92.value:
filterExpression.type = ProtoFilterType.SQL
else:
logger.warn(f"[Bug] Unrecognized filter type={value.Type} for simple consumer")
logger.warn(f"[Bug] Unrecognized filter type={value.type} for simple consumer")

filterExpression.expression = value.expression
subscriptionEntry.topic.CopyFrom(topic)
Expand Down

0 comments on commit b4a47a9

Please sign in to comment.