Module autobahn.wamp.component
¶
Component¶
This is common code for both Twisted and asyncio components; see either autobahn.twisted.component.Component
or autobahn.asyncio.component.Component
for the concrete implementations.
- class autobahn.wamp.component.Component(main=None, transports=None, config=None, realm='realm1', extra=None, authentication=None, session_factory=None, is_fatal=None)[source]¶
A WAMP application component. A component holds configuration for (and knows how to create) transports and sessions.
- Parameters
main (callable taking two args
reactor
andISession
) – After a transport has been connected and a session has been established and joined to a realm, this (async) procedure will be run until it finishes – which signals that the component has run to completion. In this case, it usually doesn’t make sense to use theon_*
kwargs. If you do not pass a main() procedure, the session will not be closed (unless you arrange for .leave() to be called).transports (None or str or list) –
Transport configurations for creating transports. Each transport can be a WAMP URL, or a dict containing the following configuration keys:
type
(optional):websocket
(default) orrawsocket
url
: the router URLendpoint
(optional, derived from URL if not provided):type
: “tcp” or “unix”host
,port
: only for TCPpath
: only for unixtimeout
: in secondstls
:True
or (under Twisted) antwisted.internet.ssl.IOpenSSLClientComponentCreator
instance (such as returned fromtwisted.internet.ssl.optionsForClientTLS
) orCertificateOptions
instance.
max_retries
: Maximum number of reconnection attempts. Unlimited if set to -1.initial_retry_delay
: Initial delay for reconnection attempt in seconds (Default: 1.0s).max_retry_delay
: Maximum delay for reconnection attempts in seconds (Default: 60s).retry_delay_growth
: The growth factor applied to the retry delay between reconnection attempts (Default 1.5).retry_delay_jitter
: A 0-argument callable that introduces nose into the delay. (Default random.random)serializer
(only for raw socket): Specify an accepted serializer (e.g. ‘json’, ‘msgpack’, ‘cbor’, ‘ubjson’, ‘flatbuffers’)serializers
: Specify list of accepted serializersoptions
: tbdproxy
: tbd
realm (str) – the realm to join
authentication (dict) – configuration of authenticators
session_factory – if None,
ApplicationSession
is used, otherwise a callable taking a singleconfig
argument that is used to create a new ApplicationSession instance.is_fatal – a callable taking a single argument, an
Exception
instance. The callable should returnTrue
if this error is “fatal”, meaning we should not try connecting to the current transport again. The default behavior (on None) is to always returnFalse
- on_join(fn)[source]¶
A decorator as a shortcut for listening for ‘join’ events.
For example:
@component.on_join def joined(session, details): print("Session {} joined: {}".format(session, details))
- register(uri, options=None, check_types=False)[source]¶
A decorator as a shortcut for registering during on-join
For example:
@component.register( "com.example.add", options=RegisterOptions(invoke='roundrobin'), ) def add(*args, **kw): print("add({}, {}): event received".format(args, kw))
- session_factory = None¶
The factory of the session we will instantiate.