Skip to content

Commit ab66ab6

Browse files
authored
Add example of sending lite_topic in python sdk. (#1170)
1 parent 0b838e7 commit ab66ab6

File tree

3 files changed

+57
-6
lines changed

3 files changed

+57
-6
lines changed

README-CN.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
| Producer with transactional messages |||||||| 🚧 |
2626
| Producer with recalling timed/delay messages ||| 🚧 | 🚧 | 🚧 || 🚧 | 🚧 |
2727
| Simple consumer |||||||| 🚧 |
28-
| Push consumer with concurrent message listener |||| 🚧 ||| 🚧 | 🚧 |
29-
| Push consumer with FIFO message listener |||| 🚧 ||| 🚧 | 🚧 |
30-
| Push consumer with FIFO consume accelerator ||| 🚧 | 🚧 | 🚧 || 🚧 | 🚧 |
28+
| Push consumer with concurrent message listener |||| ||| 🚧 | 🚧 |
29+
| Push consumer with FIFO message listener |||| ||| 🚧 | 🚧 |
30+
| Push consumer with FIFO consume accelerator ||| 🚧 | | 🚧 || 🚧 | 🚧 |
3131
| Priority Message || 🚧 | 🚧 | 🚧 | 🚧 | 🚧 | 🚧 | 🚧 |
3232

3333
## 先决条件和构建

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ Provide cloud-native and robust solutions for Java, C++, C#, Golang, Rust and al
2525
| Producer with transactional messages |||||||| 🚧 |
2626
| Producer with recalling timed/delay messages ||| 🚧 | 🚧 | 🚧 || 🚧 | 🚧 |
2727
| Simple consumer |||||||| 🚧 |
28-
| Push consumer with concurrent message listener |||| 🚧 ||| 🚧 | 🚧 |
29-
| Push consumer with FIFO message listener |||| 🚧 ||| 🚧 | 🚧 |
30-
| Push consumer with FIFO consume accelerator ||| 🚧 | 🚧 | 🚧 || 🚧 | 🚧 |
28+
| Push consumer with concurrent message listener |||| ||| 🚧 | 🚧 |
29+
| Push consumer with FIFO message listener |||| ||| 🚧 | 🚧 |
30+
| Push consumer with FIFO consume accelerator ||| 🚧 | | 🚧 || 🚧 | 🚧 |
3131
| Priority Message || 🚧 | 🚧 | 🚧 | 🚧 | 🚧 | 🚧 | 🚧 |
3232

3333
## Prerequisite and Build
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one or more
2+
# contributor license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright ownership.
4+
# The ASF licenses this file to You under the Apache License, Version 2.0
5+
# (the "License"); you may not use this file except in compliance with
6+
# the License. You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
from rocketmq import ClientConfiguration, Credentials, Message, Producer
17+
18+
if __name__ == '__main__':
19+
endpoints = "foobar.com:8080"
20+
credentials = Credentials()
21+
22+
# if auth enable
23+
# credentials = Credentials("ak", "sk")
24+
config = ClientConfiguration(endpoints, credentials)
25+
# with namespace
26+
# config = ClientConfiguration(endpoints, credentials, "namespace")
27+
topic = "parent-topic"
28+
producer = Producer(config, (topic,))
29+
30+
try:
31+
producer.startup()
32+
try:
33+
msg = Message()
34+
# parent topic for the current message
35+
msg.topic = topic
36+
msg.body = "hello, rocketmq.".encode('utf-8')
37+
for i in range(0, 10):
38+
# set lite_topic
39+
msg.lite_topic("lite-test-" + str(i))
40+
res = producer.send(msg)
41+
print(f"{producer} send message success. {res}")
42+
producer.shutdown()
43+
print(f"{producer} shutdown.")
44+
except Exception as e:
45+
print(f"{producer} raise exception: {e}")
46+
producer.shutdown()
47+
print(f"{producer} shutdown.")
48+
except Exception as e:
49+
print(f"{producer} startup raise exception: {e}")
50+
producer.shutdown()
51+
print(f"{producer} shutdown.")

0 commit comments

Comments
 (0)