# rpc.py

定义了类RequestContextSerializer，RpcProxy，RpcCallback，Service，Connection。

其中RequestContextSerializer类中定义了对实体和上下文的序列化/反序列化，将RPC的通用上下文转化到Neutron上下文。 RpcProxy类提供rpc层的操作，基本上所有需要进行rpc调用的应用都会用到这个类。其中分别定义了call，cast和fanout\_cast方法来发出rpc调用请求。

Service类代表运行在主机上的应用程序所代表的的服务，继承自service.Service，重载了start方法和stop方法。start方法中会创建三个消费连接来监听rpc请求。第一个是监听发送到某个topic上的所有主机上，第二个是监听发送到某个topic的特定主机上，最后一个是所有的广播请求。

Connection类代表了rpc请求的相关连接。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://yeasy.gitbook.io/openstack_code_neutron/neutron/common/rpcpy.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
