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