public void should_serialize_details() { var details = new { foo = "bar", baz = 42 }; var message = new CustomProcessingFailed(typeof(CustomProcessingFailedTests).FullName, "Error").WithDetails(details); var deserializedDetails = JsonConvert.DeserializeAnonymousType(message.DetailsJson, details); deserializedDetails.ShouldEqual(details); }
private void HandleDispatchErrorsForUnserializableMessage(IMessage message, Exception serializationException, string dispatchErrorMessage) { var messageTypeName = message.GetType().FullName; _logger.Error($"Unable to serialize message {messageTypeName}. Error: {serializationException}"); if (!_configuration.IsErrorPublicationEnabled || !IsRunning) { return; } var errorMessage = $"Unable to handle local message\r\nMessage is not serializable\r\nMessageType: {messageTypeName}\r\nDispatch error: {dispatchErrorMessage}\r\nSerialization error: {serializationException}"; var processingFailed = new CustomProcessingFailed(GetType().FullName, errorMessage, SystemDateTime.UtcNow); Publish(processingFailed); }
private IMessage ToMessage(MessageTypeId messageTypeId, byte[] messageBytes, OriginatorInfo originator) { try { return(_serializer.Deserialize(messageTypeId, messageBytes)); } catch (Exception exception) { var dumpLocation = DumpMessageOnDisk(messageTypeId, messageBytes); var errorMessage = string.Format("Unable to deserialize message {0}. Originator: {1}. Message dumped at: {2}\r\n{3}", messageTypeId.FullName, originator.SenderId, dumpLocation, exception); _logger.Error(errorMessage); var processingFailed = new CustomProcessingFailed(GetType().FullName, errorMessage, SystemDateTime.UtcNow); Publish(processingFailed); } return(null); }
public void should_send_CustomMessageProcessingFailed_if_unable_to_deserialize_message() { using (MessageId.PauseIdGeneration()) { SetupPeersHandlingMessage <CustomProcessingFailed>(_peerUp); var serializerMock = new Mock <IMessageSerializer>(); serializerMock.Setup(serializer => serializer.Deserialize(It.IsAny <MessageTypeId>(), It.IsAny <byte[]>())) .Throws(new Exception("message")); var bus = new Bus(_transport, _directoryMock.Object, serializerMock.Object, _messageDispatcherMock.Object, new DefaultStoppingStrategy()); bus.Configure(_self.Id, "test"); var command = new FakeCommand(123); var transportMessage = command.ToTransportMessage(); _transport.RaiseMessageReceived(transportMessage); var processingFailed = new CustomProcessingFailed(typeof(Bus).FullName, "message", SystemDateTime.UtcNow); var processingFailedTransportMessage = new TransportMessage(processingFailed.TypeId(), new byte[0], _self); _transport.ExpectExactly(new TransportMessageSent(processingFailedTransportMessage, _peerUp)); } }