12
'MessagingUnavailable',
18
14
from zope.interface import Interface
19
from zope.schema import Bool
22
class MessagingException(Exception):
23
"""Failure in messaging."""
26
class MessagingUnavailable(MessagingException):
27
"""Messaging systems are not available."""
30
class QueueNotFound(MessagingException):
31
"""Raised if the queue was not found."""
34
class QueueEmpty(MessagingException):
17
class EmptyQueueException(Exception):
35
18
"""Raised if there are no queued messages on a non-blocking read."""
38
class IMessageSession(Interface):
41
u"Whether the session is connected to the messaging system.")
44
"""Connect to the messaging system.
46
If the session is already connected this should be a no-op.
50
"""Disconnect from the messaging system.
52
If the session is already disconnected this should be a no-op.
56
"""Run deferred tasks."""
59
"""Flush the session and reset."""
62
"""Reset the session."""
64
def defer(func, *args, **kwargs):
65
"""Schedule something to happen when this session is finished."""
67
def getProducer(name):
68
"""Get a `IMessageProducer` associated with this session."""
70
def getConsumer(name):
71
"""Get a `IMessageConsumer` associated with this session."""
74
22
class IMessageConsumer(Interface):
76
23
def receive(blocking=True):
77
24
"""Receive data from the queue.
79
:raises EmptyQueue: If non-blocking and the queue is empty.
26
:raises EmptyQueueException: If non-blocking and the queue is empty.
83
33
class IMessageProducer(Interface):
86
36
"""Serialize `data` into JSON and send it to the queue on commit."""
89
39
"""Serialize `data` into JSON and send it to the queue immediately."""
91
44
def associateConsumer(consumer):
92
"""Make the consumer receive messages from this producer on commit.
94
:param consumer: An `IMessageConsumer`
97
def associateConsumerNow(consumer):
98
45
"""Make the consumer receive messages from this producer.
100
47
:param consumer: An `IMessageConsumer`
50
def disassociateConsumer(consumer):
51
"""Make the consumer stop receiving messages from this producer.
53
:param consumer: An `IMessageConsumer`