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 and ISession) – 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 the on_* 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) or rawsocket

    • url: the router URL

    • endpoint (optional, derived from URL if not provided):
      • type: “tcp” or “unix”

      • host, port: only for TCP

      • path: only for unix

      • timeout: in seconds

      • tls: True or (under Twisted) an twisted.internet.ssl.IOpenSSLClientComponentCreator instance (such as returned from twisted.internet.ssl.optionsForClientTLS) or CertificateOptions 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 serializers

    • options: tbd

    • proxy: tbd

  • realm (str) – the realm to join

  • authentication (dict) – configuration of authenticators

  • session_factory – if None, ApplicationSession is used, otherwise a callable taking a single config argument that is used to create a new ApplicationSession instance.

  • is_fatal – a callable taking a single argument, an Exception instance. The callable should return True if this error is “fatal”, meaning we should not try connecting to the current transport again. The default behavior (on None) is to always return False

on_connect(fn)[source]

A decorator as a shortcut for listening for ‘connect’ events.

on_connectfailure(fn)[source]

A decorator as a shortcut for listening for ‘connectfailure’ events.

on_disconnect(fn)[source]

A decorator as a shortcut for listening for ‘disconnect’ events.

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))
on_leave(fn)[source]

A decorator as a shortcut for listening for ‘leave’ events.

on_ready(fn)[source]

A decorator as a shortcut for listening for ‘ready’ events.

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.

subscribe(topic, options=None, check_types=False)[source]

A decorator as a shortcut for subscribing during on-join

For example:

@component.subscribe(
    "some.topic",
    options=SubscribeOptions(match='prefix'),
)
def topic(*args, **kw):
    print("some.topic({}, {}): event received".format(args, kw))