Skip to content

Commit

Permalink
Changed compression level to constant
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakub Drobena committed Nov 8, 2023
1 parent 6543378 commit 58cf03c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions ccx_messaging/publishers/kafka_publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from ccx_messaging.error import CCXMessagingError

log = logging.getLogger(__name__)
DEFAULT_COMPRESSION = 9
BEST_COMPRESSION = 9

class KafkaPublisher(Publisher):
"""
Expand Down Expand Up @@ -70,7 +70,7 @@ def __init__(self, outgoing_topic: str, kafka_broker_config: dict = None, **kwar
def produce(self, outgoing_message: bytes):
"""Send the message though the Kafka producer."""
if self.compression:
self.producer.produce(self.topic, gzip.compress(outgoing_message,compresslevel=DEFAULT_COMPRESSION))
self.producer.produce(self.topic, gzip.compress(outgoing_message,compresslevel=BEST_COMPRESSION))
else:
self.producer.produce(self.topic, outgoing_message)
self.producer.poll(0)
Expand Down
4 changes: 2 additions & 2 deletions test/publishers/kafka_publisher_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
}
),
]
DEFAULT_COMPRESSION = 9
BEST_COMPRESSION = 9

def test_init():
"""Check that init creates a valid object."""
Expand All @@ -126,7 +126,7 @@ def test_init_compression():
@pytest.mark.parametrize("input", VALID_INPUT_MSG)
def test_compressing_enabled(input):
input = bytes(json.dumps(input) + "\n",'utf-8')
expected_output = gzip.compress(input,compresslevel=DEFAULT_COMPRESSION)
expected_output = gzip.compress(input,compresslevel=BEST_COMPRESSION)
kakfa_config = {
"bootstrap.servers": "kafka:9092",
"compression" : "gzip"
Expand Down

0 comments on commit 58cf03c

Please sign in to comment.