Crossbar Framework Application Component with Logging

  • Share this:

Code introduction


This code defines an application component based on the Crossbar framework, which accepts two arguments during initialization and logs messages upon start and stop.


Technology Stack : Crossbar, Python

Code Type : Crossbar Application Component

Code Difficulty : Intermediate


                
                    
def random_crossbar_function(arg1, arg2):
    import crossbar
    from crossbar.api import application
    from crossbar.api import component
    from crossbar.api import log

    class MyComponent(component.Component):
        def __init__(self, *args, **kwargs):
            super().__init__(*args, **kwargs)
            self.arg1 = arg1
            self.arg2 = arg2

        def on_start(self):
            self.log("Component started with args: {} and {}".format(self.arg1, self.arg2))

        def on_stop(self):
            self.log("Component stopped")

    @application()
    def my_application():
        MyComponent()

    crossbar.core.start()