don't let every single possible client explode just because one malformed message was seen

This commit is contained in:
Adam R Grey 2022-12-14 17:09:28 -05:00
parent 013e4079c3
commit d79ba3671b

View File

@ -37,24 +37,27 @@ namespace franz
while (!token.IsCancellationRequested)
{
var cr = topicConsumer.Consume();
try{
var deserialized = JsonConvert.DeserializeObject(cr.Message.Value, messageType);
if (deserialized != null && (deserialized as gray_messages.message).type == deserialized.GetType().ToString())
{
foreach (var waitingAction in externalSubscribers)
{
try
{
waitingAction(deserialized);
}
}
}
catch(JsonSerializationException jse)
{
Console.Error.WriteLine($"couldn't deserialize {cr?.Message?.Value} as {messageType}; {jse}");
}
catch (Exception e)
{
Console.Error.WriteLine("if I don't catch this error the whole thing dies so...");
Console.Error.WriteLine("something happened in an action handler for: ");
Console.Error.WriteLine(JsonConvert.SerializeObject(e));
}
}
}
}
}
finally
{
topicConsumer.Close();