예제 #1
0
        async Task RunAsync()
        {
            await Task.Yield();

            Properties peekProps = Properties.Label | Properties.LookupId;

            try
            {
                for (;;)
                {
                    Message msg = _input.Peek(peekProps, TimeSpan.Zero) ?? await _input.PeekAsync(peekProps);

                    // at this point we only have the label and lookup id of the message
                    var subscribers = _subscriptions.Subscribers(msg.Label);
                    if (subscribers == null)
                    {
                        // no subscribers, remove message from input queue anyway
                        _input.Lookup(Properties.LookupId, msg.LookupId, LookupAction.ReceiveCurrent, TimeSpan.Zero);
                        continue;
                    }

                    // read the whole message now, remove it from the queue, and invoke the subscription callbacks
                    msg = _input.Lookup(Properties.All, msg.LookupId, LookupAction.ReceiveCurrent, TimeSpan.Zero);
                    if (msg == null)
                    {
                        Console.Error.WriteLine($"WARNING: we peeked message but it was removed before we could read it {{label={msg.Label}, lookupId={msg.LookupId}}}");
                        continue;
                    }

                    _subscriptions.TryInvokeAll(msg, subscribers);
                }
            }
            catch (ObjectDisposedException)
            {
                // Stop was called
            }
            catch (QueueException ex) when(ex.ErrorCode == ErrorCode.OperationCanceled)
            {
                // Stop was called
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine("WARNING: " + ex);
            }
        }
예제 #2
0
        public void can_peek_when_opened_with_move_acces()
        {
            var fn   = Queues.TryCreate(".\\private$\\subqtest", QueueTransactional.None);
            var sqfn = fn + ";sq";

            using (var qWriter = new QueueWriter(fn))
            {
                qWriter.Write(new Message {
                    AppSpecific = 234
                });
            }
            using (var qReader = new QueueReader(fn))
                using (var subQueue = new SubQueue(sqfn))
                {
                    var msg = qReader.Peek(Properties.LookupId);
                    Queues.MoveMessage(qReader, subQueue, msg.LookupId);
                    var got = subQueue.Read();
                    Assert.AreEqual(234, got.AppSpecific);
                }
        }
예제 #3
0
        async Task RunAsync()
        {
            await Task.Yield();

            try
            {
                for (;;)
                {
                    Message peeked = _input.Peek(PeekProperties, TimeSpan.Zero) ?? await _input.PeekAsync(PeekProperties);

                    try
                    {
                        var subQueue = GetRoute(peeked);
                        Queues.MoveMessage(_input, subQueue, peeked.LookupId, _transaction);
                    }
                    catch (RouteException ex)
                    {
                        if (peeked.LookupId != 0)
                        {
                            MoveToUnroutableSubQueue(peeked.LookupId, _transaction);
                        }
                    }
                }
            }
            catch (QueueException ex) when(ex.ErrorCode == ErrorCode.OperationCanceled)
            {
                // queue handle was closed, i.e. stopped
            }
            catch (ObjectDisposedException)
            {
                // queue handle was closed, i.e. stopped
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }