Search in sources :

Example 1 with FindCoordinatorRequestData

use of org.apache.kafka.common.message.FindCoordinatorRequestData in project kafka by apache.

the class RequestResponseTest method cannotUseFindCoordinatorV0ToFindTransactionCoordinator.

@Test
public void cannotUseFindCoordinatorV0ToFindTransactionCoordinator() {
    FindCoordinatorRequest.Builder builder = new FindCoordinatorRequest.Builder(new FindCoordinatorRequestData().setKeyType(CoordinatorType.TRANSACTION.id).setKey("foobar"));
    assertThrows(UnsupportedVersionException.class, () -> builder.build((short) 0));
}
Also used : Builder(org.apache.kafka.common.requests.CreateTopicsRequest.Builder) FindCoordinatorRequestData(org.apache.kafka.common.message.FindCoordinatorRequestData) Test(org.junit.jupiter.api.Test)

Example 2 with FindCoordinatorRequestData

use of org.apache.kafka.common.message.FindCoordinatorRequestData in project kafka by apache.

the class AbstractCoordinator method sendFindCoordinatorRequest.

/**
 * Discover the current coordinator for the group. Sends a GroupMetadata request to
 * one of the brokers. The returned future should be polled to get the result of the request.
 * @return A request future which indicates the completion of the metadata request
 */
private RequestFuture<Void> sendFindCoordinatorRequest(Node node) {
    // initiate the group metadata request
    log.debug("Sending FindCoordinator request to broker {}", node);
    FindCoordinatorRequestData data = new FindCoordinatorRequestData().setKeyType(CoordinatorType.GROUP.id()).setKey(this.rebalanceConfig.groupId);
    FindCoordinatorRequest.Builder requestBuilder = new FindCoordinatorRequest.Builder(data);
    return client.send(node, requestBuilder).compose(new FindCoordinatorResponseHandler());
}
Also used : FindCoordinatorRequest(org.apache.kafka.common.requests.FindCoordinatorRequest) FindCoordinatorRequestData(org.apache.kafka.common.message.FindCoordinatorRequestData)

Example 3 with FindCoordinatorRequestData

use of org.apache.kafka.common.message.FindCoordinatorRequestData in project kafka by apache.

the class TransactionManager method lookupCoordinator.

private void lookupCoordinator(FindCoordinatorRequest.CoordinatorType type, String coordinatorKey) {
    switch(type) {
        case GROUP:
            consumerGroupCoordinator = null;
            break;
        case TRANSACTION:
            transactionCoordinator = null;
            break;
        default:
            throw new IllegalStateException("Invalid coordinator type: " + type);
    }
    FindCoordinatorRequestData data = new FindCoordinatorRequestData().setKeyType(type.id()).setKey(coordinatorKey);
    FindCoordinatorRequest.Builder builder = new FindCoordinatorRequest.Builder(data);
    enqueueRequest(new FindCoordinatorHandler(builder));
}
Also used : FindCoordinatorRequest(org.apache.kafka.common.requests.FindCoordinatorRequest) FindCoordinatorRequestData(org.apache.kafka.common.message.FindCoordinatorRequestData)

Example 4 with FindCoordinatorRequestData

use of org.apache.kafka.common.message.FindCoordinatorRequestData in project kafka by apache.

the class CoordinatorStrategy method buildRequest.

@Override
public FindCoordinatorRequest.Builder buildRequest(Set<CoordinatorKey> keys) {
    unrepresentableKeys = keys.stream().filter(k -> k == null || !isRepresentableKey(k.idValue)).collect(Collectors.toSet());
    Set<CoordinatorKey> representableKeys = keys.stream().filter(k -> k != null && isRepresentableKey(k.idValue)).collect(Collectors.toSet());
    if (batch) {
        ensureSameType(representableKeys);
        FindCoordinatorRequestData data = new FindCoordinatorRequestData().setKeyType(type.id()).setCoordinatorKeys(representableKeys.stream().map(k -> k.idValue).collect(Collectors.toList()));
        return new FindCoordinatorRequest.Builder(data);
    } else {
        CoordinatorKey key = requireSingletonAndType(representableKeys);
        return new FindCoordinatorRequest.Builder(new FindCoordinatorRequestData().setKey(key.idValue).setKeyType(key.type.id()));
    }
}
Also used : Coordinator(org.apache.kafka.common.message.FindCoordinatorResponseData.Coordinator) FindCoordinatorResponse(org.apache.kafka.common.requests.FindCoordinatorResponse) GroupAuthorizationException(org.apache.kafka.common.errors.GroupAuthorizationException) InvalidGroupIdException(org.apache.kafka.common.errors.InvalidGroupIdException) Logger(org.slf4j.Logger) AbstractResponse(org.apache.kafka.common.requests.AbstractResponse) Set(java.util.Set) HashMap(java.util.HashMap) TransactionalIdAuthorizationException(org.apache.kafka.common.errors.TransactionalIdAuthorizationException) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) CoordinatorType(org.apache.kafka.common.requests.FindCoordinatorRequest.CoordinatorType) FindCoordinatorRequestData(org.apache.kafka.common.message.FindCoordinatorRequestData) FindCoordinatorRequest(org.apache.kafka.common.requests.FindCoordinatorRequest) LogContext(org.apache.kafka.common.utils.LogContext) Map(java.util.Map) Errors(org.apache.kafka.common.protocol.Errors) Collections(java.util.Collections) FindCoordinatorRequestData(org.apache.kafka.common.message.FindCoordinatorRequestData)

Aggregations

FindCoordinatorRequestData (org.apache.kafka.common.message.FindCoordinatorRequestData)4 FindCoordinatorRequest (org.apache.kafka.common.requests.FindCoordinatorRequest)3 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 GroupAuthorizationException (org.apache.kafka.common.errors.GroupAuthorizationException)1 InvalidGroupIdException (org.apache.kafka.common.errors.InvalidGroupIdException)1 TransactionalIdAuthorizationException (org.apache.kafka.common.errors.TransactionalIdAuthorizationException)1 Coordinator (org.apache.kafka.common.message.FindCoordinatorResponseData.Coordinator)1 Errors (org.apache.kafka.common.protocol.Errors)1 AbstractResponse (org.apache.kafka.common.requests.AbstractResponse)1 Builder (org.apache.kafka.common.requests.CreateTopicsRequest.Builder)1 CoordinatorType (org.apache.kafka.common.requests.FindCoordinatorRequest.CoordinatorType)1 FindCoordinatorResponse (org.apache.kafka.common.requests.FindCoordinatorResponse)1 LogContext (org.apache.kafka.common.utils.LogContext)1 Test (org.junit.jupiter.api.Test)1 Logger (org.slf4j.Logger)1