Search in sources :

Example 1 with CommandConnect

use of org.apache.pulsar.common.api.proto.PulsarApi.CommandConnect in project incubator-pulsar by apache.

the class Commands method newConnect.

public static ByteBuf newConnect(String authMethodName, String authData, int protocolVersion, String libVersion, String targetBroker, String originalPrincipal, String originalAuthData, String originalAuthMethod) {
    CommandConnect.Builder connectBuilder = CommandConnect.newBuilder();
    connectBuilder.setClientVersion(libVersion != null ? libVersion : "Pulsar Client");
    connectBuilder.setAuthMethodName(authMethodName);
    if ("ycav1".equals(authMethodName)) {
        // Handle the case of a client that gets updated before the broker and starts sending the string auth method
        // name. An example would be in broker-to-broker replication. We need to make sure the clients are still
        // passing both the enum and the string until all brokers are upgraded.
        connectBuilder.setAuthMethod(AuthMethod.AuthMethodYcaV1);
    }
    if (targetBroker != null) {
        // When connecting through a proxy, we need to specify which broker do we want to be proxied through
        connectBuilder.setProxyToBrokerUrl(targetBroker);
    }
    if (authData != null) {
        connectBuilder.setAuthData(copyFromUtf8(authData));
    }
    if (originalPrincipal != null) {
        connectBuilder.setOriginalPrincipal(originalPrincipal);
    }
    if (originalAuthData != null) {
        connectBuilder.setOriginalAuthData(originalAuthData);
    }
    if (originalAuthMethod != null) {
        connectBuilder.setOriginalAuthMethod(originalAuthMethod);
    }
    connectBuilder.setProtocolVersion(protocolVersion);
    CommandConnect connect = connectBuilder.build();
    ByteBuf res = serializeWithSize(BaseCommand.newBuilder().setType(Type.CONNECT).setConnect(connect));
    connect.recycle();
    connectBuilder.recycle();
    return res;
}
Also used : CommandConnect(org.apache.pulsar.common.api.proto.PulsarApi.CommandConnect) ByteBuf(io.netty.buffer.ByteBuf)

Aggregations

ByteBuf (io.netty.buffer.ByteBuf)1 CommandConnect (org.apache.pulsar.common.api.proto.PulsarApi.CommandConnect)1