Ejemplo n.º 1
0
        bool MessageIsExpired(InMemTransportMessage message)
        {
            var headers = message.Headers;

            if (!headers.ContainsKey(Headers.TimeToBeReceived))
            {
                return(false);
            }

            var timeToBeReceived = headers[Headers.TimeToBeReceived];
            var maximumAge       = TimeSpan.Parse(timeToBeReceived);

            return(message.Age > maximumAge);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Delivers the specified <see cref="InMemTransportMessage"/> to the address specified by <paramref name="destinationAddress"/>.
        /// If <paramref name="alwaysQuiet"/> is set to true, no events will ever be printed to <see cref="Console.Out"/>
        /// (can be used by an in-mem transport to return a message to a queue, as if there was a queue transaction that was rolled back)
        /// </summary>
        public void Deliver(string destinationAddress, InMemTransportMessage msg, bool alwaysQuiet = false)
        {
            if (destinationAddress == null) throw new ArgumentNullException("destinationAddress");
            if (msg == null) throw new ArgumentNullException("msg");

            if (_outputEventsToConsole && !alwaysQuiet)
            {
                Console.WriteLine("{0} ---> {1} ({2})", msg.Headers.GetValueOrNull(Headers.MessageId) ?? "<no message ID>", destinationAddress, _networkId);
            }

            var messageQueue = _queues
                .GetOrAdd(destinationAddress, address => new ConcurrentQueue<InMemTransportMessage>());

            messageQueue.Enqueue(msg);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Delivers the specified <see cref="InMemTransportMessage"/> to the address specified by <paramref name="destinationAddress"/>.
        /// If <paramref name="alwaysQuiet"/> is set to true, no events will ever be printed to <see cref="Console.Out"/>
        /// (can be used by an in-mem transport to return a message to a queue, as if there was a queue transaction that was rolled back)
        /// </summary>
        public void Deliver(string destinationAddress, InMemTransportMessage msg, bool alwaysQuiet = false)
        {
            if (destinationAddress == null)
            {
                throw new ArgumentNullException("destinationAddress");
            }
            if (msg == null)
            {
                throw new ArgumentNullException("msg");
            }

            if (_outputEventsToConsole && !alwaysQuiet)
            {
                Console.WriteLine("{0} ---> {1} ({2})", msg.Headers.GetValueOrNull(Headers.MessageId) ?? "<no message ID>", destinationAddress, _networkId);
            }

            var messageQueue = _queues
                               .GetOrAdd(destinationAddress, address => new ConcurrentQueue <InMemTransportMessage>());

            messageQueue.Enqueue(msg);
        }
Ejemplo n.º 4
0
        public async Task StillWorksWhenIncomingMessageCannotBeDeserialized()
        {
            const string brokenJsonString = @"{'broken': 'json', // DIE!!1}";

            var headers = new Dictionary<string, string>
            {
                {Headers.MessageId, Guid.NewGuid().ToString()},
                {Headers.ContentType, "application/json;charset=utf-8"},
            };
            var body = Encoding.UTF8.GetBytes(brokenJsonString);
            var transportMessage = new TransportMessage(headers, body);
            var inMemTransportMessage = new InMemTransportMessage(transportMessage);  
            _network.Deliver(InputQueueName, inMemTransportMessage);

            await Task.Delay(1000);

            var failedMessage = _network.GetNextOrNull("error");

            Assert.That(failedMessage, Is.Not.Null);
            var bodyString = Encoding.UTF8.GetString(failedMessage.Body);
            Assert.That(bodyString, Is.EqualTo(brokenJsonString));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Delivers the specified <see cref="InMemTransportMessage"/> to the address specified by <paramref name="destinationAddress"/>.
        /// If <paramref name="alwaysQuiet"/> is set to true, no events will ever be printed to <see cref="Console.Out"/>
        /// (can be used by an in-mem transport to return a message to a queue, as if there was a queue transaction that was rolled back)
        /// </summary>
        public void Deliver(string destinationAddress, InMemTransportMessage msg, bool alwaysQuiet = false)
        {
            if (destinationAddress == null)
            {
                throw new ArgumentNullException(nameof(destinationAddress));
            }
            if (msg == null)
            {
                throw new ArgumentNullException(nameof(msg));
            }

            if (!alwaysQuiet)
            {
                var messageId = msg.Headers.GetValueOrNull(Headers.MessageId) ?? "<no message ID>";

                _log.Info($"{messageId} ---> {destinationAddress} ({_networkId})");
            }

            var messageQueue = _queues
                               .GetOrAdd(destinationAddress, address => new ConcurrentQueue <InMemTransportMessage>());

            messageQueue.Enqueue(msg);
        }
Ejemplo n.º 6
0
        bool MessageIsExpired(InMemTransportMessage message)
        {
            var headers= message.Headers;
            if (!headers.ContainsKey(Headers.TimeToBeReceived)) return false;

            var timeToBeReceived = headers[Headers.TimeToBeReceived];
            var maximumAge = TimeSpan.Parse(timeToBeReceived);

            return message.Age > maximumAge;
        }
Ejemplo n.º 7
0
        static void PrintHeaders(InMemTransportMessage message)
        {
            Console.WriteLine(@"Headers:
{0}", string.Join(Environment.NewLine, message.Headers.Select(kvp => string.Format("    {0}: {1}", kvp.Key, kvp.Value))));
        }
Ejemplo n.º 8
0
        static void PrintHeaders(InMemTransportMessage message)
        {
            Console.WriteLine(@"Headers:
{0}", string.Join(Environment.NewLine, message.Headers.Select(kvp => $"    {kvp.Key}: {kvp.Value}")));
        }