zoukankan      html  css  js  c++  java
  • 8.rabbitmq RPC模拟微服务架构中的服务调用

    标题 :
    8.rabbitmq RPC模拟微服务架构中的服务调用
    目录 :
    RabbitMQ
    序号 :
    8

        {
            var connectionFactory = new ConnectionFactory
            {
                Port = 5672,
                VirtualHost = "test",
                HostName = "192.168.161.180",
                UserName = "test",
                Password = "123456",
                AutomaticRecoveryEnabled = true,
                TopologyRecoveryEnabled = true
            };
    



    const string queueName = "rpc-queue";


    var connection = connectionFactory.CreateConnection();
    var channel = connection.CreateModel();

    //设置服务质量
    channel.BasicQos(0, 1, false);


    //定义一个队列,将用于存放文件信息
    channel.QueueDeclare(queue: queueName, durable: true, exclusive: false, autoDelete: false, arguments: null);


    var client = new SimpleRpcClient(channel, string.Empty, ExchangeType.Direct, queueName);


    Console.WriteLine("开始RPC调用,调用的方法为 order.queryWithId");
    var basicProperties = new BasicProperties { Headers = new Dictionary<string, object>() };
    basicProperties.Headers.Add("method", "order.queryWithId");
    const string id = "789852";
    var body = Encoding.UTF8.GetBytes(id);
    var rpcCallResBytes = client.Call(basicProperties, body);
    var rpcCallResString = Encoding.UTF8.GetString(rpcCallResBytes.Body);
    Console.WriteLine($"RPC调用完毕,返回结果是:{Environment.NewLine} {rpcCallResString}");


    Console.WriteLine(" Press [enter] to exit.");
    Console.ReadLine();
    }
    }
    }

    ![](https://www.showdoc.cc/server/api/common/visitfile/sign/e97ad84645cdaf5ce88daff74a85e1bf?showdoc=.jpg)
    ​
    ###引用链接
    https://www.rabbitmq.com/tutorials/tutorial-six-dotnet.html
    请尽量按照自己期望的生活 email:18980489167@189.cn
  • 相关阅读:
    Oracle10g服务启动命令
    Linux系统添加永久静态路由的方法
    搭建YUM仓库与定制RPM包
    LVS简介
    【Linux】先添加一块磁盘制作LVM卷并进行分区挂载
    函数部分
    Python中if __name__ == "__main__": 的作用 (整理转自Arkenstone) --感谢!
    python语言基础笔记
    部分示例程序
    转,关于游标
  • 原文地址:https://www.cnblogs.com/gytangyao/p/11406104.html
Copyright © 2011-2022 走看看