@@ -25,21 +25,23 @@ public void Run()
25
25
byte [ ] message = [ ] ;
26
26
var usePersistence = false ;
27
27
28
- var scenario = Scenario . Create ( "amqp_scenario " , async ctx =>
28
+ var scenario = Scenario . Create ( "client_pool_scenario " , async ctx =>
29
29
{
30
+ // get a client from the pool by Scenario InstanceID
30
31
var client = clientPool . GetClient ( ctx . ScenarioInfo ) ;
31
32
32
33
var publish = await Step . Run ( "publish" , ctx , async ( ) =>
33
34
{
34
- var scenarioInstanceId = ctx . ScenarioInfo . InstanceId ;
35
- var prop = new BasicProperties { Persistent = usePersistence } ;
35
+ var queueName = $ "queue_ { ctx . ScenarioInfo . InstanceNumber } " ;
36
+ var props = new BasicProperties { Persistent = usePersistence } ;
36
37
37
- var response = await client . Publish ( exchange : "myExchange" , routingKey : scenarioInstanceId , basicProperties : prop , body : message ) ;
38
+ var response = await client . Publish ( exchange : "myExchange" , routingKey : queueName , props , message ) ;
38
39
return response ;
39
40
} ) ;
40
41
41
42
var receive = await Step . Run ( "receive" , ctx , async ( ) =>
42
43
{
44
+ // pass the ScenarioCancellationToken to stop waiting for a response if the scenario finish event is triggered
43
45
var response = await client . Receive ( ctx . ScenarioCancellationToken ) ;
44
46
return response ;
45
47
} ) ;
@@ -54,19 +56,21 @@ public void Run()
54
56
55
57
var factory = new ConnectionFactory { HostName = config . AmqpServerUrl } ;
56
58
59
+ // initialize a client and add it to the ClientPool
57
60
for ( var i = 0 ; i < config . ClientCount ; i ++ )
58
61
{
59
62
var connection = await factory . CreateConnectionAsync ( ) ;
60
63
var channel = await connection . CreateChannelAsync ( ) ;
61
64
var amqpClient = new AmqpClient ( channel ) ;
62
65
63
- var scenarioInstanceId = $ "amqp_scenario_{ i } ";
64
- var result = await amqpClient . Connect ( exchange : "myExchange" , exchangeType : ExchangeType . Direct , queue : scenarioInstanceId ,
65
- routingKey : scenarioInstanceId , durable : usePersistence ) ;
66
+ var queueName = $ "queue_{ i } ";
67
+
68
+ var result = await amqpClient . DeclareQueue ( exchange : "myExchange" , exchangeType : ExchangeType . Direct , queue : queueName ,
69
+ routingKey : queueName , durable : usePersistence ) ;
66
70
67
71
if ( ! result . IsError )
68
72
{
69
- await amqpClient . Subscribe ( queue : scenarioInstanceId ) ;
73
+ await amqpClient . Subscribe ( queue : queueName ) ;
70
74
clientPool . AddClient ( amqpClient ) ;
71
75
}
72
76
else
0 commit comments