private bool CheckTypeName(string typeName, BrokeredMessage msg) { if (typeName != null) { return(true); } _logger.Write(LogLevel.Error, "Received message is not a AzureCommandBus message ('PayloadTypeName' property is missing)."); var e = new BusMessageErrorEventArgs(msg, new UnknownMessageException( "Received message is not a AzureCommandBus message ('PayloadTypeName' property is missing).")); BusFailed(this, e); if (e.MessageTask == MessageHandling.PutMessageBackInQueue) { msg.Abandon(); } else { msg.Complete(); } return(false); }
private void OnMessage(IAsyncResult ar) { BrokeredMessage brokeredMessage = null; try { brokeredMessage = _queueClient.EndReceive(ar); if (brokeredMessage == null) { _logger.Write(LogLevel.Debug, "Received null message (i.e. the Azure ServiceBus library completed the async op without receiving a message)"); ReceiveMessage(); return; } var typeName = (string) brokeredMessage.Properties[MessageProperties.PayloadTypeName]; if (!CheckTypeName(typeName, brokeredMessage)) { ReceiveMessage(); return; } var type = Type.GetType(typeName, false); if (!CheckMessageType(type, brokeredMessage, typeName)) { ReceiveMessage(); return; } var method = _genericMethod.MakeGenericMethod(type); method.Invoke(this, new object[] {brokeredMessage}); brokeredMessage.Complete(); } catch (Exception exception) { _logger.Write(LogLevel.Error, "Failed to process " + brokeredMessage, exception); var targetInvoke = exception as TargetInvocationException; if (targetInvoke != null) { exception = exception.InnerException; } var e = new BusMessageErrorEventArgs(brokeredMessage, exception); CommandBusFailed(this, e); if (brokeredMessage != null) { if (e.MessageTask == MessageHandling.RemoveMessage) { brokeredMessage.Complete(); } else { brokeredMessage.Abandon(); } } } ReceiveMessage(); }
private void ReceiveMessage(BrokeredMessage brokeredMessage) { try { _queueClient.BeginReceive(OnMessage, null); } catch (Exception exception) { _logger.Write(LogLevel.Error, "Failed to start BeginReceive again.", exception); var e = new BusMessageErrorEventArgs(brokeredMessage, new FatalBusException(exception)); BusFailed(this, e); } }
private void ReceiveMessage() { try { _queueClient.BeginReceive(OnMessage, null); } catch (Exception exception) { _logger.Write(LogLevel.Error, "Failed to invoke BeginReceive", exception); var e = new BusMessageErrorEventArgs(null, new FatalBusException(exception)); CommandBusFailed(this, e); } }
private bool CheckTypeName(string typeName, BrokeredMessage msg) { if (typeName != null) return true; var e = new BusMessageErrorEventArgs(msg, new UnknownMessageException( "Received message is not a AzureCommandBus message ('PayloadTypeName' property is missing).")); CommandBusFailed(this, e); if (e.MessageTask == MessageHandling.PutMessageBackInQueue) msg.Abandon(); else msg.Complete(); return false; }
private bool CheckMessageType(Type type, BrokeredMessage msg, string typeName) { if (type != null) return true; var e = new BusMessageErrorEventArgs(msg, new UnknownMessageException( "Failed to load the Type object for '" + typeName + "'.")); CommandBusFailed(this, e); if (e.MessageTask == MessageHandling.PutMessageBackInQueue) msg.Abandon(); else msg.Complete(); return false; }