Example #1
0
        public bool HandlePeekedMessage(IMsmqTransport transport, OpenedQueue queue, Message message)
        {
            bool doesNotHaveMessageId = message.Extension.Length < 16;

            if (doesNotHaveMessageId)
            {
                const string errorMessage = "Message does not have Extension set to at least 16 bytes, which will be used as the message id. Probably not a bus message.";
                transport.RaiseMessageSerializationException(queue, message, errorMessage);
                MoveToErrorQueue(queue, message, errorMessage);
                return(true);
            }

            var          id           = message.GetMessageId();
            ErrorCounter errorCounter = null;

            failureCounts.Read(reader => reader.TryGetValue(id, out errorCounter));

            if (errorCounter == null)
            {
                return(false);
            }

            if (errorCounter.FailureCount < numberOfRetries)
            {
                return(false);
            }

            failureCounts.Write(writer =>
            {
                writer.Remove(id);
                MoveToErrorQueue(queue, message, errorCounter.ExceptionText);
            });

            return(true);
        }
Example #2
0
        public override bool HandlePeekedMessage(IMsmqTransport transport, OpenedQueue queue, Message message)
        {
            using (var tx = transactionStrategy.Begin())
            {
                var processMessageAt = DateTime.FromBinary(BitConverter.ToInt64(message.Extension, 16));
                if (CurrentTime >= processMessageAt)
                {
                    return(false);
                }

                string id;
                if (queueStrategy.TryMoveMessage(queue, message, SubQueue.Timeout, out id) == false)
                {
                    logger.DebugFormat("Failed to move message to timeout queue");
                    return(false);
                }
                tx.Complete();

                logger.DebugFormat("Moving message {0} to timeout queue, will be processed at: {1}",
                                   id, processMessageAt);

                timeoutMessageIds.Write(writer => writer.Add(processMessageAt, id));

                return(true);
            }
        }
Example #3
0
        public bool HandlePeekedMessage(IMsmqTransport transport, OpenedQueue queue, Message message)
        {
            bool doesNotHaveMessageId = message.Extension.Length < 16;
            if(doesNotHaveMessageId)
            {
                const string errorMessage = "Message does not have Extension set to at least 16 bytes, which will be used as the message id. Probably not a bus message.";
                transport.RaiseMessageSerializationException(queue,message,errorMessage);
                MoveToErrorQueue(queue, message, errorMessage);
                return true;
            }

            var id = message.GetMessageId();
            ErrorCounter errorCounter = null;

            failureCounts.Read(reader => reader.TryGetValue(id, out errorCounter));

            if (errorCounter == null)
                return false;

            if (errorCounter.FailureCount < numberOfRetries)
                return false;

            failureCounts.Write(writer =>
            {
                writer.Remove(id);
                MoveToErrorQueue(queue, message, errorCounter.ExceptionText);
            });

            return true;
        }
        public static IEndpoint New(CreateMsmqEndpointSettings settings)
        {
            try
            {
                Guard.Against.Null(settings.Address, "An address for the endpoint must be specified");
                Guard.Against.Null(settings.ErrorAddress, "An error address for the endpoint must be specified");
                Guard.Against.Null(settings.Serializer, "A message serializer for the endpoint must be specified");

                var transport = MsmqTransportFactory.New(settings);

                // TODO Does this need to be a bus concern?
                PurgeExistingMessagesIfRequested(settings);

                var errorSettings = new CreateMsmqTransportSettings(settings.ErrorAddress, settings);
                if (transport.MsmqAddress.IsTransactional)
                {
                    settings.Transactional = true;
                }

                IMsmqTransport errorTransport = MsmqTransportFactory.New(errorSettings);

                var endpoint = new MsmqEndpoint(settings.Address, settings.Serializer, transport, errorTransport);

                return(endpoint);
            }
            catch (Exception ex)
            {
                throw new EndpointException(settings.Address.Uri, "Failed to create MSMQ endpoint", ex);
            }
        }
Example #5
0
 public CheckIntervalElapsedMessageHandler(IBus bus, IPluginMetadata pluginMetadata, IAccountCollection collection, IMsmqTransport transport, ITaskFactory taskFactory)
 {
     _bus            = bus;
     _pluginMetadata = pluginMetadata;
     _collection     = collection;
     _transport      = transport;
     _taskFactory    = taskFactory;
 }
Example #6
0
        public MsmqEndpoint(IMsmqEndpointAddress address, IMessageSerializer serializer, IMsmqTransport transport, IMsmqTransport errorTransport)
            : base(address, serializer)
        {
            _tracker = new MessageRetryTracker(5);

            _transport      = transport;
            _errorTransport = errorTransport;

            SetDisposedMessage();
        }
Example #7
0
 public override void Init(IMsmqTransport transport, OpenedQueue queue)
 {
     parentTransport = transport;
     timeoutMessageIds.Write(writer =>
     {
         foreach (var message in queueStrategy.GetTimeoutMessages(queue))
         {
             writer.Add(message.Time, message.Id);
         }
     });
     timeoutTimer = new Timer(OnTimeoutCallback, null, TimeSpan.FromSeconds(0), TimeSpan.FromSeconds(1));
 }
Example #8
0
 public override void Init(IMsmqTransport transport, OpenedQueue queue)
 {
     parentTransport = transport;
     timeoutMessageIds.Write(writer =>
     {
         foreach (var message in queueStrategy.GetTimeoutMessages(queue))
         {
             writer.Add(message.Time, message.Id);
         }
     });
     timeoutTimer = new Timer(OnTimeoutCallback, null, TimeSpan.FromSeconds(0), TimeSpan.FromSeconds(1));
 }
        public override bool HandlePeekedMessage(IMsmqTransport transport1, OpenedQueue queue, Message message)
        {
            Func<CurrentMessageInformation, bool> messageRecieved = information =>
            {
                transport.RaiseAdministrativeMessageArrived(information);

                return true;
            };

            transport.ReceiveMessageInTransaction(
                queue, message.Id,
                messageRecieved,
                transport.RaiseAdministrativeMessageProcessingCompleted);

            return true;
        }
        public override bool HandlePeekedMessage(IMsmqTransport transport1, OpenedQueue queue, Message message)
        {
            Func <CurrentMessageInformation, bool> messageRecieved = information =>
            {
                transport.RaiseAdministrativeMessageArrived(information);

                return(true);
            };

            transport.ReceiveMessageInTransaction(
                queue, message.Id,
                messageRecieved,
                transport.RaiseAdministrativeMessageProcessingCompleted,
                null);

            return(true);
        }
Example #11
0
        protected override void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }
            if (disposing)
            {
                _transport.Dispose();
                _transport = null;

                _errorTransport.Dispose();
                _errorTransport = null;

                base.Dispose(true);
            }

            _disposed = true;
        }
        public AccountHandler([NotNull] IAccountCollection collection, [NotNull] ITpBus bus, [NotNull] IPluginContext context,
                              [NotNull] ILogManager logManager, [NotNull] IMsmqTransport msmqTransport)
        {
            if (collection == null)
            {
                throw new NullReferenceException("collection");
            }

            if (bus == null)
            {
                throw new ArgumentNullException("bus");
            }

            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            _collection    = collection;
            _bus           = bus;
            _context       = context;
            _msmqTransport = msmqTransport;
            _log           = logManager.GetLogger(this.GetType());
        }
Example #13
0
        public override bool HandlePeekedMessage(IMsmqTransport transport, OpenedQueue queue, Message message)
        {
          using(var tx = new TransactionScope())
          {
              var processMessageAt = DateTime.FromBinary(BitConverter.ToInt64(message.Extension, 16));
              if (CurrentTime >= processMessageAt)
                  return false;

              string id;
              if(queueStrategy.TryMoveMessage(queue, message, SubQueue.Timeout, out id)==false)
              {
                  logger.DebugFormat("Failed to move message to timeout queue");
                  return false;
              }
              tx.Complete();

              logger.DebugFormat("Moving message {0} to timeout queue, will be processed at: {1}",
                                 id,processMessageAt);

              timeoutMessageIds.Write(writer => writer.Add(processMessageAt, id));

              return true;
          }
        }
		public DeleteUnusedQueuesCommand(IAccountCollection accountCollection, IMsmqTransport msmqTransport)
		{
			_accountCollection = accountCollection;
			_msmqTransport = msmqTransport;
		}
		public RouterChildTagsSource(IAccountCollection accountCollection, IMsmqTransport transport)
		{
			_accountCollection = accountCollection;
			_transport = transport;
		}
Example #16
0
 public override bool HandlePeekedMessage(IMsmqTransport transport, OpenedQueue queue, Message message)
 {
     queue.TryGetMessageFromQueue(message.Id);
     return(true);
 }
 public override void Init(IMsmqTransport parentTransport, OpenedQueue queue)
 {
     transport = parentTransport;
 }
Example #18
0
 public void Init(IMsmqTransport transport, OpenedQueue queue)
 {
     transport.MessageSerializationException += Transport_OnMessageSerializationException;
     transport.MessageProcessingFailure      += Transport_OnMessageProcessingFailure;
     transport.MessageProcessingCompleted    += Transport_OnMessageProcessingCompleted;
 }
Example #19
0
 public void Init(IMsmqTransport transport, OpenedQueue queue)
 {
     transport.MessageSerializationException += Transport_OnMessageSerializationException;
     transport.MessageProcessingFailure += Transport_OnMessageProcessingFailure;
     transport.MessageProcessingCompleted += Transport_OnMessageProcessingCompleted;
 }
 public DeleteUnusedQueuesCommand(IAccountCollection accountCollection, IMsmqTransport msmqTransport)
 {
     _accountCollection = accountCollection;
     _msmqTransport     = msmqTransport;
 }
Example #21
0
 public override bool HandlePeekedMessage(IMsmqTransport transport, OpenedQueue queue, Message message)
 {
     queue.TryGetMessageFromQueue(message.Id);
     return true;
 }
 public virtual void Init(IMsmqTransport transport, OpenedQueue queue)
 {
 }
 public abstract bool HandlePeekedMessage(IMsmqTransport transport, OpenedQueue queue, Message message);
Example #24
0
 public abstract bool HandlePeekedMessage(IMsmqTransport transport, OpenedQueue queue, Message message);
Example #25
0
 public RouterChildTagsSource(IAccountCollection accountCollection, IMsmqTransport transport)
 {
     _accountCollection = accountCollection;
     _transport         = transport;
 }
 public override void Init(IMsmqTransport parentTransport, OpenedQueue queue)
 {
     transport = parentTransport;
 }
Example #27
0
 public virtual void Init(IMsmqTransport transport, OpenedQueue queue)
 {
 }