/// <summary> /// /// </summary> /// <param name="msg"></param> /// <returns></returns> public static bool SafeAbandon(this BrokeredMessage msg) { try { msg.Abandon(); return true; } catch (MessageLockLostException) { // It's too late to compensate the loss of a message lock. We should just ignore it so that it does not break the receive loop. } catch (MessagingException) { // There is nothing we can do as the connection may have been lost, or the underlying queue may have been removed. // If Abandon() fails with this exception, the only recourse is to receive another message. } catch (ObjectDisposedException) { // There is nothing we can do as the object has already been disposed elsewhere } catch (TransactionException) { // } catch (TimeoutException) { // took to long } return false; }
public static bool TryAbandon(this BrokeredMessage msg) { try { // Abandons a brokered message. This will cause the Service Bus to // unlock the message and make it available to be received again, // either by the same consumer or by another competing consumer. msg.Abandon(); // Return a result indicating that the message has been abandoned successfully. return true; } catch (MessageLockLostException) { // It's too late to compensate the loss of a message lock. // We should just ignore it so that it does not break the receive loop. // We should be prepared to receive the same message again. } catch (MessagingException) { // There is nothing we can do as the connection may have been lost, // or the underlying topic/subscription may have been removed. // If Abandon() fails with this exception, the only recourse is to receive another message (possibly the same one). } return false; }
public static Domain.Repository.Pessoas GetLoggedUser(this HttpSessionStateBase session) { Domain.Repository.Pessoas user = null; if (session["LoggedUser"] == null) { FormsAuthentication.SignOut(); session.Abandon(); //HttpContext.Current.Response.Redirect("/Authentication/"); } else { string json = session["LoggedUser"].ToString(); user = JsonConvert.DeserializeObject<Domain.Repository.Pessoas>(json); } return user; }
public static bool SafeAbandon(this BrokeredMessage msg) { try { msg.Abandon(); return true; } catch (MessageLockLostException ex) { // It's too late to compensate the loss of a message lock. We should just ignore it so that it does not break the receive loop. Log.Warn(string.Format("A message lock lost exception occured while trying to abandon a message, you may consider to increase the lock duration or reduce the batch size, the exception was {0}", ex.Message), ex); } catch (MessagingException ex) { // There is nothing we can do as the connection may have been lost, or the underlying queue may have been removed. // If Abandon() fails with this exception, the only recourse is to receive another message. Log.Warn(string.Format("A messaging exception occured while trying to abandon a message, this might imply that the connection was lost or the underlying queue got removed, the exception was {0}", ex.Message), ex); } catch (ObjectDisposedException ex) { // There is nothing we can do as the object has already been disposed elsewhere Log.Warn(string.Format("An object disposed exception occured while trying to abandon a message, this might imply that the connection was lost or the underlying queue got removed, the exception was {0}", ex.Message), ex); } catch (TransactionException ex) { // ASB Sdk beat us to it Log.Warn(string.Format("A transaction exception occured while trying to abandon a message, this probably means that the Azure ServiceBus SDK has rolled back the transaction already, the exception was {0}", ex.Message), ex); } catch (TimeoutException ex) { // took to long Log.Warn(string.Format("A timeout exception occured while trying to abandon a message, the exception was {0}", ex.Message), ex); } return false; }