示例#1
0
        public static void Main()
        {
            var rpc = new RpcServer("ExampleChannel");

            rpc.Bind <IMath>(new MathImpl() as IMath);

            rpc.Start();

            Console.WriteLine("Service started");

            Console.ReadLine();
        }
示例#2
0
        static void Main(string[] args)
        {
            var factory = new ConnectionFactory()
            {
                Uri = "amqp://*****:*****@192.168.1.25:5672/test"
            };

            // 设置心跳超时,默认值为60秒
            factory.RequestedHeartbeat = 60;
            using (IConnection conn = factory.CreateConnection())
            {
                using (IModel channel = conn.CreateModel())
                {
                    // 声明Exchange
                    channel.ExchangeDeclare(
                        exchange: "ExchangeName",
                        type: ExchangeType.Direct,
                        durable: false,
                        autoDelete: false
                        );
                    // 声明Queue
                    var queueName = channel.QueueDeclare(
                        queue: "QueueName",
                        durable: false,
                        exclusive: false,
                        autoDelete: false
                        ).QueueName;
                    // 绑定Queue
                    channel.QueueBind(
                        queue: queueName,
                        exchange: "ExchangeName",
                        routingKey: "RoutingKey" // direct连接,RoutingKey可以省略
                        );

                    Subscription subscription = new Subscription(channel, queueName);
                    RpcServer    server       = new RpcServer(subscription);

                    server.MainLoop();

                    Console.ReadLine();
                }
            }
        }