示例#1
0
    /// <summary>
    /// Gets the number of messages waiting in the queue
    /// </summary>
    public async Task <Dictionary <string, object> > GetProperties(CancellationToken cancellationToken)
    {
        if (_inputQueueAddress == null)
        {
            throw new InvalidOperationException("Cannot get message count from one-way transport");
        }

        var count = _network.GetCount(_inputQueueAddress);

        return(new Dictionary <string, object>
        {
            { TransportInspectorPropertyKeys.QueueLength, count.ToString() }
        });
    }
示例#2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Starting...");

            var network = new InMemNetwork(false);

            using (var activator = new BuiltinHandlerActivator()) // This one would be provided by the IoC container
                using (var timer = new Timer())
                    using (var timer2 = new Timer())
                        using (var stats_timer = new Timer())
                        {
                            // Add the "Input" OneWay bus
                            var bus = Configure.With(activator)
                                      .Logging(l => l.ColoredConsole(minLevel: UsedLogLevel))
                                      .Transport(t => t.UseInMemoryTransportAsOneWayClient(network))
                                      //.Sagas(s => s.UseFilesystem("processes"))
                                      .Routing(r => r.TypeBased()
                                               .Map <CurrentTimeMessage>(InputQueueName + "ctm")
                                               .Map <TestMessage>(InputQueueName + "tm"))
                                      //.MapFallback(InputQueueName + "unknownmessage"))
                                      .Start();
                            // Add the busses to receive the messages and dispatch the workers.
                            var bus1 = ConfigureBus <CurrentTimeMessage>(ConfigureActivator <PrintDateTime>(), network, InputQueueName + "ctm");
                            var bus2 = ConfigureBus <TestMessage>(ConfigureActivator <PrintTest>(), network, InputQueueName + "tm");

                            timer.Elapsed += delegate { bus.Send(new CurrentTimeMessage(DateTimeOffset.Now)).Wait(); };
                            timer.Interval = 1000;
                            timer.Start();

                            timer2.Elapsed += delegate { bus.Send(new TestMessage()).Wait(); };
                            timer2.Interval = 2500;
                            timer2.Start();

                            stats_timer.Elapsed += delegate {
                                var sb = new StringBuilder("Stats: ");
                                foreach (var q in network.Queues)
                                {
                                    sb.AppendFormat("{0}: {1}; ", q, network.GetCount(q));
                                }
                                Console.WriteLine(sb.ToString());
                            };
                            stats_timer.Interval = 5000;
                            stats_timer.Start();


                            Console.WriteLine("Press enter to quit");
                            Console.ReadLine();
                        }
        }