public static ReadOnlySequence <byte> NewSend(long producerId, long lowestSequenceId, long highestSequenceId, int numMessages, long txnIdLeastBits, long txnIdMostBits, MessageMetadata messageData, ReadOnlySequence <byte> payload) { var send = new CommandSend { ProducerId = (ulong)producerId, SequenceId = (ulong)lowestSequenceId, HighestSequenceId = (ulong)highestSequenceId }; if (numMessages > 1) { send.NumMessages = numMessages; } if (txnIdLeastBits >= 0) { send.TxnidLeastBits = (ulong)txnIdLeastBits; } if (txnIdMostBits >= 0) { send.TxnidMostBits = (ulong)txnIdMostBits; } if (messageData.TotalChunkMsgSize > 1) { send.IsChunk = true; } var serialized = Serializer.Serialize(send.ToBaseCommand(), messageData, payload); return(new ReadOnlySequence <byte>(serialized)); }
public static ReadOnlySequence <byte> NewProducer(string topic, long producerId, long requestId, string producerName, bool encrypted, IDictionary <string, string> metadata, ISchemaInfo schemaInfo, long epoch, bool userProvidedProducerName, Common.ProducerAccessMode accessMode) { var producer = new CommandProducer { Topic = topic, ProducerId = (ulong)producerId, RequestId = (ulong)requestId, Epoch = (ulong)epoch, ProducerAccessMode = ConvertProducerAccessMode(accessMode) }; if (!ReferenceEquals(producerName, null)) { producer.ProducerName = producerName; } producer.UserProvidedProducerName = userProvidedProducerName; producer.Encrypted = encrypted; producer.Metadatas.AddRange(CommandUtils.ToKeyValueList(metadata)); if (null != schemaInfo) { producer.Schema = GetSchema(schemaInfo); } return(Serializer.Serialize(producer.ToBaseCommand())); }
public static ReadOnlySequence <byte> NewReachedEndOfTopic(long consumerId) { var reachedEndOfTopic = new CommandReachedEndOfTopic { ConsumerId = (ulong)consumerId }; return(Serializer.Serialize(reachedEndOfTopic.ToBaseCommand())); }
public static ReadOnlySequence <byte> NewActiveConsumerChange(long consumerId, bool isActive) { var change = new CommandActiveConsumerChange { ConsumerId = (ulong)consumerId, IsActive = isActive }; return(Serializer.Serialize(change.ToBaseCommand())); }
public static ReadOnlySequence <byte> NewPartitionMetadataRequest(string topic, long requestId) { var partitionMetadata = new CommandPartitionedTopicMetadata { Topic = topic, RequestId = (ulong)requestId }; return(Serializer.Serialize(partitionMetadata.ToBaseCommand())); }
public static ReadOnlySequence <byte> NewCloseProducer(long producerId, long requestId) { var closeProducer = new CommandCloseProducer { ProducerId = (ulong)producerId, RequestId = (ulong)requestId }; return(Serializer.Serialize(closeProducer.ToBaseCommand())); }
public static ReadOnlySequence <byte> NewUnsubscribe(long consumerId, long requestId) { var unsubscribe = new CommandUnsubscribe { ConsumerId = (ulong)consumerId, RequestId = (ulong)requestId }; return(Serializer.Serialize(unsubscribe.ToBaseCommand())); }
public static ReadOnlySequence <byte> NewSubscribe(string topic, string subscription, long consumerId, long requestId, CommandSubscribe.SubType subType, int priorityLevel, string consumerName, bool isDurable, MessageIdData startMessageId, IDictionary <string, string> metadata, bool readCompacted, bool isReplicated, CommandSubscribe.InitialPosition subscriptionInitialPosition, long startMessageRollbackDurationInSec, ISchemaInfo schemaInfo, bool createTopicIfDoesNotExist, KeySharedPolicy keySharedPolicy) { var subscribe = new CommandSubscribe { Topic = topic, Subscription = subscription, subType = subType, ConsumerId = (ulong)consumerId, ConsumerName = consumerName, RequestId = (ulong)requestId, PriorityLevel = priorityLevel, Durable = isDurable, ReadCompacted = readCompacted, initialPosition = subscriptionInitialPosition, ReplicateSubscriptionState = isReplicated, ForceTopicCreation = createTopicIfDoesNotExist }; if (keySharedPolicy != null) { var keySharedMeta = new KeySharedMeta { allowOutOfOrderDelivery = keySharedPolicy.AllowOutOfOrderDelivery, keySharedMode = ConvertKeySharedMode(keySharedPolicy.KeySharedMode) }; if (keySharedPolicy is KeySharedPolicy.KeySharedPolicySticky sticky) { var ranges = sticky.GetRanges().Ranges; foreach (var range in ranges) { keySharedMeta.hashRanges.Add(new IntRange { Start = range.Start, End = range.End }); } } subscribe.keySharedMeta = keySharedMeta; } if (startMessageId != null) { subscribe.StartMessageId = startMessageId; } if (startMessageRollbackDurationInSec > 0) { subscribe.StartMessageRollbackDurationSec = (ulong)startMessageRollbackDurationInSec; } subscribe.Metadatas.AddRange(CommandUtils.ToKeyValueList(metadata)); if (schemaInfo != null) { var schema = GetSchema(schemaInfo); subscribe.Schema = schema; } return(Serializer.Serialize(subscribe.ToBaseCommand())); }
public static ReadOnlySequence <byte> NewSeek(long consumerId, long requestId, long timestamp) { var seek = new CommandSeek { ConsumerId = (ulong)consumerId, RequestId = (ulong)requestId, MessagePublishTime = (ulong)timestamp }; return(Serializer.Serialize(seek.ToBaseCommand())); }
public static ReadOnlySequence <byte> NewSendError(long producerId, long sequenceId, ServerError error, string errorMsg) { var sendError = new CommandSendError { ProducerId = (ulong)producerId, SequenceId = (ulong)sequenceId, Error = error, Message = errorMsg }; return(Serializer.Serialize(sendError.ToBaseCommand())); }
public static ReadOnlySequence <byte> NewSeek(long consumerId, long requestId, long ledgerId, long entryId, long[] ackSet) { var seek = new CommandSeek { ConsumerId = (ulong)consumerId, RequestId = (ulong)requestId }; var messageId = new MessageIdData { ledgerId = (ulong)ledgerId, entryId = (ulong)entryId, AckSets = ackSet }; seek.MessageId = messageId; return(Serializer.Serialize(seek.ToBaseCommand())); }
public static ReadOnlySequence <byte> NewLookup(string topic, string listenerName, bool authoritative, long requestId) { var lookupTopic = new CommandLookupTopic { Topic = topic, RequestId = (ulong)requestId, Authoritative = authoritative }; if (!string.IsNullOrWhiteSpace(listenerName)) { lookupTopic.AdvertisedListenerName = listenerName; } return(Serializer.Serialize(lookupTopic.ToBaseCommand())); }
public static ReadOnlySequence <byte> NewAuthResponse(string authMethod, AuthData clientData, int clientProtocolVersion, string clientVersion) { var authData = new AuthData { auth_data = clientData.auth_data, AuthMethodName = authMethod }; var response = new CommandAuthResponse { Response = authData, ProtocolVersion = clientProtocolVersion, ClientVersion = clientVersion ?? "Pulsar Client" }; return(Serializer.Serialize(response.ToBaseCommand())); }
public static ReadOnlySequence <byte> NewConnect(string authMethodName, string authData, int protocolVersion, string libVersion, string targetBroker, string originalPrincipal, string originalAuthData, string originalAuthMethod) { var connect = new CommandConnect { ClientVersion = libVersion ?? "Pulsar Client", AuthMethodName = authMethodName, FeatureFlags = new FeatureFlags { SupportsAuthRefresh = true } }; 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. connect.AuthMethod = AuthMethod.AuthMethodYcaV1; } if (!ReferenceEquals(targetBroker, null)) { // When connecting through a proxy, we need to specify which broker do we want to be proxied through connect.ProxyToBrokerUrl = targetBroker; } if (!ReferenceEquals(authData, null)) { connect.AuthData = ByteString.CopyFromUtf8(authData).ToByteArray(); } if (!ReferenceEquals(originalPrincipal, null)) { connect.OriginalPrincipal = originalPrincipal; } if (!ReferenceEquals(originalAuthData, null)) { connect.OriginalAuthData = originalAuthData; } if (!ReferenceEquals(originalAuthMethod, null)) { connect.OriginalAuthMethod = originalAuthMethod; } connect.ProtocolVersion = protocolVersion; return(Serializer.Serialize(connect.ToBaseCommand())); }
public static ReadOnlySequence <byte> NewAuthChallenge(string authMethod, AuthData brokerData, int clientProtocolVersion) { var challenge = new CommandAuthChallenge(); // If the broker supports a newer version of the protocol, it will anyway advertise the max version that the // client supports, to avoid confusing the client. var versionToAdvertise = Math.Min(Enum.GetValues(typeof(ProtocolVersion)).Cast <int>().Max(), clientProtocolVersion); challenge.ProtocolVersion = versionToAdvertise; challenge.Challenge = new AuthData { auth_data = brokerData.auth_data, AuthMethodName = authMethod }; //var challenge = challenge.Challenge().Build(); return(Serializer.Serialize(challenge.ToBaseCommand())); }
public static ReadOnlySequence <byte> NewConnect(string authMethodName, AuthData authData, int protocolVersion, string libVersion, string targetBroker, string originalPrincipal, AuthData originalAuthData, string originalAuthMethod) { var connect = new CommandConnect { ClientVersion = libVersion, AuthMethodName = authMethodName, FeatureFlags = new FeatureFlags { SupportsAuthRefresh = true } }; if (!string.IsNullOrWhiteSpace(targetBroker)) { // When connecting through a proxy, we need to specify which broker do we want to be proxied through connect.ProxyToBrokerUrl = targetBroker; } if (authData != null) { connect.AuthData = authData.auth_data; } if (!string.IsNullOrWhiteSpace(originalPrincipal)) { connect.OriginalPrincipal = originalPrincipal; } if (originalAuthData != null) { connect.OriginalAuthData = Encoding.UTF8.GetString(originalAuthData.auth_data); } if (!string.IsNullOrWhiteSpace(originalAuthMethod)) { connect.OriginalAuthMethod = originalAuthMethod; } connect.ProtocolVersion = protocolVersion; var ba = connect.ToBaseCommand(); return(Serializer.Serialize(ba)); }