crossbar.router.service

Classes

RouterServiceAgent

User router-realm service session, and WAMP meta API implementation.

Module Contents

class RouterServiceAgent(config: autobahn.wamp.types.ComponentConfig, router: crossbar.router.router.Router, schemas=None)[source]

Bases: autobahn.twisted.wamp.ApplicationSession

User router-realm service session, and WAMP meta API implementation.

Router service session which is used internally by a router to issue WAMP calls or publish events, and which provides WAMP meta API procedures.

_expose_on_sessions: List[Tuple[autobahn.wamp.interfaces.ISession, str | None, str | None]] = [][source]
_router[source]
_schemas[source]
log[source]
onJoin(details)[source]

Implements autobahn.wamp.interfaces.ISession.onJoin()

onLeave(details)[source]

Implements autobahn.wamp.interfaces.ISession.onLeave()

onUserError(failure, msg)[source]

Implements autobahn.wamp.interfaces.ISession.onUserError()

publish(topic, *args, **kwargs)[source]

Implements autobahn.wamp.interfaces.IPublisher.publish()

registration_count_callees(registration_id, details=None)[source]

Retrieve number of callees registered on (attached to) a registration.

Parameters:

registration_id (int) – The ID of the registration to get the number of callees for.

Returns:

Number of callees currently attached to the registration.

Return type:

int

registration_get(registration_id, details=None)[source]

Get registration details.

Parameters:

registration_id (int) – The ID of the registration to retrieve.

Returns:

The registration details.

Return type:

dict

registration_list(session_id=None, details=None)[source]

List current registrations.

Returns:

A dictionary with three entries for the match policies ‘exact’, ‘prefix’ and ‘wildcard’, with a list of registration IDs for each.

Return type:

dict

registration_list_callees(registration_id, details=None)[source]

Retrieve list of callees (WAMP session IDs) registered on (attached to) a registration.

Parameters:

registration_id (int) – The ID of the registration to get callees for.

Returns:

A list of WAMP session IDs of callees currently attached to the registration.

Return type:

list

registration_lookup(procedure, options=None, details=None)[source]

Given a procedure URI (and options), return the registration (if any) managing the procedure.

This essentially models what a dealer does when registering for a procedure.

Parameters:
  • procedure (str) – The procedure to lookup the registration for.

  • options (dict or None) – Same options as when registering a procedure.

Returns:

The ID of the registration managing the procedure or None.

Return type:

int or None

registration_match(procedure, details=None)[source]

Given a procedure URI, return the registration best matching the procedure.

This essentially models what a dealer does for dispatching an incoming call.

Parameters:

procedure (str) – The procedure to match.

Returns:

The best matching registration or None.

Return type:

obj or None

registration_remove_callee(registration_id, callee_id, reason=None, details=None)[source]

Forcefully remove callee from registration.

Parameters:
  • registration_id (int) – The ID of the registration to remove the callee from.

  • callee_id (int) – The WAMP session ID of the callee to remove.

schema_define(uri, schema, details=None)[source]

Declare metadata for a given URI.

Parameters:
  • uri (str) – The URI for which to declare metadata.

  • schema (dict) – The WAMP schema declaration for the URI or None to remove any declarations for the URI.

Returns:

None if declaration was unchanged, True if declaration was new, False if declaration existed, but was modified.

Return type:

bool or None

schema_describe(uri=None, details=None)[source]

Describe a given URI or all URIs.

Parameters:

uri (str) – The URI to describe or None to retrieve all declarations.

Returns:

A list of WAMP schema declarations.

Return type:

list

session_add_testament(topic, args, kwargs, publish_options=None, scope='destroyed', details=None)[source]

Add a testament to the current session.

Parameters:
  • topic (str) – The topic to publish the testament to.

  • args (list or tuple) – A list of arguments for the publish.

  • kwargs (dict) – A dict of keyword arguments for the publish.

  • publish_options (None or dict) – The publish options for the publish.

  • scope (str) – The scope of the testament, either “detached” or “destroyed”.

Returns:

The publication ID.

Return type:

int

session_count(filter_authroles=None, details=None)[source]

Count sessions currently joined on the router.

Parameters:

filter_authroles (None or list) – If provided, only count sessions with an authrole from this list.

Returns:

Count of joined sessions.

Return type:

int

session_flush_testaments(scope='destroyed', details=None)[source]

Flush the testaments of a given scope for the calling session.

Parameters:

scope (str) – The scope to flush, either “detached” or “destroyed”.

Returns:

Number of flushed testament events.

Return type:

int

session_get(session_id: int, details=None) Dict[str, Any] | None[source]

Get details for given session.

Example:

{'authextra': {'transport': {'channel_framing': 'websocket',
                             'channel_id': {},
                             'channel_serializer': None,
                             'channel_type': 'tcp',
                             'http_cbtid': 'y8pPyx+e8J9cYjdzFVWF/3/e',
                             'http_headers_received': {'cache-control': 'no-cache',
                                                       'connection': 'Upgrade',
                                                       'host': 'localhost:8080',
                                                       'pragma': 'no-cache',
                                                       'sec-websocket-extensions': 'permessage-deflate; '
                                                                                   'client_no_context_takeover; '
                                                                                   'client_max_window_bits',
                                                       'sec-websocket-key': '+jParRIjHXuCNGIWYKPtYQ==',
                                                       'sec-websocket-protocol': 'wamp.2.json',
                                                       'sec-websocket-version': '13',
                                                       'upgrade': 'WebSocket',
                                                       'user-agent': 'AutobahnPython/22.4.1.dev7'},
                             'http_headers_sent': {'Set-Cookie': 'cbtid=y8pPyx+e8J9cYjdzFVWF/3/e;max-age=604800'},
                             'is_secure': False,
                             'is_server': True,
                             'own': None,
                             'own_fd': -1,
                             'own_pid': 61066,
                             'own_tid': 61066,
                             'peer': 'tcp4:127.0.0.1:48638',
                             'peer_cert': None,
                             'websocket_extensions_in_use': [{'client_max_window_bits': 13,
                                                              'client_no_context_takeover': False,
                                                              'extension': 'permessage-deflate',
                                                              'is_server': True,
                                                              'mem_level': 5,
                                                              'server_max_window_bits': 13,
                                                              'server_no_context_takeover': False}],
                             'websocket_protocol': 'wamp.2.json'},
               'x_cb_node': 'intel-nuci7-61036',
               'x_cb_peer': 'unix',
               'x_cb_pid': 61045,
               'x_cb_worker': 'test_router1'},
 'authid': 'client1',
 'authmethod': 'anonymous-proxy',
 'authprovider': 'static',
 'authrole': 'frontend',
 'session': 8459804897712124,
 'transport': {'channel_framing': 'rawsocket',
               'channel_id': {},
               'channel_serializer': 'cbor',
               'channel_type': 'tcp',
               'http_cbtid': None,
               'http_headers_received': None,
               'http_headers_sent': None,
               'is_secure': False,
               'is_server': None,
               'own': None,
               'own_fd': -1,
               'own_pid': 61045,
               'own_tid': 61045,
               'peer': 'unix',
               'peer_cert': None,
               'websocket_extensions_in_use': None,
               'websocket_protocol': 'wamp.2.cbor'}}
Parameters:

session_id – The WAMP session ID to retrieve details for.

Returns:

WAMP session details.

session_kill(session_id, reason=None, message=None, details=None)[source]

Forcefully kill a session.

Parameters:
  • session_id (int) – The WAMP session ID of the session to kill.

  • reason (str or None) – A reason URI provided to the killed session.

  • message (str or None) – A message provided to the killed session.

session_kill_by_authid(authid, reason=None, message=None, details=None)[source]

Forcefully kill all sessions with given authid.

Parameters:
  • authid (str) – The WAMP authid of the sessions to kill.

  • reason (str or None) – A reason URI provided to the killed session(s).

  • message (str or None) – A message provided to the killed session(s).

session_kill_by_authrole(authrole, reason=None, message=None, details=None)[source]

Forcefully kill all sessions with given authrole.

Parameters:
  • authrole (str) – The WAMP authrole of the sessions to kill.

  • reason (str or None) – A reason URI provided to the killed session(s).

  • message (str or None) – A message provided to the killed session(s).

session_list(filter_authroles=None, details=None)[source]

Get list of session IDs of sessions currently joined on the router.

Parameters:

filter_authroles (None or list) – If provided, only return sessions with an authrole from this list.

Returns:

List of WAMP session IDs (order undefined).

Return type:

list

subscription_count_subscribers(subscription_id, details=None)[source]

Retrieve number of subscribers subscribed on (attached to) a subscription.

Parameters:

subscription_id (int) – The ID of the subscription to get the number subscribers for.

Returns:

Number of subscribers currently attached to the subscription.

Return type:

int

subscription_get(subscription_id, details=None)[source]

Get subscription details.

Parameters:

subscription_id (int) – The ID of the subscription to retrieve.

Returns:

The subscription details.

Return type:

dict

subscription_get_events(subscription_id, limit=10, details=None)[source]

Return history of events for given subscription.

Parameters:
  • subscription_id (int) – The ID of the subscription to get events for.

  • limit (int) – Return at most this many events.

Returns:

List of events.

Return type:

list

subscription_list(session_id=None, details=None)[source]

List current subscriptions.

Returns:

A dictionary with three entries for the match policies ‘exact’, ‘prefix’ and ‘wildcard’, with a list of subscription IDs for each.

Return type:

dict

subscription_list_subscribers(subscription_id, details=None)[source]

Retrieve list of subscribers (WAMP session IDs) subscribed on (attached to) a subscription.

Parameters:

subscription_id (int) – The ID of the subscription to get subscribers for.

Returns:

A list of WAMP session IDs of subscribers currently attached to the subscription.

Return type:

list

subscription_lookup(topic, options=None, details=None)[source]

Given a topic URI (and options), return the subscription (if any) managing the topic.

This essentially models what a broker does when subscribing for a topic.

Parameters:
  • topic (str) – The topic to lookup the subscription for.

  • options (dict or None) – Same options as when subscribing to a topic.

Returns:

The ID of the subscription managing the topic or None.

Return type:

int or None

subscription_match(topic, details=None)[source]

Given a topic URI, returns all subscriptions matching the topic.

This essentially models what a broker does for dispatching an incoming publication.

Parameters:

topic (str) – The topic to match.

Returns:

All matching subscriptions or None.

Return type:

obj or None

subscription_remove_subscriber(subscription_id, subscriber_id, reason=None, details=None)[source]

Forcefully remove subscriber from subscription.

Parameters:
  • subscription_id (int) – The ID of the subscription to remove the subscriber from.

  • subscriber_id (int) – The WAMP session ID of the subscriber to remove.