1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
3
# Copyright 2010 United States Government as represented by the
4
# Administrator of the National Aeronautics and Space Administration.
6
# Copyright 2011 Red Hat, Inc.
8
# Licensed under the Apache License, Version 2.0 (the "License"); you may
9
# not use this file except in compliance with the License. You may obtain
10
# a copy of the License at
12
# http://www.apache.org/licenses/LICENSE-2.0
14
# Unless required by applicable law or agreed to in writing, software
15
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
17
# License for the specific language governing permissions and limitations
1
21
from nova import exception
2
22
from nova import flags
3
23
from nova import log as logging
27
47
self.traceback = traceback
28
48
super(RemoteError, self).__init__(**self.__dict__)
51
class Connection(object):
52
"""A connection, returned by rpc.create_connection().
54
This class represents a connection to the message bus used for rpc.
55
An instance of this class should never be created by users of the rpc API.
56
Use rpc.create_connection() instead.
59
"""Close the connection.
61
This method must be called when the connection will no longer be used.
62
It will ensure that any resources associated with the connection, such
63
as a network connection, and cleaned up.
65
raise NotImplementedError()
67
def create_consumer(self, topic, proxy, fanout=False):
68
"""Create a consumer on this connection.
70
A consumer is associated with a message queue on the backend message
71
bus. The consumer will read messages from the queue, unpack them, and
72
dispatch them to the proxy object. The contents of the message pulled
73
off of the queue will determine which method gets called on the proxy
76
:param topic: This is a name associated with what to consume from.
77
Multiple instances of a service may consume from the same
78
topic. For example, all instances of nova-compute consume
79
from a queue called "compute". In that case, the
80
messages will get distributed amongst the consumers in a
81
round-robin fashion if fanout=False. If fanout=True,
82
every consumer associated with this topic will get a
83
copy of every message.
84
:param proxy: The object that will handle all incoming messages.
85
:param fanout: Whether or not this is a fanout topic. See the
86
documentation for the topic parameter for some
87
additional comments on this.
89
raise NotImplementedError()
91
def consume_in_thread(self):
92
"""Spawn a thread to handle incoming messages.
94
Spawn a thread that will be responsible for handling all incoming
95
messages for consumers that were set up on this connection.
97
Message dispatching inside of this is expected to be implemented in a
98
non-blocking manner. An example implementation would be having this
99
thread pull messages in for all of the consumers, but utilize a thread
100
pool for dispatching the messages to the proxy objects.
102
raise NotImplementedError()