File tree Expand file tree Collapse file tree 1 file changed +7
-3
lines changed Expand file tree Collapse file tree 1 file changed +7
-3
lines changed Original file line number Diff line number Diff line change @@ -96,16 +96,15 @@ public function getClient(?int $brokerId = null): ClientInterface
9696 if (null === $ brokerId ) {
9797 return $ this ->getRandomClient ();
9898 } elseif (isset ($ this ->brokers [$ brokerId ])) {
99- return $ this ->brokers [ $ brokerId] ;
99+ return $ this ->getClientByIndex ( $ brokerId) ;
100100 } else {
101101 throw new InvalidArgumentException (sprintf ('Not found brokerId %s ' , $ brokerId ));
102102 }
103103 }
104104
105- public function getRandomClient ( ): ClientInterface
105+ public function getClientByIndex ( int $ index ): ClientInterface
106106 {
107107 $ brokers = $ this ->getBrokers ();
108- $ index = array_rand ($ brokers , 1 );
109108 $ url = parse_url ($ brokers [$ index ]);
110109 if (!$ url ) {
111110 throw new InvalidArgumentException (sprintf ('Invalid bootstrapServer %s ' , $ brokers [$ index ]));
@@ -123,6 +122,11 @@ public function getRandomClient(): ClientInterface
123122 return $ this ->clients [$ index ];
124123 }
125124
125+ public function getRandomClient (): ClientInterface
126+ {
127+ return $ this ->getClientByIndex (array_rand ($ this ->getBrokers (), 1 ));
128+ }
129+
126130 /**
127131 * @return string|string[]
128132 */
You can’t perform that action at this time.
0 commit comments