support specifying message size in emc config

This commit is contained in:
Timothy Pogue 2022-09-13 16:39:53 -06:00
parent d75d5a7dad
commit 06350a13cb
2 changed files with 10 additions and 1 deletions

View File

@ -511,6 +511,12 @@ CONF_SCHEMA = {
'minimum': 0,
'maximum': 1500,
'default': 1500
},
'max_message_size': {
'type': 'integer',
'minimum': 1048576, # 1mb
'maxmium': 8388608, # 8.3mb,
'default': 1048576, # 1mb
}
},
'required': ['producers']

View File

@ -67,6 +67,9 @@ class ExternalMessageConsumer:
# The amount of candles per dataframe on the initial request
self.initial_candle_limit = self._emc_config.get('initial_candle_limit', 1500)
# Message size limit, default 1mb
self.message_size_limit = self._emc_config.get('message_size_limit', 2**20)
# Setting these explicitly as they probably shouldn't be changed by a user
# Unless we somehow integrate this with the strategy to allow creating
# callbacks for the messages
@ -175,7 +178,7 @@ class ExternalMessageConsumer:
ws_url = f"{url}?token={token}"
# This will raise InvalidURI if the url is bad
async with websockets.connect(ws_url) as ws:
async with websockets.connect(ws_url, max_size=self.message_size_limit) as ws:
channel = WebSocketChannel(ws, channel_id=name)
logger.info(f"Producer connection success - {channel}")