1919import static com .rabbitmq .stream .Constants .COMMAND_DECLARE_PUBLISHER ;
2020import static com .rabbitmq .stream .Constants .COMMAND_DELETE_PUBLISHER ;
2121import static com .rabbitmq .stream .Constants .COMMAND_DELETE_STREAM ;
22+ import static com .rabbitmq .stream .Constants .COMMAND_EXCHANGE_COMMAND_VERSIONS ;
2223import static com .rabbitmq .stream .Constants .COMMAND_HEARTBEAT ;
2324import static com .rabbitmq .stream .Constants .COMMAND_METADATA ;
2425import static com .rabbitmq .stream .Constants .COMMAND_OPEN ;
6162import com .rabbitmq .stream .compression .CompressionCodecFactory ;
6263import com .rabbitmq .stream .impl .Client .ShutdownContext .ShutdownReason ;
6364import com .rabbitmq .stream .impl .ServerFrameHandler .FrameHandler ;
65+ import com .rabbitmq .stream .impl .ServerFrameHandler .FrameHandlerInfo ;
6466import com .rabbitmq .stream .metrics .MetricsCollector ;
6567import com .rabbitmq .stream .metrics .NoOpMetricsCollector ;
6668import com .rabbitmq .stream .sasl .CredentialsProvider ;
@@ -1302,7 +1304,7 @@ public List<String> partitions(String superStream) {
13021304 throw new IllegalArgumentException ("stream must not be null" );
13031305 }
13041306 int length =
1305- 2 + 2 + 4 + + 2 + superStream .length (); // API code, version, correlation ID, 1 string
1307+ 2 + 2 + 4 + 2 + superStream .length (); // API code, version, correlation ID, 1 string
13061308 int correlationId = correlationSequence .incrementAndGet ();
13071309 try {
13081310 ByteBuf bb = allocate (length + 4 );
@@ -1323,6 +1325,35 @@ public List<String> partitions(String superStream) {
13231325 }
13241326 }
13251327
1328+ List <FrameHandlerInfo > exchangeCommandVersions () {
1329+ List <FrameHandlerInfo > commandVersions = ServerFrameHandler .commandVersions ();
1330+ int length = 2 + 2 + 4 + 4 ; // API code, version, correlation ID, array size
1331+ length += commandVersions .size () * (2 + 2 + 2 );
1332+ int correlationId = correlationSequence .incrementAndGet ();
1333+ try {
1334+ ByteBuf bb = allocate (length + 4 );
1335+ bb .writeInt (length );
1336+ bb .writeShort (encodeRequestCode (COMMAND_EXCHANGE_COMMAND_VERSIONS ));
1337+ bb .writeShort (VERSION_1 );
1338+ bb .writeInt (correlationId );
1339+ bb .writeInt (commandVersions .size ());
1340+ for (FrameHandlerInfo commandVersion : commandVersions ) {
1341+ bb .writeShort (commandVersion .getKey ());
1342+ bb .writeShort (commandVersion .getMinVersion ());
1343+ bb .writeShort (commandVersion .getMaxVersion ());
1344+ }
1345+ OutstandingRequest <List <FrameHandlerInfo >> request =
1346+ new OutstandingRequest <>(this .rpcTimeout );
1347+ outstandingRequests .put (correlationId , request );
1348+ channel .writeAndFlush (bb );
1349+ request .block ();
1350+ return request .response .get ();
1351+ } catch (RuntimeException e ) {
1352+ outstandingRequests .remove (correlationId );
1353+ throw new StreamException (e );
1354+ }
1355+ }
1356+
13261357 void shutdownReason (ShutdownReason reason ) {
13271358 this .shutdownReason = reason ;
13281359 }
0 commit comments