public static MessageScope <T> ReceiveInScope <T>(this ISubscriberClient client, TimeSpan timeout)
        {
            if (client == null)
            {
                throw new ArgumentNullException("client");
            }

            return(new MessageScope <T>(client.Receive <T>(timeout)));
        }
Ejemplo n.º 2
0
        private static void StartWithOptions(CommandLineOptions opts)
        {
            Log.Info("Starting test server");
            IPAddress ipAddress;

            try
            {
                ipAddress = IPAddress.Parse(opts.Hostname);
            }
            catch (Exception)
            {
                ipAddress = Dns.GetHostEntry(opts.Hostname).AddressList[0];
            }
            Server server = new Server(ipAddress);

            server.StartListening();

            if (opts.CreateLocalPublisher)
            {
                _localPublisher = server.CreateLocalPublisher();
                _localPublisher.Publish("test-channel");
            }

            if (opts.CreateLocalSubscriber)
            {
                _localSubscriber = server.CreateLocalSubscriber();
                _localSubscriber.Subscribe("test-channel");
                _localSubscriber.MessageReceived.Subscribe((s) => Log.Info($"LocalSubscriber received message: {s}"));
            }

            Log.Info("Test server ready");
            if (opts.CreateLocalPublisher)
            {
                while (true)
                {
                    var message = Console.ReadLine();
                    if (message == "dispose")
                    {
                        _localPublisher.Dispose();
                    }
                    else
                    {
                        _localPublisher.Send(message);
                    }
                }
            }
            else
            {
                Console.ReadKey();
            }
        }
 public static MessageScope <T> ReceiveInScope <T>(this ISubscriberClient client)
 {
     return(client.ReceiveInScope <T>(TimeSpan.Zero));
 }