public static int Main(string[] args)
        {
            if (args.Length < 1) {
                Console.Error.WriteLine("Usage: ShutdownableClient <uri> [<secondsdelay>]");
                Console.Error.WriteLine("RabbitMQ .NET client version "+typeof(IModel).Assembly.GetName().Version.ToString());
                Console.Error.WriteLine("Parameters:");
                Console.Error.WriteLine("  <uri> = \"amqp://*****:*****@host:port/vhost\"");
                return 2;
            }

            ConnectionFactory cf = new ConnectionFactory();
            cf.Uri = args[0];
            using (IConnection conn = cf.CreateConnection()) {
                using (IModel ch = conn.CreateModel()) {
                    object[] callArgs = new object[1];
                    if (args.Length > 1) {
                        callArgs[0] = double.Parse(args[1]);
                    } else {
                        callArgs[0] = (double) 0.0;
                    }

                    SimpleRpcClient client = new SimpleRpcClient(ch, "ShutdownableServer");
                    client.TimeoutMilliseconds = 5000;
                    client.TimedOut += new EventHandler(TimedOutHandler);
                    client.Disconnected += new EventHandler(DisconnectedHandler);
                    object[] reply = client.Call(callArgs);
                    if (reply == null) {
                        Console.WriteLine("Timeout or disconnection.");
                    } else {
                        Console.WriteLine("Reply: {0}", reply[0]);
                    }
                }
            }
            return 0;
        }
Пример #2
0
        static void Main(string[] args)
        {
            var factory = new ConnectionFactory();
            factory.Protocol = Protocols.AMQP_0_9;
            factory.HostName = "localhost";
            factory.Port = AmqpTcpEndpoint.UseDefaultPort;

            using (var con = factory.CreateConnection())
            {
                using (var channel = con.CreateModel())
                {
                    SimpleRpcClient client = new SimpleRpcClient(channel, "test");

                    Console.WriteLine("Connected to the queue.  Type in a product name to submit an order or type 'q' + <ENTER> to quit...");
                    string productName = Console.ReadLine();
                    while (productName != "q")
                    {
                        byte[] body = ASCIIEncoding.ASCII.GetBytes(productName);
                        Console.WriteLine("Submitting order for product '{0}'...", productName);
                        var responseBody = client.Call(body);
                        string response = ASCIIEncoding.ASCII.GetString(responseBody);
                        Console.WriteLine("Response recieved.  Order ID: {0}", response);

                        productName = Console.ReadLine();
                    }

                }
            }
        }
Пример #3
0
        public static int Main(string[] args)
        {
            if (args.Length < 1) {
                Console.Error.WriteLine("Usage: AddClient <hostname>[:<portnumber>] [<number> ...]");
                Console.Error.WriteLine("RabbitMQ .NET client version "+typeof(IModel).Assembly.GetName().Version.ToString());
                return 2;
            }

            ConnectionFactory cf = new ConnectionFactory();
            cf.Address = args[0];

            using (IConnection conn = cf.CreateConnection()) {
                using (IModel ch = conn.CreateModel()) {

                    object[] addends = new object[args.Length - 1];
                    for (int i = 0; i < args.Length - 1; i++) {
                        addends[i] = double.Parse(args[i + 1]);
                    }

                    SimpleRpcClient client = new SimpleRpcClient(ch, "AddServer");
                    client.TimeoutMilliseconds = 5000;
                    client.TimedOut += new EventHandler(TimedOutHandler);
                    client.Disconnected += new EventHandler(DisconnectedHandler);
                    object[] reply = client.Call(addends);
                    if (reply == null) {
                        Console.WriteLine("Timeout or disconnection.");
                    } else {
                        Console.WriteLine("Reply: {0}", reply[0]);
                    }
                }
            }
            return 0;
        }