dxlclient.callbacks module¶
Classes for the different DXL message callbacks.
-
class
dxlclient.callbacks.
EventCallback
¶ Bases:
dxlclient.callbacks.MessageCallback
Concrete instances of this interface are used to receive
dxlclient.message.Event
messages.To receive events, a concrete instance of this callback must be created and registered with a
dxlclient.client.DxlClient
instance via thedxlclient.client.DxlClient.add_event_callback()
method.The following is a simple example of using an event callback:
from dxlclient.callbacks import EventCallback class MyEventCallback(EventCallback): def on_event(self, event): print("Received event! " + event.source_client_id) dxl_client.add_event_callback("/testeventtopic", MyEventCallback())
NOTE: By default when registering an event callback the client will automatically subscribe (
dxlclient.client.DxlClient.subscribe()
) to the topic.The following demonstrates a client that is sending an event message that would be received by the callback above.
from dxlclient.message import Event # Create the event message evt = Event("/testeventtopic") # Populate the event payload evt.payload = "testing".encode() # Send the event dxl_client.send_event(evt)
Constructor
-
on_event
(event)¶ Invoked when an
dxlclient.message.Event
has been received.Parameters: event -- The dxlclient.message.Event
message that was received
-
-
class
dxlclient.callbacks.
MessageCallback
¶ Bases:
dxlclient._BaseObject
Base class for the different callbacks
Constructor
-
class
dxlclient.callbacks.
RequestCallback
¶ Bases:
dxlclient.callbacks.MessageCallback
Concrete instances of this interface are used to receive
dxlclient.message.Request
messages.Request callbacks are typically used when implementing a "service".
See
dxlclient.service.ServiceRegistrationInfo
for more information on how to register a service.Constructor
-
on_request
(request)¶ Invoked when an
dxlclient.message.Request
has been received.Parameters: request -- The dxlclient.message.Request
message that was received
-
-
class
dxlclient.callbacks.
ResponseCallback
¶ Bases:
dxlclient.callbacks.MessageCallback
Concrete instances of this interface are used to receive
dxlclient.message.Response
messages.Response callbacks are typically used when invoking a service asynchronously.
The following is a simple example of using a response callback with an asynchronous service invocation:
from dxlclient.message import Request from dxlclient.callbacks import ResponseCallback class MyResponseCallback(ResponseCallback): def on_response(self, response): print("Received response! " + response.service_id) request = Request("/testservice/testrequesttopic") dxl_client.async_request(request, MyResponseCallback())
Constructor
-
on_response
(response)¶ Invoked when an
dxlclient.message.Response
has been received.Parameters: response -- The dxlclient.message.Response
message that was received
-