Ejemplo n.º 1
0
  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;
  }
Ejemplo n.º 2
0
  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;
  }