当前位置: 首页>>代码示例>>Java>>正文


Java ApiKeys.API_VERSIONS属性代码示例

本文整理汇总了Java中org.apache.kafka.common.protocol.ApiKeys.API_VERSIONS属性的典型用法代码示例。如果您正苦于以下问题:Java ApiKeys.API_VERSIONS属性的具体用法?Java ApiKeys.API_VERSIONS怎么用?Java ApiKeys.API_VERSIONS使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在org.apache.kafka.common.protocol.ApiKeys的用法示例。


在下文中一共展示了ApiKeys.API_VERSIONS属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handleKafkaRequest

private boolean handleKafkaRequest(byte[] requestBytes) throws IOException, AuthenticationException {
    boolean isKafkaRequest = false;
    String clientMechanism = null;
    try {
        ByteBuffer requestBuffer = ByteBuffer.wrap(requestBytes);
        RequestHeader requestHeader = RequestHeader.parse(requestBuffer);
        ApiKeys apiKey = ApiKeys.forId(requestHeader.apiKey());
        // A valid Kafka request header was received. SASL authentication tokens are now expected only
        // following a SaslHandshakeRequest since this is not a GSSAPI client token from a Kafka 0.9.0.x client.

        // 状态切换
        setSaslState(SaslState.HANDSHAKE_REQUEST);
        isKafkaRequest = true;
        // 检测apikye、version是否合法

        if (!Protocol.apiVersionSupported(requestHeader.apiKey(), requestHeader.apiVersion())) {
            if (apiKey == ApiKeys.API_VERSIONS)
                sendKafkaResponse(ApiVersionsResponse.unsupportedVersionSend(node, requestHeader));
            else
                throw new UnsupportedVersionException("Version " + requestHeader.apiVersion() + " is not supported for apiKey " + apiKey);
        } else {
            AbstractRequest request = AbstractRequest.getRequest(requestHeader.apiKey(), requestHeader.apiVersion(),
                    requestBuffer).request;

            LOG.debug("Handle Kafka request {}", apiKey);
            switch (apiKey) {
                case API_VERSIONS:
                    handleApiVersionsRequest(requestHeader);
                    break;
                case SASL_HANDSHAKE:
                    clientMechanism = handleHandshakeRequest(requestHeader, (SaslHandshakeRequest) request);
                    break;
                default:
                    throw new IllegalSaslStateException("Unexpected Kafka request of type " + apiKey + " during SASL handshake.");
            }
        }
    } catch (SchemaException | IllegalArgumentException e) {
        if (saslState == SaslState.GSSAPI_OR_HANDSHAKE_REQUEST) {
            // SchemaException is thrown if the request is not in Kafka format. IllegalArgumentException is thrown
            // if the API key is invalid. For compatibility with 0.9.0.x where the first packet is a GSSAPI token
            // starting with 0x60, revert to GSSAPI for both these exceptions.
            if (LOG.isDebugEnabled()) {
                StringBuilder tokenBuilder = new StringBuilder();
                for (byte b : requestBytes) {
                    tokenBuilder.append(String.format("%02x", b));
                    if (tokenBuilder.length() >= 20)
                         break;
                }
                LOG.debug("Received client packet of length {} starting with bytes 0x{}, process as GSSAPI packet", requestBytes.length, tokenBuilder);
            }
            if (enabledMechanisms.contains(SaslConfigs.GSSAPI_MECHANISM)) {
                LOG.debug("First client packet is not a SASL mechanism request, using default mechanism GSSAPI");
                clientMechanism = SaslConfigs.GSSAPI_MECHANISM;
            } else
                throw new UnsupportedSaslMechanismException("Exception handling first SASL packet from client, GSSAPI is not supported by server", e);
        } else
            throw e;
    }
    if (clientMechanism != null) {
        // sasl机制检测通过,创建PlainSaslServer
        createSaslServer(clientMechanism);
        setSaslState(SaslState.AUTHENTICATE);
    }
    return isKafkaRequest;
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:65,代码来源:SaslServerAuthenticator.java

示例2: Builder

public Builder() {
    super(ApiKeys.API_VERSIONS);
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:3,代码来源:ApiVersionsRequest.java


注:本文中的org.apache.kafka.common.protocol.ApiKeys.API_VERSIONS属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。