The following module includes the client-facing Application Layer (uP-L3) interfaces to communication with USubscription, UDiscovery, and UTwin services.
Interface | Implementation(s) | Description |
---|---|---|
Subscription Management APIs to subscribe(), unsubscribe() and fetch information from the subscription database. |
The module includes the interface for the client-facing APIs as well as a simple in-memory implementation that is based on the uP-L2 in-memory implementations. the term in-memory is used to indicate that the data required by the code is cached inside of the object and not persisted to a given database backend, this design is useful for embedded applications (i.e. in the vehicle) however will not scale to the multi-tenanted cloud applications.
transport = # your UTransport instance
#subscription topic
topic : UUri = UUri( ue_id=4, ue_version_major=1, resource_id=0x8000)
#Listener to process incoming events on the topic
class MySubscriptionListener(UListener):
def on_receive(self, umsg: UMessage) -> None:
# Handle receiving published message
pass
listener = MySubscriptionListener()
# Optional handler that is called whenever the SubscriptionState changes for the subscriber
class MySubscriptionChangeHandler(SubscriptionChangeHandler)
def handle_subscription_change(self, topic: UUri, status: SubscriptionStatus) -> None:
# Handle subscription status changes if you're interested like when
# the subscription state changes from SUBSCRIBE_PENDING to SUBSCRIBED
pass
subscriber : InMemoryUSubscriptionClient = InMemoryUSubscriptionClient(transport)
response : SubscriptionResponse = subscriber.subscribe(topic, listener, CallOptions.DEFAULT, MySubscriptionChangeHandler())
#UnSubscribe from the topic
status : UStatus = subscriber.unsubscribe(topic, listener)