BewareMyPower commented on code in PR #109: URL: https://github.com/apache/pulsar-client-python/pull/109#discussion_r1209658709
########## pulsar/__init__.py: ########## @@ -1447,6 +1456,73 @@ def policy(self): """ return self._policy +class ConsumerKeySharedPolicy: + """ + Consumer key shared policy is used to configure the consumer behaviour when the ConsumerType is KeyShared. + """ + def __init__( + self, + key_shared_mode: KeySharedMode = KeySharedMode.AutoSplit, + allow_out_of_order_delivery: bool = False, + sticky_ranges: Optional[List[Tuple[int, int]]] = None, + ): + """ + Wrapper KeySharedPolicy. + + Parameters + ---------- + + key_shared_mode: KeySharedMode, optional + Set the key shared mode. eg: KeySharedMode.Sticky or KeysharedMode.AutoSplit + + allow_out_of_order_delivery: bool, optional + Set whether to allow for out of order delivery + If it is enabled, it relaxes the ordering requirement and allows the broker to send out-of-order + messages in case of failures. This makes it faster for new consumers to join without being stalled by + an existing slow consumer. + + If this is True, a single consumer still receives all keys, but they may come in different orders. + + sticky_ranges: List[Tuple[int, int]], optional + Set the ranges used with sticky mode. The integers can be from 0 to 2^16 (0 <= val < 65,536) + """ + if key_shared_mode == KeySharedMode.Sticky and sticky_ranges is None: + raise ValueError("When using key_shared_mode = KeySharedMode.Sticky you must also provide sticky_ranges") + + self._policy = KeySharedPolicy() + self._policy.set_key_shared_mode(key_shared_mode) + self._policy.set_allow_out_of_order_delivery(allow_out_of_order_delivery) + + if sticky_ranges is not None: + self._policy.set_sticky_ranges(sticky_ranges) + + @property + def key_shared_mode(self) -> KeySharedMode: + """ + Returns the key shared mode + """ + return self._policy.get_key_shared_mode() + + @property + def allow_out_of_order_delivery(self) -> bool: + """ + Returns whether out of order delivery is enabled + """ + return self._policy.is_allow_out_of_order_delivery() + + @property + def sticky_ranges(self) -> List[Tuple[int, int]]: + """ + Returns the actual sticky ranges + """ + return self._policy.get_sticky_ranges() + + def policy(self): + """ + Returns the actual KeySharedPolicy. + """ + return self._policy Review Comment: Resolve it since the batch receive policy also exposes it. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@pulsar.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org