@@ -146,6 +146,12 @@ def partition_key(self):
146146 """
147147 return self ._message .partition_key ()
148148
149+ def ordering_key (self ):
150+ """
151+ Get the ordering key for the message.
152+ """
153+ return self ._message .ordering_key ()
154+
149155 def publish_timestamp (self ):
150156 """
151157 Get the timestamp in milliseconds with the message publish time.
@@ -1020,7 +1026,7 @@ def my_listener(reader, message):
10201026 Symmetric encryption class implementation, configuring public key encryption messages for the producer
10211027 and private key decryption messages for the consumer
10221028 """
1023-
1029+
10241030 # If a pulsar.MessageId object is passed, access the _pulsar.MessageId object
10251031 if isinstance (start_message_id , MessageId ):
10261032 start_message_id = start_message_id ._msg_id
@@ -1142,6 +1148,7 @@ def last_sequence_id(self):
11421148 def send (self , content ,
11431149 properties = None ,
11441150 partition_key = None ,
1151+ ordering_key = None ,
11451152 sequence_id = None ,
11461153 replication_clusters = None ,
11471154 disable_replication = False ,
@@ -1164,6 +1171,8 @@ def send(self, content,
11641171 partition_key: optional
11651172 Sets the partition key for message routing. A hash of this key is used
11661173 to determine the message's topic partition.
1174+ ordering_key: optional
1175+ Sets the ordering key for message routing.
11671176 sequence_id: optional
11681177 Specify a custom sequence id for the message being published.
11691178 replication_clusters: optional
@@ -1180,14 +1189,15 @@ def send(self, content,
11801189 deliver_after: optional
11811190 Specify a delay in timedelta for the delivery of the messages.
11821191 """
1183- msg = self ._build_msg (content , properties , partition_key , sequence_id ,
1192+ msg = self ._build_msg (content , properties , partition_key , ordering_key , sequence_id ,
11841193 replication_clusters , disable_replication , event_timestamp ,
11851194 deliver_at , deliver_after )
11861195 return self ._producer .send (msg )
11871196
11881197 def send_async (self , content , callback ,
11891198 properties = None ,
11901199 partition_key = None ,
1200+ ordering_key = None ,
11911201 sequence_id = None ,
11921202 replication_clusters = None ,
11931203 disable_replication = False ,
@@ -1239,6 +1249,8 @@ def callback(res, msg_id):
12391249 partition_key: optional
12401250 Sets the partition key for the message routing. A hash of this key is
12411251 used to determine the message's topic partition.
1252+ ordering_key: optional
1253+ Sets the ordering key for the message routing.
12421254 sequence_id: optional
12431255 Specify a custom sequence id for the message being published.
12441256 replication_clusters: optional
@@ -1254,7 +1266,7 @@ def callback(res, msg_id):
12541266 deliver_after: optional
12551267 Specify a delay in timedelta for the delivery of the messages.
12561268 """
1257- msg = self ._build_msg (content , properties , partition_key , sequence_id ,
1269+ msg = self ._build_msg (content , properties , partition_key , ordering_key , sequence_id ,
12581270 replication_clusters , disable_replication , event_timestamp ,
12591271 deliver_at , deliver_after )
12601272 self ._producer .send_async (msg , callback )
@@ -1274,14 +1286,15 @@ def close(self):
12741286 """
12751287 self ._producer .close ()
12761288
1277- def _build_msg (self , content , properties , partition_key , sequence_id ,
1289+ def _build_msg (self , content , properties , partition_key , ordering_key , sequence_id ,
12781290 replication_clusters , disable_replication , event_timestamp ,
12791291 deliver_at , deliver_after ):
12801292 data = self ._schema .encode (content )
12811293
12821294 _check_type (bytes , data , 'data' )
12831295 _check_type_or_none (dict , properties , 'properties' )
12841296 _check_type_or_none (str , partition_key , 'partition_key' )
1297+ _check_type_or_none (str , ordering_key , 'ordering_key' )
12851298 _check_type_or_none (int , sequence_id , 'sequence_id' )
12861299 _check_type_or_none (list , replication_clusters , 'replication_clusters' )
12871300 _check_type (bool , disable_replication , 'disable_replication' )
@@ -1296,6 +1309,8 @@ def _build_msg(self, content, properties, partition_key, sequence_id,
12961309 mb .property (k , v )
12971310 if partition_key :
12981311 mb .partition_key (partition_key )
1312+ if ordering_key :
1313+ mb .ordering_key (ordering_key )
12991314 if sequence_id :
13001315 mb .sequence_id (sequence_id )
13011316 if replication_clusters :
0 commit comments