Skip to content

Latest commit

 

History

History
50 lines (34 loc) · 2.18 KB

README.adoc

File metadata and controls

50 lines (34 loc) · 2.18 KB

Application Layer APIs (uP-L3 Interface)

The following module includes the client-facing Application Layer (uP-L3) interfaces to communication with USubscription, UDiscovery, and UTwin services.

uP-L3 Interfaces

Table 1. Interfaces (uP-L3 Interface)
Interface Implementation(s) Description

USubscriptionClient

InMemoryUSubscriptionClient

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.

Examples

Subscribe and Unsubscribe

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)