Client Side

Here is an example of an rpc client definition:

import oslo_messaging

from neutron.common import rpc as n_rpc

class ClientAPI(object):
"""Client side RPC interface definition. API version history:
1.0 - Initial version
1.1 - Added my_remote_method_2
""" def __init__(self, topic):
target = oslo_messaging.Target(topic=topic, version='1.0')
self.client = n_rpc.get_client(target) def my_remote_method(self, context, arg1, arg2):
cctxt = self.client.prepare()
return cctxt.call(context, 'my_remote_method', arg1=arg1, arg2=arg2) def my_remote_method_2(self, context, arg1):
cctxt = self.client.prepare(version='1.1')
return cctxt.call(context, 'my_remote_method_2', arg1=arg1)
my_remote_method 在v1中,
my_remote_method_2 v1.1中,当调用这个api是,其指定了server端至少实现了v1.1

Server Side

The server side of an rpc interface looks like this:

import oslo_messaging

class ServerAPI(object):

    target = oslo_messaging.Target(version='1.1')

    def my_remote_method(self, context, arg1, arg2):
return 'foo' def my_remote_method_2(self, context, arg1):
return 'bar'

server端说明了支持v1.1

Versioning

rpc interfaces change必须向后兼容。server必须在同一大版本下支持旧的client。

Example Change

比如说my_remote_method_2里增加一个参数,该参数必须有个default值向后兼容,升级小版本

server side code would look like this:

import oslo_messaging

class ServerAPI(object):

    target = oslo_messaging.Target(version='1.2')

    def my_remote_method(self, context, arg1, arg2):
return 'foo' def my_remote_method_2(self, context, arg1, arg2=None):
if not arg2:
# Deal with the fact that arg2 was not specified if needed.
return 'bar'

The client must also specify that version ‘1.2’ is required for this method call to be successful.

import oslo_messaging

from neutron.common import rpc as n_rpc

class ClientAPI(object):
"""Client side RPC interface definition. API version history:
1.0 - Initial version
1.1 - Added my_remote_method_2
1.2 - Added arg2 to my_remote_method_2
""" def __init__(self, topic):
target = oslo_messaging.Target(topic=topic, version='1.0')
self.client = n_rpc.get_client(target) def my_remote_method(self, context, arg1, arg2):
cctxt = self.client.prepare()
return cctxt.call(context, 'my_remote_method', arg1=arg1, arg2=arg2) def my_remote_method_2(self, context, arg1, arg2):
cctxt = self.client.prepare(version='1.2')
return cctxt.call(context, 'my_remote_method_2',
arg1=arg1, arg2=arg2)

Example: DHCP

The DHCP agent includes a client API, neutron.agent.dhcp.agent.DhcpPluginAPI.

The server side is defined in neutron.api.rpc.handlers.dhcp_rpc.DhcpRpcCallback.

Similarly, there is an RPC interface defined that allows the Neutron plugin to remotely invoke methods in the DHCP agent.

The client side is defined in neutron.api.rpc.agentnotifiers.dhcp_rpc_agent_api.DhcpAgentNotifyApi.

The server side of this interface that runs in the DHCP agent is neutron.agent.dhcp.agent.DhcpAgent.

http://docs.openstack.org/developer/neutron/devref/rpc_api.html

最新文章

  1. 转:Delphi的类与继承(VB与delphi比较)
  2. spring简单介绍
  3. Codeforces Round #369 (Div. 2) D. Directed Roads dfs求某个联通块的在环上的点的数量
  4. mldn android
  5. 【不积跬步,无以致千里】mysql 多行合并函数
  6. [js高手之路]Node.js模板引擎教程-jade速学与实战4-模板引用,继承,插件使用
  7. wireshark_帧信息
  8. HTTP协议初步解析
  9. 关于使用format()方法格式化字符串,读这一篇就够了!
  10. Font Awesome 供更精准的图标搜索
  11. Count the string kmp
  12. windows下如何批量修改文件名
  13. Django 之Redis配置
  14. angular的启动原理
  15. superset----缓存之redis
  16. [UOJ#276][清华集训2016]汽水[分数规划+点分治]
  17. ubuntu14.04-64位机配置android开发环境,ADT,sdk,eclipsea
  18. 求组合数 C++程序
  19. R语言学习——欧拉计划(3)Largest prime factor 求最大质因数
  20. php imagecreatetruecolor()方法报未定义错误解决方法

热门文章

  1. 【数据挖掘】分类之Naïve Bayes(转载)
  2. C语言中的一个*和[]优先级问题
  3. man page及info page用法
  4. 2018,从AI看安卓生态的变革
  5. 【Navicat Premium】之连接Oracle数据库
  6. 那不是Bug,是新需求
  7. Android屏幕密度(Density)和分辨率概念详解
  8. 重载(overload)、覆盖(override)和隐藏(hide)
  9. HDFS上传机制
  10. iphone传感器