private bool Transport_OnMessageArrived(CurrentMessageInformation information) { var info = (RhinoFileCurrentMessageInformation)information; ErrorCounter val = null; _failureCounts.Read(reader => reader.TryGetValue(info.TransportMessageId, out val)); if (val == null || val.FailureCount < _numberOfRetries) return false; var result = false; _failureCounts.Write(writer => { if (!writer.TryGetValue(info.TransportMessageId, out val)) return; info.Queue.MoveTo(SubQueue.Errors.ToString(), info.TransportMessage); info.Queue.EnqueueDirectlyTo(SubQueue.Errors.ToString(), new MessagePayload { Data = (val.ExceptionText == null ? null : Encoding.Unicode.GetBytes(val.ExceptionText)), Headers = { {"correlation-id", info.TransportMessageId}, {"retries", val.FailureCount.ToString()} } }); result = true; }); return result; }
private void TransportOnMessageSent(CurrentMessageInformation currentMessageInformation) { var containsNonCachableMessages = currentMessageInformation.AllMessages.Any(x=>x is ICacheableRequest == false); var cacheableRequests = currentMessageInformation.AllMessages.OfType<ICacheableRequest>(); if(containsNonCachableMessages) { // since we are making a non cachable request, the // _cachable_ requests part of this batch are likely to be // affected by this message, so we go ahead and expire them // to avoid showing incorrect data foreach (var cachableRequestToExpire in cacheableRequests) { cache.Remove(cachableRequestToExpire.Key); } return; } var responses = from msg in cacheableRequests let response = cache.Get(msg.Key) where response != null select response.Value; var array = responses.ToArray(); if (array.Length == 0) return; bus.ConsumeMessages(array); }
public bool RaiseAdministrativeMessageArrived(CurrentMessageInformation information) { var copy = AdministrativeMessageArrived; if (copy != null) return copy(information); return false; }
private static void TransportMessageProcessingCompleted(CurrentMessageInformation arg1, Exception arg2) { messageArrived = false; if (session == null) return; session.Dispose(); session = null; }
private void Transport_OnMessageSerializationException(CurrentMessageInformation information, Exception exception) { failureCounts.Write(writer => writer.Add(information.MessageId, new ErrorCounter { FailureCount = numberOfRetries + 1, ExceptionText = exception.ToString() })); }
private void Transport_OnMessageSerializationException(CurrentMessageInformation info, Exception t) { Send(new SerializationErrorMessage { MessageId = info.MessageId, Error = t.ToString(), Source = info.Source, }); }
public MessageHandlingCompletion(TransactionScope tx, Action sendMessageBackToQueue, Exception exception, Action<CurrentMessageInformation, Exception> messageCompleted, Action<CurrentMessageInformation> beforeTransactionCommit, ILog logger, Action<CurrentMessageInformation, Exception> messageProcessingFailure, CurrentMessageInformation currentMessageInformation) { this.tx = tx; this.sendMessageBackToQueue = sendMessageBackToQueue; this.exception = exception; this.messageCompleted = messageCompleted; this.beforeTransactionCommit = beforeTransactionCommit; this.logger = logger; this.messageProcessingFailure = messageProcessingFailure; this.currentMessageInformation = currentMessageInformation; }
public static IDisposable Track(CurrentMessageInformation msg) { if(currentContext == null) return null; if(msg == null ) return null; var str = string.Join(", ", msg.AllMessages.Select(o => ToString(o)).ToArray()); currentContext.SetValue(null, str, null); return new DisposableAction(() => currentContext.SetValue(null, null, null)); }
private void Transport_OnMessageProcessingCompleted(CurrentMessageInformation information, Exception ex) { if (ex != null) return; ErrorCounter val = null; _failureCounts.Read(reader => reader.TryGetValue(information.TransportMessageId, out val)); if (val == null) return; _failureCounts.Write(writer => writer.Remove(information.TransportMessageId)); }
private void TransportOnMessageProcessingCompleted( CurrentMessageInformation currentMessageInformation, Exception exception) { _logger.Info("TransportOnMessageProcessingCompleted"); if (exception == null) { ErrorCounter errorCounter; _failureCounts.TryRemove(currentMessageInformation.MessageId, out errorCounter); } }
private void Transport_OnMessageProcessingCompleted(CurrentMessageInformation info, Exception ex) { var timestamp = DateTime.Now; Send(new MessageProcessingCompletedMessage { Timestamp = timestamp, Duration = timestamp - messageArrival, MessageType = info.Message.ToString(), MessageId = info.MessageId, Source = info.Source, }); }
public SqlMessageHandlingCompletion(SqlQueueManager sqlQueueManager, Action sendMessageBackToQueue, Exception exception, Action<CurrentMessageInformation, Exception> messageCompleted, Action<CurrentMessageInformation> beforeTransactionCommit, Action<CurrentMessageInformation> beforeTransactionRollback, ILog logger, Action<CurrentMessageInformation, Exception> messageProcessingFailure, CurrentMessageInformation currentMessageInformation) { this.sqlQueueManager = sqlQueueManager; this.sendMessageBackToQueue = sendMessageBackToQueue; this.exception = exception; this.messageCompleted = messageCompleted; this.beforeTransactionCommit = beforeTransactionCommit; this.beforeTransactionRollback = beforeTransactionRollback; this.logger = logger; this.messageProcessingFailure = messageProcessingFailure; this.currentMessageInformation = currentMessageInformation; }
private bool TheTransport_OnMessageArrived(CurrentMessageInformation message) { var acceptingWork = message.Message as AcceptingWork; if (acceptingWork != null) { TellLoadBalancerThatWeAreReadyToWorkForAllThreads(); return true; } return false; }
private bool TransportOnMessageArrived(CurrentMessageInformation currentMessageInformation) { var cachableResponse = currentMessageInformation.Message as ICacheableResponse; if (cachableResponse == null) return false; var alreadyInCache = cache.Get(cachableResponse.Key); if (alreadyInCache == null || alreadyInCache.Timestamp < cachableResponse.Timestamp) cache.Put(cachableResponse.Key, cachableResponse.Timestamp, cachableResponse); return false; }
bool TransportMessageArrived(CurrentMessageInformation arg) { var msg = arg.Message; bool handled = false; _routes.OfType<TransportationRoute>().Where(x => msg.GetType().CanBeCastTo(x.InputType)) .Each(x => { var arguments = new TransportationServiceArguments(msg); arguments.With<IMessageHandledNotifier>(new ActionMessageHandledNotifier(() => handled = true)); x.Invoker.Invoke(arguments, new Dictionary<string, object>()); }); return handled; }
internal void Transport_OnMessageProcessingFailure(CurrentMessageInformation info, Exception e) { string messageType = (info.Message ?? "no message").ToString(); SendInSingleTransaction(new MessageProcessingFailedMessage { ErrorText = e.ToString(), Timestamp = DateTime.Now, MessageType = messageType, MessageId = info.MessageId, Source = info.Source, Message = info.Message }); }
public object[] GatherConsumers(CurrentMessageInformation msg) { var message = msg.Message; object[] sagas = GetSagasFor(message); var sagaMessage = message as ISagaMessage; var msgType = message.GetType(); object[] instanceConsumers = subscriptionStorage .GetInstanceSubscriptions(msgType); var consumerTypes = reflection.GetGenericTypesOfWithBaseTypes(typeof(ConsumerOf <>), message); var occasionalConsumerTypes = reflection.GetGenericTypesOfWithBaseTypes(typeof(OccasionalConsumerOf <>), message); var consumers = GetAllNonOccasionalConsumers(consumerTypes, occasionalConsumerTypes, sagas); for (var i = 0; i < consumers.Length; i++) { var saga = consumers[i] as IAccessibleSaga; if (saga == null) { continue; } // if there is an existing saga, we skip the new one var type = saga.GetType(); if (sagas.Any(type.IsInstanceOfType)) { serviceLocator.Release(consumers[i]); consumers[i] = null; continue; } // we do not create new sagas if the saga is not initiated by // the message var initiatedBy = reflection.GetGenericTypeOf(typeof(InitiatedBy <>), msgType); if (initiatedBy.IsInstanceOfType(saga) == false) { serviceLocator.Release(consumers[i]); consumers[i] = null; continue; } saga.Id = sagaMessage != null ? sagaMessage.CorrelationId : GuidCombGenerator.Generate(); } return(instanceConsumers .Union(sagas) .Union(consumers.Where(x => x != null)) .ToArray()); }
private void Transport_OnMessageSent(CurrentMessageInformation info) { if (info.AllMessages.OfType<ILogMessage>().Any()) return; Send(new MessageSentMessage { MessageId = info.MessageId, Source = info.Source, Message = info.AllMessages, MessageType = info.AllMessages[0].ToString(), Timestamp = DateTime.Now, Destination = info.Destination }); }
public static bool ProcessSingleMessage( CurrentMessageInformation currentMessageInformation, Func<CurrentMessageInformation, bool> messageRecieved) { if (messageRecieved == null) return false; foreach (Func<CurrentMessageInformation, bool> func in messageRecieved.GetInvocationList()) { if (func(currentMessageInformation)) { return true; } } return false; }
public void ConsumeMessages(params object[] messages) { foreach (var message in messages) { var currentMessageInfo = new CurrentMessageInformation { AllMessages = messages, Message = message, MessageId = Guid.NewGuid(), Destination = transport.Endpoint.Uri, Source = transport.Endpoint.Uri, TransportMessageId = "ConsumeMessages" }; Transport_OnMessageArrived(currentMessageInfo); } }
private void Transport_OnMessageProcessingFailure(CurrentMessageInformation information, Exception ex) { _failureCounts.Write(writer => { ErrorCounter errorCounter; if (writer.TryGetValue(information.TransportMessageId, out errorCounter) == false) { errorCounter = new ErrorCounter { ExceptionText = (ex == null ? null : ex.ToString()), FailureCount = 0 }; writer.Add(information.TransportMessageId, errorCounter); } errorCounter.FailureCount += 1; }); }
private bool Transport_OnAdministrativeMessageArrived(CurrentMessageInformation info) { var route = info.Message as Reroute; if (route == null) { return(false); } endpointRouter.RemapEndpoint(route.OriginalEndPoint, route.NewEndPoint); var reroutedEndpoint = ReroutedEndpoint; if (reroutedEndpoint != null) { reroutedEndpoint(route); } return(true); }
private void Transport_OnMessageSerializationException(CurrentMessageInformation information, Exception exception) { var info = (SqlQueueCurrentMessageInformation) information; failureCounts.Write(writer => writer.Add(info.TransportMessageId, new ErrorCounter { ExceptionText = exception == null ? null : exception.ToString(), FailureCount = numberOfRetries + 1 })); info.Queue.MoveTo(SubQueue.Errors.ToString(), info.TransportMessage); info.Queue.EnqueueDirectlyTo(SubQueue.Errors.ToString(), new MessagePayload { Data = exception == null ? null : Encoding.Unicode.GetBytes(exception.ToString()), Headers = { {"correlation-id", info.TransportMessageId}, {"retries", "1"} } }); }
private void TransportOnMessageProcessingFailure( CurrentMessageInformation currentMessageInformation, Exception exception) { _logger.Error("TransportOnMessageProcessingFailure", exception); ErrorCounter updatedErrorCounter = _failureCounts.AddOrUpdate(currentMessageInformation.MessageId, guid => new ErrorCounter(exception.ToString(), 1), delegate(Guid guid, ErrorCounter counter) { counter.FailureCount++; return counter; }); if (updatedErrorCounter.FailureCount >= _numberOfRetries) { ErrorCounter errCounter; if (_failureCounts.TryRemove(currentMessageInformation.MessageId, out errCounter)) { _bus.SendToSelfNoThrow(new FailedToProcessMessageEvent(currentMessageInformation.TransportMessageId, currentMessageInformation.Message, updatedErrorCounter.ExceptionText)); } } }
public bool HandleAdministrativeMessage(CurrentMessageInformation msgInfo) { var addSubscription = msgInfo.Message as AddSubscription; if (addSubscription != null) { return ConsumeAddSubscription(addSubscription); } var removeSubscription = msgInfo.Message as RemoveSubscription; if (removeSubscription != null) { return ConsumeRemoveSubscription(removeSubscription); } var addInstanceSubscription = msgInfo.Message as AddInstanceSubscription; if (addInstanceSubscription != null) { return ConsumeAddInstanceSubscription(addInstanceSubscription); } var removeInstanceSubscription = msgInfo.Message as RemoveInstanceSubscription; if (removeInstanceSubscription != null) { return ConsumeRemoveInstanceSubscription(removeInstanceSubscription); } return false; }
public void RaiseAdministrativeMessageProcessingCompleted(CurrentMessageInformation information, Exception ex) { var copy = AdministrativeMessageProcessingCompleted; if (copy != null) copy(information, ex); }
private bool ConsumeAddSubscription(CurrentMessageInformation msgInfo, AddSubscription addSubscription) { bool newSubscription = AddSubscription(addSubscription.Type, addSubscription.Endpoint.Uri.ToString()); var msmqMsgInfo = msgInfo as MsmqCurrentMessageInformation; if (msmqMsgInfo != null && newSubscription) { Message message = msmqMsgInfo.MsmqMessage; msmqMsgInfo.Queue.Send( message.SetSubQueueToSendTo(SubQueue.Subscriptions)); AddMessageIdentifierForTracking( message.Id, addSubscription.Type, addSubscription.Endpoint.Uri); return true; } AddMessageIdentifierForTracking( msgInfo.TransportMessageId, addSubscription.Type, addSubscription.Endpoint.Uri); return false; }
private bool ConsumeAddInstanceSubscription(CurrentMessageInformation msgInfo, AddInstanceSubscription subscription) { remoteInstanceSubscriptions.Add( subscription.InstanceSubscriptionKey, subscription.Type, new Uri(subscription.Endpoint), msgInfo.TransportMessageId); var msmqMsgInfo = msgInfo as MsmqCurrentMessageInformation; if (msmqMsgInfo != null) { msmqMsgInfo.Queue.Send( msmqMsgInfo.MsmqMessage.SetSubQueueToSendTo(SubQueue.Subscriptions)); } RaiseSubscriptionChanged(); return true; }
private void Transport_OnMessageProcessingCompleted(CurrentMessageInformation t1, Exception t2) { TellLoadBalancerThatWeAreReadyForWork(); }
public bool Transport_OnMessageArrived(CurrentMessageInformation msg) { var consumers = GatherConsumers(msg); if (consumers.Length == 0) { logger.ErrorFormat("Got message {0}, but had no consumers for it", msg.Message); return(false); } try { currentMessage = msg.Message; foreach (var consumer in consumers) { logger.DebugFormat("Invoking consume on {0} for message {1}, from '{2}' to '{3}'", consumer, msg.Message, msg.Source, msg.Destination); var sp = Stopwatch.StartNew(); try { reflection.InvokeConsume(consumer, msg.Message); } catch (Exception e) { if (logger.IsDebugEnabled) { var message = string.Format("Consumer {0} failed to process message {1}", consumer, msg.Message ); logger.Debug(message, e); } throw; } finally { sp.Stop(); var elapsed = sp.Elapsed; logger.DebugFormat("Consumer {0} finished processing {1} in {2}", consumer, msg.Message, elapsed); } var sagaEntity = consumer as IAccessibleSaga; if (sagaEntity == null) { continue; } PersistSagaInstance(sagaEntity); } return(true); } finally { currentMessage = null; foreach (var consumer in consumers) { serviceLocator.Release(consumer); } } }
private void Transport_OnMessageSerializationException(CurrentMessageInformation information, Exception ex) { var info = (RhinoFileCurrentMessageInformation)information; _failureCounts.Write(writer => writer.Add(info.TransportMessageId, new ErrorCounter { ExceptionText = (ex == null ? null : ex.ToString()), FailureCount = _numberOfRetries + 1 })); using (var tx = new TransactionScope(TransactionScopeOption.RequiresNew)) { info.Queue.MoveTo(SubQueue.Errors.ToString(), info.TransportMessage); info.Queue.EnqueueDirectlyTo(SubQueue.Errors.ToString(), new MessagePayload { Data = (ex == null ? null : Encoding.Unicode.GetBytes(ex.ToString())), Headers = { {"correlation-id", info.TransportMessageId}, {"retries", "1"} } }); tx.Complete(); } }
private bool Transport_OnMessageArrived(CurrentMessageInformation info) { messageArrival = DateTime.Now; Send(new MessageArrivedMessage { Timestamp = messageArrival, MessageType = info.Message.ToString(), MessageId = info.MessageId, Source = info.Source, Message = info.Message }); return false; }
private bool ConsumeAddSubscription(CurrentMessageInformation msgInfo, AddSubscription addSubscription) { bool newSubscription = AddSubscription(addSubscription.Type, addSubscription.Endpoint); AddMessageIdentifierForTracking(msgInfo.MessageId.ToString(), addSubscription.Type, new Uri(addSubscription.Endpoint)); var msmqMsgInfo = msgInfo as MsmqCurrentMessageInformation; if (msmqMsgInfo != null && newSubscription) { queueStrategy.MoveToSubscriptionQueue(msmqMsgInfo.Queue, msmqMsgInfo.MsmqMessage); return true; } return false; }
private bool ConsumeAddInstanceSubscription(CurrentMessageInformation msgInfo, AddInstanceSubscription subscription) { remoteInstanceSubscriptions.Add( subscription.InstanceSubscriptionKey, subscription.Type, new Uri(subscription.Endpoint), msgInfo.MessageId); var msmqMsgInfo = msgInfo as MsmqCurrentMessageInformation; if (msmqMsgInfo != null) queueStrategy.MoveToSubscriptionQueue(msmqMsgInfo.Queue, msmqMsgInfo.MsmqMessage); RaiseSubscriptionChanged(); return true; }