modify alert sql

This commit is contained in:
menshibin 2024-08-12 22:55:35 +08:00
parent 9ae084ee6e
commit b9165de6b2
2 changed files with 16 additions and 14 deletions

View File

@ -142,17 +142,17 @@ def seek_offset(consumer):
raise err
# ANCHOR_END: assignment
# ANCHOR: unsubscribe
def unsubscribe(consumer):
# ANCHOR: unsubscribe
try:
consumer.unsubscribe()
print("Consumer unsubscribed successfully.");
except Exception as err:
print(f"Failed to unsubscribe consumer. ErrMessage:{err}")
# ANCHOR_END: unsubscribe
finally:
if consumer:
consumer.close()
# ANCHOR_END: unsubscribe
if __name__ == "__main__":
consumer = None
@ -162,9 +162,10 @@ if __name__ == "__main__":
subscribe(consumer)
seek_offset(consumer)
commit_offset(consumer)
unsubscribe(consumer)
consumer.unsubscribe()
print("Consumer unsubscribed successfully.");
except Exception as err:
print(f"Failed to stmt consumer. ErrMessage:{err}")
finally:
if consumer:
consumer.close()
consumer.unsubscribe()

View File

@ -143,14 +143,17 @@ def commit_offset(consumer):
# ANCHOR_END: commit_offset
#
# ANCHOR: unsubscribe
def unsubscribe(consumer):
# ANCHOR: unsubscribe
try:
consumer.unsubscribe()
print("Consumer unsubscribed successfully.");
except Exception as err:
print(f"Failed to unsubscribe consumer. ErrMessage:{err}")
finally:
if consumer:
consumer.close()
# ANCHOR_END: unsubscribe
@ -161,10 +164,8 @@ if __name__ == "__main__":
consumer = create_consumer()
subscribe(consumer)
seek_offset(consumer)
commit_offset(consumer)
unsubscribe(consumer)
commit_offset(consumer)
except Exception as err:
print(f"Failed to stmt consumer. ErrorMessage:{err}")
finally:
if consumer:
consumer.close()
unsubscribe(consumer);