crossbar.bridge.mqtt.wamp

Attributes

Classes

WampMQTTServerFactory

This is a factory which produces protocols.

WampMQTTServerProtocol

This is the base class for streaming connection-oriented protocols.

WampTransport

Functions

_mqtt_topicfilter_to_wamp(topic)

Convert a MQTT topic as used in MQTT Subscribe (and hence ptoentially containing

_mqtt_topicname_to_wamp(topic)

Convert a MQTT topic as used in MQTT Publish to a WAMP URI.

_wamp_topic_to_mqtt(topic)

Convert a WAMP URI as used in WAMP Publish to a MQTT topic.

Module Contents

class WampMQTTServerFactory(router_session_factory, config, reactor)[source]

Bases: twisted.internet.protocol.Factory

This is a factory which produces protocols.

By default, buildProtocol will create a protocol of the class given in self.protocol.

_get_payload_format(topic)[source]

Map a WAMP topic URI to MQTT payload format. :param topic: WAMP URI. :type topic: str

Returns:

Payload format metadata.

Return type:

dict

_options[source]
_payload_mapping[source]
_reactor[source]
_realm[source]
_router_factory[source]
_router_session_factory[source]
_set_payload_format(topic, pmap=None)[source]
_transform_mqtt_dynamic(decoder, codec_realm, mapped_topic, topic, payload)[source]
_transform_mqtt_native(serializer, payload)[source]

Transform MQTT binary payload from a MQTT Publish to keyword dict suitable for the constructor of a WAMP Publish message, that is autobahn.wamp.message.Publish.

_transform_wamp_dynamic(encoder, codec_realm, mapped_topic, topic, msg)[source]
_transform_wamp_native(serializer, msg)[source]
buildProtocol(addr)[source]

Create an instance of a subclass of Protocol.

The returned instance will handle input on an incoming server connection, and an attribute “factory” pointing to the creating factory.

Alternatively, L{None} may be returned to immediately close the new connection.

Override this method to alter how Protocol instances get created.

@param addr: an object implementing L{IAddress}

log[source]
protocol[source]
serializers[source]
transform_mqtt(topic, payload)[source]
transform_wamp(topic, msg)[source]
class WampMQTTServerProtocol(reactor)[source]

Bases: twisted.internet.protocol.Protocol

This is the base class for streaming connection-oriented protocols.

If you are going to write a new connection-oriented protocol for Twisted, start here. Any protocol implementation, either client or server, should be a subclass of this class.

The API is quite simple. Implement L{dataReceived} to handle both event-based and synchronous input; output can be sent through the ‘transport’ attribute, which is to be an instance that implements L{twisted.internet.interfaces.ITransport}. Override C{connectionLost} to be notified when the connection ends.

Some subclasses exist already to help you write common types of protocols: see the L{twisted.protocols.basic} module for a few of them.

_inflight_subscriptions[source]
_mqtt[source]
_on_message(inc_msg)[source]
_publish(event, acknowledge=None)[source]

Given a MQTT event, create a WAMP Publish message and forward that on the forwarding WAMP session.

_request_to_packetid[source]
_subrequest_callbacks[source]
_subrequest_to_mqtt_subrequest[source]
_topic_lookup[source]
_waiting_for_connect = None[source]
_wamp_session = None[source]
_when_ready()[source]
connectionLost(reason)[source]

Called when the connection is shut down.

Clear any circular references here, and any external references to this Protocol. The connection has been closed.

@type reason: L{twisted.python.failure.Failure}

connectionMade(ignore_handshake=False)[source]

Called when a connection is made.

This may be considered the initializer of the protocol, because it is called when the connection is completed. For clients, this is called once the connection to the server has been established; for servers, this is called after an accept() call stops blocking and a socket has been received. If you need to send any greeting or initial message, do it here.

dataReceived(data)[source]

Called whenever data is received.

Use this method to translate to a higher-level message. Usually, some callback will be made upon the receipt of each complete protocol message.

@param data: a string of indeterminate length. Please keep in mind

that you will probably need to buffer some data, as partial (or multiple) protocol messages may be received! I recommend that unit tests for protocols call through to this method with differing chunk sizes, down to one byte at a time.

handshakeCompleted()[source]
log[source]
on_message(inc_msg)[source]
process_connect(packet)[source]

Process the initial Connect message from the MQTT client.

This should return a pair (accept_conn, session_present), where accept_conn is a return code:

0: connection accepted 1-5: connection refused (see MQTT spec 3.2.2.3)

process_puback(event)[source]
process_pubcomp(event)[source]
process_publish_qos_0(event)[source]
process_publish_qos_1(event)[source]
process_pubrec(event)[source]
process_pubrel(event)[source]
process_subscribe(packet)[source]
process_unsubscribe(packet)[source]
class WampTransport(factory, on_message, real_transport)[source]

Bases: object

_authid = None[source]
factory[source]
on_message[source]
send(msg)[source]
transport[source]
transport_details[source]
_mqtt_topicfilter_to_wamp(topic)[source]

Convert a MQTT topic as used in MQTT Subscribe (and hence ptoentially containing special characters “+” and “#”) to a WAMP URI and a match policy.

_mqtt_topicname_to_wamp(topic)[source]

Convert a MQTT topic as used in MQTT Publish to a WAMP URI.

_validator[source]
_wamp_topic_to_mqtt(topic)[source]

Convert a WAMP URI as used in WAMP Publish to a MQTT topic.