faust.channels
¶
Channel.
A channel is used to send values to streams.
The stream will iterate over incoming events in the channel.
-
class
faust.channels.
Channel
(app: faust.types.app.AppT, *, key_type: Union[Type[faust.types.models.ModelT], Type[bytes], Type[str]] = None, value_type: Union[Type[faust.types.models.ModelT], Type[bytes], Type[str]] = None, is_iterator: bool = False, queue: mode.utils.queues.ThrowableQueue = None, maxsize: int = None, root: faust.types.channels.ChannelT = None, active_partitions: Set[faust.types.tuples.TP] = None, loop: asyncio.events.AbstractEventLoop = None) → None[source]¶ Create new channel.
- Parameters
app (
AppT
[]) – The app that created this channel (app.channel()
)key_type (
Union
[Type
[ModelT
],Type
[bytes
],Type
[str
],None
]) – The Model used for keys in this channel.value_type (
Union
[Type
[ModelT
],Type
[bytes
],Type
[str
],None
]) – The Model used for values in this channel.maxsize (
Optional
[int
]) – The maximum number of messages this channel can hold. If exceeded any newput
call will block until a message is removed from the channel.is_iterator (
bool
) – When streams iterate over a channel they will callstream.clone(is_iterator=True)
so this attribute denotes that this channel instance is currently being iterated over.active_partition – Set of active topic partitions this channel instance is assigned to.
loop (
Optional
[AbstractEventLoop
]) – Theasyncio
event loop to use.
-
property
queue
¶ Return the underlying queue/buffer backing this channel. :rtype:
ThrowableQueue
-
clone
(*, is_iterator: bool = None, **kwargs) → faust.types.channels.ChannelT[source]¶ Create clone of this channel.
- Parameters
is_iterator (
Optional
[bool
]) – Set to True if this is now a channel that is being iterated over.- Keyword Arguments
**kwargs – Any keyword arguments passed will override any of the arguments supported by
Channel.__init__
.- Return type
ChannelT
[]
-
clone_using_queue
(queue: asyncio.queues.Queue) → faust.types.channels.ChannelT[source]¶ Create clone of this channel using specific queue instance.
- Return type
ChannelT
[]
-
stream
(**kwargs) → faust.types.streams.StreamT[source]¶ Create stream reading from this channel.
- Return type
StreamT
[+T_co]
-
get_topic_name
() → str[source]¶ Get the topic name, or raise if this is not a named channel.
- Return type
-
send_soon
(*, key: Union[bytes, faust.types.core._ModelT, Any, None] = None, value: Union[bytes, faust.types.core._ModelT, Any] = None, partition: int = None, timestamp: float = None, headers: Union[List[Tuple[str, bytes]], Mapping[str, bytes]] = None, key_serializer: Union[faust.types.codecs.CodecT, str, None] = None, value_serializer: Union[faust.types.codecs.CodecT, str, None] = None, callback: Callable[faust.types.tuples.FutureMessage, Union[None, Awaitable[None]]] = None, force: bool = False) → faust.types.tuples.FutureMessage[source]¶ Produce message by adding to buffer.
This method is only supported by
Topic
.- Raises
NotImplementedError – always for in-memory channel.
- Return type
-
as_future_message
(key: Union[bytes, faust.types.core._ModelT, Any, None] = None, value: Union[bytes, faust.types.core._ModelT, Any] = None, partition: int = None, timestamp: float = None, headers: Union[List[Tuple[str, bytes]], Mapping[str, bytes]] = None, key_serializer: Union[faust.types.codecs.CodecT, str, None] = None, value_serializer: Union[faust.types.codecs.CodecT, str, None] = None, callback: Callable[faust.types.tuples.FutureMessage, Union[None, Awaitable[None]]] = None) → faust.types.tuples.FutureMessage[source]¶ Create promise that message will be transmitted.
- Return type
-
prepare_headers
(headers: Union[List[Tuple[str, bytes]], Mapping[str, bytes], None]) → Union[List[Tuple[str, bytes]], MutableMapping[str, bytes]][source]¶ Prepare
headers
passed before publishing.
-
prepare_key
(key: Union[bytes, faust.types.core._ModelT, Any, None], key_serializer: Union[faust.types.codecs.CodecT, str, None]) → Any[source]¶ Prepare key before it is sent to this channel.
Topic
uses this to implement serialization of keys sent to the channel.- Return type
-
prepare_value
(value: Union[bytes, faust.types.core._ModelT, Any], value_serializer: Union[faust.types.codecs.CodecT, str, None]) → Any[source]¶ Prepare value before it is sent to this channel.
Topic
uses this to implement serialization of values sent to the channel.- Return type
-
on_stop_iteration
() → None[source]¶ Signal that iteration over this channel was stopped.
Tip
Remember to call
super
when overriding this method.- Return type
None
-
derive
(**kwargs) → faust.types.channels.ChannelT[source]¶ Derive new channel from this channel, using new configuration.
See
faust.Topic.derive
.For local channels this will simply return the same channel.
- Return type
ChannelT
[]