Skip to content

Commit

Permalink
only send string
Browse files Browse the repository at this point in the history
  • Loading branch information
Ed-XCF committed Sep 17, 2021
1 parent 50ca2f5 commit 26fdc09
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions aliyun_rocketmq_provider/hooks/aliyun_rocketmq.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import json
from typing import Dict

from mq_http_sdk.mq_client import MQClient, MQProducer
Expand Down Expand Up @@ -46,11 +45,16 @@ def get_conn(self) -> MQProducer:
client = MQClient(conn.host, conn.login, conn.password)
return client.get_producer(conn.schema, self.topic)

def run(self, data: Dict, tag: str = None, fail_silently: bool = False) -> TopicMessage:
def run(
self,
message_body: str,
message_tag: str = None,
fail_silently: bool = False
) -> TopicMessage:
"""Publish the data."""
try:
conn = self.get_conn()
message = TopicMessage(json.dumps(data), (tag or "").lower())
message = TopicMessage(message_body, (message_tag or "").lower())
return conn.publish_message(message)
except Exception as e:
if not fail_silently:
Expand Down
2 changes: 1 addition & 1 deletion tests/hooks/test_aliyun_rocketmq_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ def setup_class(self):
def test_publish(self):
hook = AliyunRocketMQHook(topic="test_topic")
with mock.patch.object(MQClient, "publish_message"):
response = hook.run({})
response = hook.run("")
assert response.message_id == ""

0 comments on commit 26fdc09

Please sign in to comment.