Skip to content

Commit da09a54

Browse files
Split up topic names between tests
Signed-off-by: Elena Kolevska <elena@kolevska.com>
1 parent f7f5162 commit da09a54

File tree

4 files changed

+41
-18
lines changed

4 files changed

+41
-18
lines changed

examples/pubsub-streaming-async/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_B1..."
31+
- "== APP == Processing message: {'id': 2, 'message': 'hello world'} from TOPIC_B1..."
32+
- "== APP == Processing message: {'id': 3, 'message': 'hello world'} from TOPIC_B1..."
33+
- "== APP == Processing message: {'id': 4, 'message': 'hello world'} from TOPIC_B1..."
34+
- "== APP == Processing message: {'id': 5, 'message': 'hello world'} from TOPIC_B1..."
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_B1
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_B1
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_B2..."
79+
- "== APP == Processing message: {'id': 2, 'message': 'hello world'} from TOPIC_B2..."
80+
- "== APP == Processing message: {'id': 3, 'message': 'hello world'} from TOPIC_B2..."
81+
- "== APP == Processing message: {'id': 4, 'message': 'hello world'} from TOPIC_B2..."
82+
- "== APP == Processing message: {'id': 5, 'message': 'hello world'} from TOPIC_B2..."
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_B2
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_B2
115115
```
116116

117117
<!-- END_STEP -->

examples/pubsub-streaming-async/publisher.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,18 @@
1010
# See the License for the specific language governing permissions and
1111
# limitations under the License.
1212
# ------------------------------------------------------------
13+
import argparse
1314
import asyncio
1415
import json
1516

1617
from dapr.aio.clients import DaprClient
1718

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+
1825

1926
async def publish_events():
2027
"""
@@ -30,7 +37,7 @@ async def publish_events():
3037
# Create a typed message with content type and body
3138
await d.publish_event(
3239
pubsub_name='pubsub',
33-
topic_name='TOPIC_A',
40+
topic_name=topic_name,
3441
data=json.dumps(req_data),
3542
data_content_type='application/json',
3643
publish_metadata={'ttlInSeconds': '100', 'rawPayload': 'false'},

examples/pubsub-streaming-async/subscriber-handler.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
1+
import argparse
12
import asyncio
23
from dapr.aio.clients import DaprClient
34
from dapr.clients.grpc._response import TopicEventResponse
45

6+
parser = argparse.ArgumentParser(description='Publish events to a Dapr pub/sub topic.')
7+
parser.add_argument('--topic', type=str, required=True, help='The topic name to publish to.')
8+
args = parser.parse_args()
9+
10+
topic_name = args.topic
11+
dlq_topic_name = topic_name + '_DEAD'
12+
513
counter = 0
614

715

@@ -24,9 +32,9 @@ async def main():
2432
# Subscribe to the pubsub topic with the message handler
2533
close_fn = await client.subscribe_with_handler(
2634
pubsub_name='pubsub',
27-
topic='TOPIC_A',
35+
topic=topic_name,
2836
handler_fn=process_message,
29-
dead_letter_topic='TOPIC_A_DEAD',
37+
dead_letter_topic=dlq_topic_name,
3038
)
3139

3240
# Wait until 5 messages are processed

examples/pubsub-streaming-async/subscriber.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
1+
import argparse
12
import asyncio
23

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

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

816

@@ -18,7 +26,7 @@ async def main():
1826
async with DaprClient() as client:
1927
global counter
2028
subscription = await client.subscribe(
21-
pubsub_name='pubsub', topic='TOPIC_A', dead_letter_topic='TOPIC_A_DEAD'
29+
pubsub_name='pubsub', topic=topic_name, dead_letter_topic=dlq_topic_name
2230
)
2331

2432
try:

0 commit comments

Comments
 (0)