Skip to content

Commit 2ab9a77

Browse files
Split up topic names between tests
Signed-off-by: Elena Kolevska <[email protected]>
1 parent ed69ed8 commit 2ab9a77

File tree

4 files changed

+40
-19
lines changed

4 files changed

+40
-19
lines changed

examples/pubsub-streaming/README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ Run the following command in a terminal/command prompt:
2727
<!-- STEP
2828
name: Run subscriber
2929
expected_stdout_lines:
30-
- "== APP == Processing message: {'id': 1, 'message': 'hello world'} from TOPIC_A..."
31-
- "== APP == Processing message: {'id': 2, 'message': 'hello world'} from TOPIC_A..."
32-
- "== APP == Processing message: {'id': 3, 'message': 'hello world'} from TOPIC_A..."
33-
- "== APP == Processing message: {'id': 4, 'message': 'hello world'} from TOPIC_A..."
34-
- "== APP == Processing message: {'id': 5, 'message': 'hello world'} from TOPIC_A..."
30+
- "== APP == Processing message: {'id': 1, 'message': 'hello world'} from TOPIC_A1..."
31+
- "== APP == Processing message: {'id': 2, 'message': 'hello world'} from TOPIC_A1..."
32+
- "== APP == Processing message: {'id': 3, 'message': 'hello world'} from TOPIC_A1..."
33+
- "== APP == Processing message: {'id': 4, 'message': 'hello world'} from TOPIC_A1..."
34+
- "== APP == Processing message: {'id': 5, 'message': 'hello world'} from TOPIC_A1..."
3535
- "== APP == Closing subscription..."
3636
output_match_mode: substring
3737
background: true
@@ -41,7 +41,7 @@ sleep: 3
4141

4242
```bash
4343
# 1. Start Subscriber
44-
dapr run --app-id python-subscriber --app-protocol grpc python3 subscriber.py
44+
dapr run --app-id python-subscriber --app-protocol grpc -- python3 subscriber.py --topic=TOPIC_A1
4545
```
4646

4747
<!-- END_STEP -->
@@ -63,7 +63,7 @@ sleep: 15
6363

6464
```bash
6565
# 2. Start Publisher
66-
dapr run --app-id python-publisher --app-protocol grpc --dapr-grpc-port=3500 --enable-app-health-check python3 publisher.py
66+
dapr run --app-id python-publisher --app-protocol grpc --dapr-grpc-port=3500 --enable-app-health-check -- python3 publisher.py --topic=TOPIC_A1
6767
```
6868

6969
<!-- END_STEP -->
@@ -75,11 +75,11 @@ Run the following command in a terminal/command prompt:
7575
<!-- STEP
7676
name: Run subscriber
7777
expected_stdout_lines:
78-
- "== APP == Processing message: {'id': 1, 'message': 'hello world'} from TOPIC_A..."
79-
- "== APP == Processing message: {'id': 2, 'message': 'hello world'} from TOPIC_A..."
80-
- "== APP == Processing message: {'id': 3, 'message': 'hello world'} from TOPIC_A..."
81-
- "== APP == Processing message: {'id': 4, 'message': 'hello world'} from TOPIC_A..."
82-
- "== APP == Processing message: {'id': 5, 'message': 'hello world'} from TOPIC_A..."
78+
- "== APP == Processing message: {'id': 1, 'message': 'hello world'} from TOPIC_A2..."
79+
- "== APP == Processing message: {'id': 2, 'message': 'hello world'} from TOPIC_A2..."
80+
- "== APP == Processing message: {'id': 3, 'message': 'hello world'} from TOPIC_A2..."
81+
- "== APP == Processing message: {'id': 4, 'message': 'hello world'} from TOPIC_A2..."
82+
- "== APP == Processing message: {'id': 5, 'message': 'hello world'} from TOPIC_A2..."
8383
- "== APP == Closing subscription..."
8484
output_match_mode: substring
8585
background: true
@@ -89,7 +89,7 @@ sleep: 3
8989

9090
```bash
9191
# 1. Start Subscriber
92-
dapr run --app-id python-subscriber --app-protocol grpc python3 subscriber-handler.py
92+
dapr run --app-id python-subscriber --app-protocol grpc -- python3 subscriber-handler.py --topic=TOPIC_A2
9393
```
9494

9595
<!-- END_STEP -->
@@ -111,7 +111,7 @@ sleep: 15
111111

112112
```bash
113113
# 2. Start Publisher
114-
dapr run --app-id python-publisher --app-protocol grpc --dapr-grpc-port=3500 --enable-app-health-check python3 publisher.py
114+
dapr run --app-id python-publisher --app-protocol grpc --dapr-grpc-port=3500 --enable-app-health-check -- python3 publisher.py --topic=TOPIC_A2
115115
```
116116

117117
<!-- END_STEP -->

examples/pubsub-streaming/publisher.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,18 @@
1010
# See the License for the specific language governing permissions and
1111
# limitations under the License.
1212
# ------------------------------------------------------------
13-
13+
import argparse
1414
import json
1515
import time
1616

1717
from dapr.clients import DaprClient
1818

19+
parser = argparse.ArgumentParser(description='Publish events to a Dapr pub/sub topic.')
20+
parser.add_argument('--topic', type=str, required=True, help='The topic name to publish to.')
21+
args = parser.parse_args()
22+
23+
topic_name = args.topic
24+
1925
with DaprClient() as d:
2026
id = 0
2127
while id < 5:
@@ -25,7 +31,7 @@
2531
# Create a typed message with content type and body
2632
resp = d.publish_event(
2733
pubsub_name='pubsub',
28-
topic_name='TOPIC_A',
34+
topic_name=topic_name,
2935
data=json.dumps(req_data),
3036
data_content_type='application/json',
3137
publish_metadata={'ttlInSeconds': '100', 'rawPayload': 'false'},

examples/pubsub-streaming/subscriber-handler.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
1+
import argparse
12
import time
23

34
from dapr.clients import DaprClient
45
from dapr.clients.grpc._response import TopicEventResponse
56

67
counter = 0
78

9+
parser = argparse.ArgumentParser(description='Publish events to a Dapr pub/sub topic.')
10+
parser.add_argument('--topic', type=str, required=True, help='The topic name to publish to.')
11+
args = parser.parse_args()
12+
13+
topic_name = args.topic
14+
dlq_topic_name = topic_name + '_DEAD'
815

916
def process_message(message):
1017
# Process the message here
@@ -20,9 +27,9 @@ def main():
2027
# and process them in the `process_message` function
2128
close_fn = client.subscribe_with_handler(
2229
pubsub_name='pubsub',
23-
topic='TOPIC_A',
30+
topic=topic_name,
2431
handler_fn=process_message,
25-
dead_letter_topic='TOPIC_A_DEAD',
32+
dead_letter_topic=dlq_topic_name,
2633
)
2734

2835
while counter < 5:

examples/pubsub-streaming/subscriber.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
1+
import argparse
12
import time
23

34
from dapr.clients import DaprClient
45
from dapr.clients.grpc.subscription import StreamInactiveError
56

67
counter = 0
78

9+
parser = argparse.ArgumentParser(description='Publish events to a Dapr pub/sub topic.')
10+
parser.add_argument('--topic', type=str, required=True, help='The topic name to publish to.')
11+
args = parser.parse_args()
12+
13+
topic_name = args.topic
14+
dlq_topic_name = topic_name + '_DEAD'
15+
816

917
def process_message(message):
1018
global counter
@@ -20,7 +28,7 @@ def main():
2028

2129
try:
2230
subscription = client.subscribe(
23-
pubsub_name='pubsub', topic='TOPIC_A', dead_letter_topic='TOPIC_A_DEAD'
31+
pubsub_name='pubsub', topic=topic_name, dead_letter_topic=dlq_topic_name
2432
)
2533
except Exception as e:
2634
print(f'Error occurred: {e}')

0 commit comments

Comments
 (0)