public BlockingChannel create(ConsumerGroupId consumerGroupId) { ConsumerMetadataResponse metadataResponse = readConsumerMetadata(consumerGroupId); if (metadataResponse.errorCode() != ErrorMapping.NoError()) { throw new ReadingConsumerMetadataException(metadataResponse.errorCode()); } Broker coordinator = metadataResponse.coordinator(); BlockingChannel blockingChannel = new BlockingChannel( coordinator.host(), coordinator.port(), BlockingChannel.UseDefaultBufferSize(), BlockingChannel.UseDefaultBufferSize(), readTimeout); return blockingChannel; }
private ConsumerMetadataResponse readConsumerMetadata(ConsumerGroupId consumerGroupId) { BlockingChannel channel = new BlockingChannel( broker.getHostText(), broker.getPort(), BlockingChannel.UseDefaultBufferSize(), BlockingChannel.UseDefaultBufferSize(), readTimeout); channel.connect(); channel.send( new ConsumerMetadataRequest( consumerGroupId.asString(), ConsumerMetadataRequest.CurrentVersion(), 0, "0")); ConsumerMetadataResponse metadataResponse = ConsumerMetadataResponse.readFrom(channel.receive().buffer()); channel.disconnect(); return metadataResponse; }