49
49
50
50
from _pulsar import Result , CompressionType , ConsumerType , InitialPosition , PartitionsRoutingMode , BatchingType , \
51
51
LoggerLevel , BatchReceivePolicy , KeySharedPolicy , KeySharedMode , ProducerAccessMode , RegexSubscriptionMode , \
52
- DeadLetterPolicyBuilder # noqa: F401
52
+ DeadLetterPolicyBuilder , ConsumerCryptoFailureAction # noqa: F401
53
53
54
54
from pulsar .__about__ import __version__
55
55
@@ -876,6 +876,7 @@ def subscribe(self, topic, subscription_name,
876
876
batch_index_ack_enabled = False ,
877
877
regex_subscription_mode : RegexSubscriptionMode = RegexSubscriptionMode .PersistentOnly ,
878
878
dead_letter_policy : Union [None , ConsumerDeadLetterPolicy ] = None ,
879
+ crypto_failure_action : ConsumerCryptoFailureAction = ConsumerCryptoFailureAction .FAIL ,
879
880
):
880
881
"""
881
882
Subscribe to the given topic and subscription combination.
@@ -979,6 +980,19 @@ def my_listener(consumer, message):
979
980
stopped. By using the dead letter mechanism, messages have the max redelivery count, when they're
980
981
exceeding the maximum number of redeliveries. Messages are sent to dead letter topics and acknowledged
981
982
automatically.
983
+ crypto_failure_action: ConsumerCryptoFailureAction, default=ConsumerCryptoFailureAction.FAIL
984
+ Set the behavior when the decryption fails. The default is to fail the message.
985
+
986
+ Supported actions:
987
+
988
+ * ConsumerCryptoFailureAction.FAIL: Fail consume until crypto succeeds
989
+ * ConsumerCryptoFailureAction.DISCARD:
990
+ Message is silently acknowledged and not delivered to the application.
991
+ * ConsumerCryptoFailureAction.CONSUME:
992
+ Deliver the encrypted message to the application. It's the application's responsibility
993
+ to decrypt the message. If message is also compressed, decompression will fail. If the
994
+ message contains batch messages, client will not be able to retrieve individual messages
995
+ in the batch.
982
996
"""
983
997
_check_type (str , subscription_name , 'subscription_name' )
984
998
_check_type (ConsumerType , consumer_type , 'consumer_type' )
@@ -1002,6 +1016,7 @@ def my_listener(consumer, message):
1002
1016
_check_type_or_none (ConsumerKeySharedPolicy , key_shared_policy , 'key_shared_policy' )
1003
1017
_check_type (bool , batch_index_ack_enabled , 'batch_index_ack_enabled' )
1004
1018
_check_type (RegexSubscriptionMode , regex_subscription_mode , 'regex_subscription_mode' )
1019
+ _check_type (ConsumerCryptoFailureAction , crypto_failure_action , 'crypto_failure_action' )
1005
1020
1006
1021
conf = _pulsar .ConsumerConfiguration ()
1007
1022
conf .consumer_type (consumer_type )
@@ -1040,6 +1055,7 @@ def my_listener(consumer, message):
1040
1055
conf .batch_index_ack_enabled (batch_index_ack_enabled )
1041
1056
if dead_letter_policy :
1042
1057
conf .dead_letter_policy (dead_letter_policy .policy ())
1058
+ conf .crypto_failure_action (crypto_failure_action )
1043
1059
1044
1060
c = Consumer ()
1045
1061
if isinstance (topic , str ):
@@ -1068,7 +1084,8 @@ def create_reader(self, topic, start_message_id,
1068
1084
subscription_role_prefix = None ,
1069
1085
is_read_compacted = False ,
1070
1086
crypto_key_reader : Union [None , CryptoKeyReader ] = None ,
1071
- start_message_id_inclusive = False
1087
+ start_message_id_inclusive = False ,
1088
+ crypto_failure_action : ConsumerCryptoFailureAction = ConsumerCryptoFailureAction .FAIL ,
1072
1089
):
1073
1090
"""
1074
1091
Create a reader on a particular topic
@@ -1129,6 +1146,19 @@ def my_listener(reader, message):
1129
1146
and private key decryption messages for the consumer
1130
1147
start_message_id_inclusive: bool, default=False
1131
1148
Set the reader to include the startMessageId or given position of any reset operation like Reader.seek
1149
+ crypto_failure_action: ConsumerCryptoFailureAction, default=ConsumerCryptoFailureAction.FAIL
1150
+ Set the behavior when the decryption fails. The default is to fail the message.
1151
+
1152
+ Supported actions:
1153
+
1154
+ * ConsumerCryptoFailureAction.FAIL: Fail consume until crypto succeeds
1155
+ * ConsumerCryptoFailureAction.DISCARD:
1156
+ Message is silently acknowledged and not delivered to the application.
1157
+ * ConsumerCryptoFailureAction.CONSUME:
1158
+ Deliver the encrypted message to the application. It's the application's responsibility
1159
+ to decrypt the message. If message is also compressed, decompression will fail. If the
1160
+ message contains batch messages, client will not be able to retrieve individual messages
1161
+ in the batch.
1132
1162
"""
1133
1163
1134
1164
# If a pulsar.MessageId object is passed, access the _pulsar.MessageId object
@@ -1144,6 +1174,7 @@ def my_listener(reader, message):
1144
1174
_check_type (bool , is_read_compacted , 'is_read_compacted' )
1145
1175
_check_type_or_none (CryptoKeyReader , crypto_key_reader , 'crypto_key_reader' )
1146
1176
_check_type (bool , start_message_id_inclusive , 'start_message_id_inclusive' )
1177
+ _check_type (ConsumerCryptoFailureAction , crypto_failure_action , 'crypto_failure_action' )
1147
1178
1148
1179
conf = _pulsar .ReaderConfiguration ()
1149
1180
if reader_listener :
@@ -1158,6 +1189,7 @@ def my_listener(reader, message):
1158
1189
if crypto_key_reader :
1159
1190
conf .crypto_key_reader (crypto_key_reader .cryptoKeyReader )
1160
1191
conf .start_message_id_inclusive (start_message_id_inclusive )
1192
+ conf .crypto_failure_action (crypto_failure_action )
1161
1193
1162
1194
c = Reader ()
1163
1195
c ._reader = self ._client .create_reader (topic , start_message_id , conf )
0 commit comments