Search in sources :

Example 1 with JoinGroupRequestData

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

the class AbstractCoordinator method sendJoinGroupRequest.

/**
 * Join the group and return the assignment for the next generation. This function handles both
 * JoinGroup and SyncGroup, delegating to {@link #onLeaderElected(String, String, List, boolean)} if
 * elected leader by the coordinator.
 *
 * NOTE: This is visible only for testing
 *
 * @return A request future which wraps the assignment returned from the group leader
 */
RequestFuture<ByteBuffer> sendJoinGroupRequest() {
    if (coordinatorUnknown())
        return RequestFuture.coordinatorNotAvailable();
    // send a join group request to the coordinator
    log.info("(Re-)joining group");
    JoinGroupRequest.Builder requestBuilder = new JoinGroupRequest.Builder(new JoinGroupRequestData().setGroupId(rebalanceConfig.groupId).setSessionTimeoutMs(this.rebalanceConfig.sessionTimeoutMs).setMemberId(this.generation.memberId).setGroupInstanceId(this.rebalanceConfig.groupInstanceId.orElse(null)).setProtocolType(protocolType()).setProtocols(metadata()).setRebalanceTimeoutMs(this.rebalanceConfig.rebalanceTimeoutMs).setReason(this.rejoinReason));
    log.debug("Sending JoinGroup ({}) to coordinator {}", requestBuilder, this.coordinator);
    // Note that we override the request timeout using the rebalance timeout since that is the
    // maximum time that it may block on the coordinator. We add an extra 5 seconds for small delays.
    int joinGroupTimeoutMs = Math.max(client.defaultRequestTimeoutMs(), Math.max(rebalanceConfig.rebalanceTimeoutMs + JOIN_GROUP_TIMEOUT_LAPSE, // guard against overflow since rebalance timeout can be MAX_VALUE
    rebalanceConfig.rebalanceTimeoutMs));
    return client.send(coordinator, requestBuilder, joinGroupTimeoutMs).compose(new JoinGroupResponseHandler(generation));
}
Also used : JoinGroupRequest(org.apache.kafka.common.requests.JoinGroupRequest) JoinGroupRequestData(org.apache.kafka.common.message.JoinGroupRequestData)

Example 2 with JoinGroupRequestData

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

the class RequestResponseTest method createJoinGroupRequest.

private JoinGroupRequest createJoinGroupRequest(short version) {
    JoinGroupRequestData.JoinGroupRequestProtocolCollection protocols = new JoinGroupRequestData.JoinGroupRequestProtocolCollection(Collections.singleton(new JoinGroupRequestData.JoinGroupRequestProtocol().setName("consumer-range").setMetadata(new byte[0])).iterator());
    JoinGroupRequestData data = new JoinGroupRequestData().setGroupId("group1").setSessionTimeoutMs(30000).setMemberId("consumer1").setProtocolType("consumer").setProtocols(protocols).setReason("reason: test");
    // v1 and above contains rebalance timeout
    if (version >= 1)
        data.setRebalanceTimeoutMs(60000);
    // v5 and above could set group instance id
    if (version >= 5)
        data.setGroupInstanceId("groupInstanceId");
    return new JoinGroupRequest.Builder(data).build(version);
}
Also used : JoinGroupRequestData(org.apache.kafka.common.message.JoinGroupRequestData)

Example 3 with JoinGroupRequestData

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

the class JoinGroupRequestTest method testRebalanceTimeoutDefaultsToSessionTimeoutV0.

@Test
public void testRebalanceTimeoutDefaultsToSessionTimeoutV0() {
    int sessionTimeoutMs = 30000;
    short version = 0;
    ByteBuffer buffer = MessageUtil.toByteBuffer(new JoinGroupRequestData().setGroupId("groupId").setMemberId("consumerId").setProtocolType("consumer").setSessionTimeoutMs(sessionTimeoutMs), version);
    JoinGroupRequest request = JoinGroupRequest.parse(buffer, version);
    assertEquals(sessionTimeoutMs, request.data().sessionTimeoutMs());
    assertEquals(sessionTimeoutMs, request.data().rebalanceTimeoutMs());
}
Also used : ByteBuffer(java.nio.ByteBuffer) JoinGroupRequestData(org.apache.kafka.common.message.JoinGroupRequestData) Test(org.junit.jupiter.api.Test)

Example 4 with JoinGroupRequestData

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

the class AbstractCoordinatorTest method expectJoinGroup.

private void expectJoinGroup(String expectedMemberId, String expectedReason, int responseGeneration, String responseMemberId) {
    JoinGroupResponse response = joinGroupFollowerResponse(responseGeneration, responseMemberId, "leaderId", Errors.NONE, PROTOCOL_TYPE);
    mockClient.prepareResponse(body -> {
        if (!(body instanceof JoinGroupRequest)) {
            return false;
        }
        JoinGroupRequestData joinGroupRequest = ((JoinGroupRequest) body).data();
        // abstract coordinator never sets reason to null
        String actualReason = joinGroupRequest.reason();
        boolean isReasonMatching = expectedReason == null || expectedReason.equals(actualReason);
        return joinGroupRequest.memberId().equals(expectedMemberId) && joinGroupRequest.protocolType().equals(PROTOCOL_TYPE) && isReasonMatching;
    }, response);
}
Also used : JoinGroupRequest(org.apache.kafka.common.requests.JoinGroupRequest) JoinGroupResponse(org.apache.kafka.common.requests.JoinGroupResponse) JoinGroupRequestData(org.apache.kafka.common.message.JoinGroupRequestData)

Aggregations

JoinGroupRequestData (org.apache.kafka.common.message.JoinGroupRequestData)4 JoinGroupRequest (org.apache.kafka.common.requests.JoinGroupRequest)2 ByteBuffer (java.nio.ByteBuffer)1 JoinGroupResponse (org.apache.kafka.common.requests.JoinGroupResponse)1 Test (org.junit.jupiter.api.Test)1