예제 #1
0
        /// <summary>
        /// Reads messages off a queue as they arrive, deserializes them into the
        /// specified type T and invokes registered handlers. This operation is
        /// asynchnronous meaning registered handlers will be invoked on the
        /// background thread.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        public void ReceiveAsync <T>()
        {
            if (_readQueue == null || !_readQueue.IsInitialized)
            {
                throw new BusException("Bus has not been configured for receiving messages. Did you forget to call DefineReadQueue on BusBuilder?");
            }

            _readQueue.ReceiveAsync(message => {
                var context = new ReadMessageContext(_errorQueue, _readQueue);
                var receiveMessageHandler     = new ReceiveMessageHandler <T>(_handlers, _config, _logger);
                var retryAspect               = new RetryAspect(receiveMessageHandler, _config, _logger);
                var removeFromReadQueueAspect = new RemoveFromReadQueueAspect(retryAspect, context, _config, _logger);
                var moveToErrorQueueAspect    = new MoveToErrorQueueAspect(removeFromReadQueueAspect, context, _config, _logger);
                var loggingAspect             = new LoggingAspect(moveToErrorQueueAspect, ReceiveOperation, _logger);
                var transactionAspect         = new TransactionAspect(loggingAspect, _logger);
                var discardAspect             = new DiscardFailuresAspect(transactionAspect, _config, _logger);
                var failFastAspect            = new FailFastAspect(discardAspect, _config, _logger);
                failFastAspect.Handle(message);

                if (failFastAspect.Failed)
                {
                    _readQueue.StopReceiveAsync();
                }
            });
        }
예제 #2
0
        /// <summary>
        /// Takes a given type T and serializes it to json before
        /// wrapping it in an MSMQ message and placing it on a queue.
        /// </summary>
        public void Send <T>(T dto)
        {
            if (!_writeQueueManager.HasWriteQueues)
            {
                throw new BusException("Bus has not been configured for sending messages. Did you forget to call DefineWriteQueue on BusBuilder?");
            }

            foreach (var writeQueue in _writeQueueManager.GetWriteQueues())
            {
                var message            = CreateMsmqMessageFromDto(dto);
                var context            = new WriteMessageContext(writeQueue);
                var sendMessageHandler = new SendMessageHandler(context, _config, _logger);
                var loggingAspect      = new LoggingAspect(sendMessageHandler, SendOperation, _logger);
                var transactionAspect  = new TransactionAspect(loggingAspect, _logger);
                transactionAspect.Handle(message);
            }
        }
예제 #3
0
        /// <summary>
        /// Reads messages off a queue, deserializes them into the
        /// specified type T and invokes registered handlers. Useful when
        /// you want to control when messages are processed i.e. at a set
        /// time every day, for example.
        /// </summary>
        public void Receive <T>()
        {
            if (_readQueue == null || !_readQueue.IsInitialized)
            {
                throw new BusException("Bus has not been configured for receiving messages. Did you forget to call DefineReadQueue on BusBuilder?");
            }

            foreach (Message message in _readQueue.GetAllMessages())
            {
                var context = new ReadMessageContext(_errorQueue, _readQueue);
                var receiveMessageHandler     = new ReceiveMessageHandler <T>(_handlers, _config, _logger);
                var retryAspect               = new RetryAspect(receiveMessageHandler, _config, _logger);
                var removeFromReadQueueAspect = new RemoveFromReadQueueAspect(retryAspect, context, _logger);
                var moveToErrorQueueAspect    = new MoveToErrorQueueAspect(removeFromReadQueueAspect, context, _logger);
                var loggingAspect             = new LoggingAspect(moveToErrorQueueAspect, ReceiveOperation, _logger);
                var transactionAspect         = new TransactionAspect(loggingAspect, _logger);
                transactionAspect.Handle(message);
            }
        }
예제 #4
0
 public SecurityByApiControllerInterceptor(AuthenticationAspect authAspect, TransactionAspect transAspect)
 {
     _authAspect  = authAspect;
     _transAspect = transAspect;
 }