Upgrade to Pro — share decks privately, control downloads, hide ads and more …

WAMP as a platform for composite SOA applications and its implementation on Lua

WAMP as a platform for composite SOA applications and its implementation on Lua

WAMP stands for Web Application Messaging Protocol. This is an open protocol that implements two patterns within a single protocol: RPC and Publish / Subscribe. As it seems to me, this is a great platform for the Internet of Things, Smart City and in general business applications with a lot of different components and services.

Konstantin Burkalev

December 13, 2017
Tweet

More Decks by Konstantin Burkalev

Other Decks in Programming

Transcript

  1. WAMP as a platform
    for composite SOA
    applications and its
    implementation on Lua
    Konstantin Burkalev
    @KSDaemon

    View full-size slide

  2. Few words about me…
    2
    • Software architect
    • 15+ years in IT
    • Author and host of podcasts: SDCast & RadioJS
    • Active member of WAMP protocol development group
    • Author and maintainer of a few WAMP implementations,
    some of them are written in Lua

    View full-size slide

  3. Talk plan
    Example of system using WAMP
    What is WAMP and how it works
    WAMP as basis for SOA applications
    Application fields
    WAMP client in Lua
    WAMP router in Nginx/Lua
    3

    View full-size slide

  4. Task: Smart Home System
    4

    View full-size slide

  5. Living room
    Task: Smart Home System
    4

    View full-size slide

  6. Living room
    Task: Smart Home System
    4

    View full-size slide

  7. Living room
    Task: Smart Home System
    4

    View full-size slide

  8. Bath room
    Living room
    Task: Smart Home System
    4

    View full-size slide

  9. Bath room
    Living room
    Task: Smart Home System
    4

    View full-size slide

  10. Bath room
    Living room
    Task: Smart Home System
    4

    View full-size slide

  11. Bath room
    Living room
    Task: Smart Home System
    4
    User

    View full-size slide

  12. Bath room
    Living room
    Task: Smart Home System
    4
    User

    View full-size slide

  13. The temperature sensor detects
    the temperature raise
    Bath room
    Living room
    Task: Smart Home System
    4
    User

    View full-size slide

  14. The client is notified
    Logged in database
    Bath room
    Living room
    Task: Smart Home System
    4
    User

    View full-size slide

  15. The client is notified
    Logged in database
    Bath room
    Living room
    Task: Smart Home System
    4
    User

    View full-size slide

  16. The system turns on air conditioning
    Bath room
    Living room
    Task: Smart Home System
    4
    User

    View full-size slide

  17. The temperature in the room decreases
    Bath room
    Living room
    Task: Smart Home System
    4
    User

    View full-size slide

  18. Bath room
    Living room
    Task: Smart Home System
    4
    User

    View full-size slide

  19. Bath room
    Living room
    Task: Smart Home System
    4
    User

    View full-size slide

  20. The system turns off the air conditioning
    Bath room
    Living room
    Task: Smart Home System
    4
    User

    View full-size slide

  21. The system turns off the air conditioning
    Bath room
    Living room
    Task: Smart Home System
    4
    User

    View full-size slide

  22. The humidity in the bathroom rises
    Bath room
    Living room
    Task: Smart Home System
    4
    User

    View full-size slide

  23. The client is notified
    Logged in database
    Bath room
    Living room
    Task: Smart Home System
    4
    User

    View full-size slide

  24. The client is notified
    Logged in database
    Bath room
    Living room
    Task: Smart Home System
    4
    User

    View full-size slide

  25. The system turns on a fan
    Bath room
    Living room
    Task: Smart Home System
    4
    User

    View full-size slide

  26. The system turns on a fan
    Bath room
    Living room
    Task: Smart Home System
    4
    User

    View full-size slide

  27. The humidity in the bathroom drops
    Bath room
    Living room
    Task: Smart Home System
    4
    User

    View full-size slide

  28. Bath room
    Living room
    Task: Smart Home System
    4
    User

    View full-size slide

  29. Bath room
    Living room
    Task: Smart Home System
    4
    User

    View full-size slide

  30. The system turns off the fan
    Bath room
    Living room
    Task: Smart Home System
    4
    User

    View full-size slide

  31. The system turns off the fan
    Bath room
    Living room
    Task: Smart Home System
    4
    User

    View full-size slide

  32. Bath room
    Living room
    Task: Smart Home System
    4
    User
    Admin

    View full-size slide

  33. Admin configures threshold values
    Bath room
    Living room
    Task: Smart Home System
    4
    User
    Admin

    View full-size slide

  34. Admin searches new devices
    Bath room
    Living room
    Task: Smart Home System
    4
    User
    Admin

    View full-size slide

  35. The system informs about
    found devices
    Bath room
    Living room
    Task: Smart Home System
    4
    User
    Admin

    View full-size slide

  36. The system informs about
    found devices
    Bath room
    Living room
    Task: Smart Home System
    4
    User
    Admin

    View full-size slide

  37. Bath room
    Living room
    Task: Smart Home System
    4
    User
    Admin

    View full-size slide

  38. What is WAMP
    5

    View full-size slide

  39. What is WAMP
    • It stands for "Web Application Messaging Protocol"
    5

    View full-size slide

  40. What is WAMP
    • It stands for "Web Application Messaging Protocol"
    • Is intended for communication between software components in
    near real-time
    5

    View full-size slide

  41. What is WAMP
    • It stands for "Web Application Messaging Protocol"
    • Is intended for communication between software components in
    near real-time
    • Provides two mechanisms:
    • Publish/Subscribe (PubSub)
    • Remote Procedure Calls (RPC)
    5

    View full-size slide

  42. What is WAMP
    • It stands for "Web Application Messaging Protocol"
    • Is intended for communication between software components in
    near real-time
    • Provides two mechanisms:
    • Publish/Subscribe (PubSub)
    • Remote Procedure Calls (RPC)
    • Bi-directional, ordered
    5

    View full-size slide

  43. What is WAMP
    • It stands for "Web Application Messaging Protocol"
    • Is intended for communication between software components in
    near real-time
    • Provides two mechanisms:
    • Publish/Subscribe (PubSub)
    • Remote Procedure Calls (RPC)
    • Bi-directional, ordered
    • For communication between clients is required WAMP-router
    5

    View full-size slide

  44. Why WAMP?
    • Open specification
    6

    View full-size slide

  45. Why WAMP?
    • Open specification
    • Thoughtful Publish / Subscribe
    6

    View full-size slide

  46. Why WAMP?
    • Open specification
    • Thoughtful Publish / Subscribe
    • Thoughtful Remote Procedure Calls
    6

    View full-size slide

  47. Why WAMP?
    • Open specification
    • Thoughtful Publish / Subscribe
    • Thoughtful Remote Procedure Calls
    • Message routing
    6

    View full-size slide

  48. Why WAMP?
    • Open specification
    • Thoughtful Publish / Subscribe
    • Thoughtful Remote Procedure Calls
    • Message routing
    • Cross-platform
    6

    View full-size slide

  49. Why WAMP?
    • Open specification
    • Thoughtful Publish / Subscribe
    • Thoughtful Remote Procedure Calls
    • Message routing
    • Cross-platform
    • There are implementations in more than 15 languages
    6

    View full-size slide

  50. WAMP alternatives
    7
    Technology PubSub RPC
    Routed
    RPC
    Web native
    Cross
    Language
    Open
    Standard
    WAMP ✔ ✔ ✔ ✔ ✔ ✔
    AJAX - ✔ - ✔ ✔ -
    AMQP ✔ (✔) - - ✔ ✔
    Java JMS ✔ - - - - ✔
    JSON-RPC - ✔ - ✔ ✔ ✔
    MQTT ✔ - - - ✔ ✔
    REST - ✔ - ✔ ✔ -
    SOAP - ✔ - ✔ ✔ ✔
    socket.io ✔ - - ✔ - -
    XMPP ✔ - - ✔ ✔ ✔
    ZMQ ✔ - - - ✔ -

    View full-size slide

  51. WAMP: message examples
    8

    View full-size slide

  52. WAMP architecture
    9

    View full-size slide

  53. WAMP architecture
    10
    Client.
    Can provide
    or consume
    resources such as
    subscriptions and RPC.

    View full-size slide

  54. WAMP architecture
    11
    Router.
    Deals with
    authorization and
    routing
    messages
    between clients.

    View full-size slide

  55. WAMP architecture
    12
    Peer.
    Can be a client
    or a router,
    must have
    at least one role.

    View full-size slide

  56. WAMP architecture
    13
    Role.
    Defines
    features of the node.
    There are 4 client roles
    and 2 roles of the router.

    View full-size slide

  57. WAMP architecture
    14
    Session.
    It is necessary for
    identification and
    authorization of clients,
    announce the roles
    of nodes.

    View full-size slide

  58. WAMP architecture
    15
    Realm.
    domain, namespace,
    single space
    within which
    resources
    and message routing
    takes place.

    View full-size slide

  59. WAMP architecture
    16
    Transport.
    You can use:
    Websocket, Raw TCP,
    Unix sockets and even
    HTTP Long poll.

    View full-size slide

  60. WAMP architecture
    17
    Serializer.
    All messages are
    serialized using
    JSON/MessagePack/
    CBOR.
    message

    View full-size slide

  61. WAMP architecture
    18
    Resource
    identifiers, URI.
    Required for
    topics, procedures
    and errors.
    For example:
    Topic: «sensor.events»
    RPC: «discover.devices»
    message

    View full-size slide

  62. Basic WAMP concepts
    19

    View full-size slide

  63. Basic WAMP concepts
    • Client. Can provide or consume resources, such as subscriptions and RPC.
    • Router. Deals with authorization and message routing between clients.
    • Peer. Can be a client or a router, must have at least one role.
    • Role. Determines the capabilities of the node. There are 4 client roles and 2 router roles.
    • Session. It is necessary to identify and authorize clients, announce the role of nodes.
    • Realm. Domain, namespace, within which messages are routed.
    • Transport. You can use: WebSockets, Raw TCP, Unix sockets and even HTTP Long poll.
    • Serializer. Messages are serialized using JSON / MessagePack / CBOR / etc.
    • Resource identifiers, URIs. Required for topics, procedures and errors.
    19

    View full-size slide

  64. WAMP: Features
    20

    View full-size slide

  65. WAMP: Features
    • Basic profile: basic features of RPC and PubSub
    20

    View full-size slide

  66. WAMP: Features
    • Basic profile: basic features of RPC and PubSub
    • Advanced profile:
    20

    View full-size slide

  67. WAMP: Features
    • Basic profile: basic features of RPC and PubSub
    • Advanced profile:
    • Challenge-Response Authentication
    • Progressive call results, call timeout, call canceling
    • Publication / call trust levels
    • Caller / publisher identification
    • Pattern based registration / subscription
    • Shared registration, sharded registration / subscription
    • Event history
    • Meta API & Procedure / topic reflection
    20

    View full-size slide

  68. WAMP: session establishment
    21
    Client Router
    Realm

    View full-size slide

  69. WAMP: session establishment
    21
    HELLO
    Client Router
    Realm
    [1, "homeapp", { "roles": { "publisher": {}, "subscriber": {} } }]

    View full-size slide

  70. WAMP: session establishment
    21
    HELLO
    WELCOME
    Client Router
    Realm
    [2, 9129137332, { "roles": { "broker": {} } }]

    View full-size slide

  71. WAMP: session establishment
    21
    HELLO
    WELCOME
    ABORT
    Client Router
    Realm
    [3, {"message": "The realm does not exist."}, "wamp.error.no_such_realm"]

    View full-size slide

  72. WAMP: session establishment
    21
    HELLO
    WELCOME
    GOODBYE (init by client)
    ABORT
    Client Router
    Realm
    [6, {"message": "The host is shutting down now."}, "wamp.error.system_shutdown"]

    View full-size slide

  73. WAMP: session establishment
    21
    HELLO
    WELCOME
    GOODBYE (init by client)
    ABORT
    GOODBYE
    Client Router
    Realm
    [6, {}, "wamp.error.goodbye_and_out"]

    View full-size slide

  74. WAMP: session establishment
    21
    HELLO
    WELCOME
    GOODBYE (init by client)
    ABORT
    GOODBYE
    GOODBYE (init by router)
    Client Router
    Realm
    [6, {}, "wamp.error.close_realm"]

    View full-size slide

  75. WAMP: session establishment
    21
    HELLO
    WELCOME
    GOODBYE (init by client)
    ABORT
    GOODBYE
    GOODBYE
    GOODBYE (init by router)
    Client Router
    Realm
    [6, {}, "wamp.error.goodbye_and_out"]

    View full-size slide

  76. WAMP: session establishment
    21
    HELLO
    WELCOME
    GOODBYE (init by client)
    ABORT
    GOODBYE
    GOODBYE
    GOODBYE (init by router)
    Client Router
    Realm

    View full-size slide

  77. WAMP: Publish / Subscribe
    22
    Publisher Broker Subscriber
    Realm

    View full-size slide

  78. WAMP: Publish / Subscribe
    22
    SUBSCRIBE
    Publisher Broker Subscriber
    Realm
    [32, 713845233, {}, "sensor.events"]

    View full-size slide

  79. WAMP: Publish / Subscribe
    22
    SUBSCRIBE
    SUBSCRIBED
    Publisher Broker Subscriber
    Realm
    [33, 713845233, 5512315355]

    View full-size slide

  80. WAMP: Publish / Subscribe
    22
    SUBSCRIBE
    SUBSCRIBED
    ERROR
    Publisher Broker Subscriber
    Realm
    [8, 32, 713845233, {}, "wamp.error.not_authorized"]

    View full-size slide

  81. WAMP: Publish / Subscribe
    22
    SUBSCRIBE
    SUBSCRIBED
    ERROR
    PUBLISH
    Publisher Broker Subscriber
    Realm
    [16, 239714735, {}, "sensor.events", [], {"sensorId ": 25, "temp": 27}]

    View full-size slide

  82. WAMP: Publish / Subscribe
    22
    SUBSCRIBE
    SUBSCRIBED
    ERROR
    PUBLISH
    PUBLISHED
    Publisher Broker Subscriber
    Realm
    [17, 239714735, 4429313566]

    View full-size slide

  83. WAMP: Publish / Subscribe
    22
    SUBSCRIBE
    SUBSCRIBED
    ERROR
    PUBLISH
    PUBLISHED
    ERROR
    Publisher Broker Subscriber
    Realm
    [8, 16, 239714735, {}, "wamp.error.not_authorized"]

    View full-size slide

  84. WAMP: Publish / Subscribe
    22
    SUBSCRIBE
    SUBSCRIBED
    ERROR
    PUBLISH
    PUBLISHED
    ERROR
    EVENT
    Publisher Broker Subscriber
    Realm
    [36, 5512315355, 4429313566, {}, [], {"sensorId ": 25, "temp": 27}]

    View full-size slide

  85. WAMP: Publish / Subscribe
    22
    SUBSCRIBE
    SUBSCRIBED
    UNSUBSCRIBE
    ERROR
    PUBLISH
    PUBLISHED
    ERROR
    EVENT
    Publisher Broker Subscriber
    Realm
    [34, 85346237, 5512315355]

    View full-size slide

  86. WAMP: Publish / Subscribe
    22
    SUBSCRIBE
    SUBSCRIBED
    UNSUBSCRIBE
    UNSUBSCRIBED
    ERROR
    PUBLISH
    PUBLISHED
    ERROR
    EVENT
    Publisher Broker Subscriber
    Realm
    [35, 85346237]

    View full-size slide

  87. WAMP: Publish / Subscribe
    22
    SUBSCRIBE
    SUBSCRIBED
    UNSUBSCRIBE
    UNSUBSCRIBED
    ERROR
    ERROR
    PUBLISH
    PUBLISHED
    ERROR
    EVENT
    Publisher Broker Subscriber
    Realm
    [8, 34, 85346237, {}, "wamp.error.no_such_subscription"]

    View full-size slide

  88. WAMP: Publish / Subscribe
    22
    SUBSCRIBE
    SUBSCRIBED
    UNSUBSCRIBE
    UNSUBSCRIBED
    ERROR
    ERROR
    PUBLISH
    PUBLISHED
    ERROR
    EVENT
    Publisher Broker Subscriber
    Realm

    View full-size slide

  89. WAMP: Remote Procedure Calls
    23
    Caller Dealer Callee
    Realm

    View full-size slide

  90. WAMP: Remote Procedure Calls
    23
    Caller Dealer Callee
    REGISTER
    Realm
    [64, 25349185, {}, "dcs.fan.control"]

    View full-size slide

  91. WAMP: Remote Procedure Calls
    23
    Caller Dealer Callee
    REGISTER
    REGISTERED
    Realm
    [65, 25349185, 2103333224]

    View full-size slide

  92. WAMP: Remote Procedure Calls
    23
    Caller Dealer Callee
    REGISTER
    REGISTERED
    ERROR
    Realm
    [8, 64, 25349185, {}, "wamp.error.procedure_already_exists"]

    View full-size slide

  93. WAMP: Remote Procedure Calls
    23
    Caller Dealer Callee
    REGISTER
    REGISTERED
    ERROR
    CALL
    Realm
    [48, 7814135, {}, "dcs.fan.control", [true]]

    View full-size slide

  94. WAMP: Remote Procedure Calls
    23
    Caller Dealer Callee
    REGISTER
    REGISTERED
    ERROR
    CALL
    INVOCATION
    Realm
    [68, 6131533, 9823528, {}, [true]]

    View full-size slide

  95. WAMP: Remote Procedure Calls
    23
    Caller Dealer Callee
    REGISTER
    REGISTERED
    ERROR
    CALL
    INVOCATION
    YIELD
    Realm
    [70, 6131533, {}]

    View full-size slide

  96. WAMP: Remote Procedure Calls
    23
    Caller Dealer Callee
    REGISTER
    REGISTERED
    ERROR
    CALL
    RESULT
    INVOCATION
    YIELD
    Realm
    [50, 7814135, {}]

    View full-size slide

  97. WAMP: Remote Procedure Calls
    23
    Caller Dealer Callee
    REGISTER
    REGISTERED
    ERROR
    CALL
    RESULT
    INVOCATION
    YIELD
    ERROR
    Realm
    [8, 68, 6131533, {}, "homeapp.error.hardware_not_found"]

    View full-size slide

  98. WAMP: Remote Procedure Calls
    23
    Caller Dealer Callee
    REGISTER
    REGISTERED
    ERROR
    CALL
    RESULT
    INVOCATION
    YIELD
    ERROR
    ERROR
    Realm
    [8, 48, 7814135, {}, "homeapp.error.hardware_not_found"]

    View full-size slide

  99. WAMP: Remote Procedure Calls
    23
    Caller Dealer Callee
    REGISTER
    REGISTERED
    UNREGISTER
    ERROR
    CALL
    RESULT
    INVOCATION
    YIELD
    ERROR
    ERROR
    Realm
    [66, 788923562, 2103333224]

    View full-size slide

  100. WAMP: Remote Procedure Calls
    23
    Caller Dealer Callee
    REGISTER
    REGISTERED
    UNREGISTER
    UNREGISTERED
    ERROR
    CALL
    RESULT
    INVOCATION
    YIELD
    ERROR
    ERROR
    Realm
    [67, 788923562]

    View full-size slide

  101. WAMP: Remote Procedure Calls
    23
    Caller Dealer Callee
    REGISTER
    REGISTERED
    UNREGISTER
    UNREGISTERED
    ERROR
    ERROR
    CALL
    RESULT
    INVOCATION
    YIELD
    ERROR
    ERROR
    Realm
    [8, 66, 788923562, {}, "wamp.error.no_such_registration"]

    View full-size slide

  102. WAMP: Remote Procedure Calls
    23
    Caller Dealer Callee
    REGISTER
    REGISTERED
    UNREGISTER
    UNREGISTERED
    ERROR
    ERROR
    CALL
    RESULT
    INVOCATION
    YIELD
    ERROR
    ERROR
    Realm

    View full-size slide

  103. WAMP as a basis for SOA applications
    24

    View full-size slide

  104. WAMP as a basis for SOA applications
    Distributed architecture
    24

    View full-size slide

  105. WAMP as a basis for SOA applications
    Distributed architecture
    Loose coupling of components
    24

    View full-size slide

  106. WAMP as a basis for SOA applications
    Distributed architecture
    Loose coupling of components
    A simple and intuitive interface for interaction
    24

    View full-size slide

  107. WAMP as a basis for SOA applications
    Distributed architecture
    Loose coupling of components
    A simple and intuitive interface for interaction
    Unified Routing
    24

    View full-size slide

  108. WAMP as a basis for SOA applications
    Distributed architecture
    Loose coupling of components
    A simple and intuitive interface for interaction
    Unified Routing
    Independence from programming language
    24

    View full-size slide

  109. WAMP as a basis for SOA applications
    Distributed architecture
    Loose coupling of components
    A simple and intuitive interface for interaction
    Unified Routing
    Independence from programming language
    Re-usability of components
    24

    View full-size slide

  110. WAMP as a basis for SOA applications
    Distributed architecture
    Loose coupling of components
    A simple and intuitive interface for interaction
    Unified Routing
    Independence from programming language
    Re-usability of components
    WAMP satisfies the requirements of SOA
    24

    View full-size slide

  111. WAMP as ESB
    25
    WAMP
    Router
    Service
    Providers
    Service
    Providers
    Service
    Providers
    Service
    Providers
    Service
    Providers
    Consumers
    Consumers
    Consumers
    Consumers
    Consumers
    call RPC
    Subscribe to topics
    Register RPC
    Publish events
    Subscribe to topics
    Publish events
    Сервер
    Сервер
    Server

    View full-size slide

  112. WAMP in heterogeneous systems
    26
    WAMP
    Router
    File
    uploader
    (python)
    Web
    Client
    (js)
    Backoffice
    Client
    (c#)
    Video
    processing
    (c++)
    Image
    processing
    (go)
    Logger
    (ruby)
    External
    API
    Gateway
    Client
    REST API
    (nodejs)
    Mobile
    Client
    (swift)
    Backoffice
    REST API
    (Java)
    DB
    Mobile
    Client
    (java)
    Realm
    Realm
    Realm
    Сервер
    Сервер
    Server

    View full-size slide

  113. WAMP Application fields
    27

    View full-size slide

  114. WAMP Application fields
    27
    Distributed applications with a large number of services

    View full-size slide

  115. WAMP Application fields
    27
    Distributed applications with a large number of services
    Smart homes, Smart cities, Internet of things in General

    View full-size slide

  116. WAMP Application fields
    27
    Distributed applications with a large number of services
    Smart homes, Smart cities, Internet of things in General
    Systems with long-running processes

    View full-size slide

  117. WAMP Application fields
    27
    Distributed applications with a large number of services
    Smart homes, Smart cities, Internet of things in General
    Systems with long-running processes
    Easy modern alternative to XMPP, XMLRPC

    View full-size slide

  118. WAMP Application fields
    27
    Distributed applications with a large number of services
    Smart homes, Smart cities, Internet of things in General
    Systems with long-running processes
    Easy modern alternative to XMPP, XMLRPC
    Network multiplayer games

    View full-size slide

  119. WAMP: real projects
    28

    View full-size slide

  120. WAMP: real projects
    • Kadecot API Server. Sony Computer Science Laboratories
    28

    View full-size slide

  121. WAMP: real projects
    • Kadecot API Server. Sony Computer Science Laboratories
    • ParaView. Parallel Data Analysis and Visualization Application, Kitware
    28

    View full-size slide

  122. WAMP: real projects
    • Kadecot API Server. Sony Computer Science Laboratories
    • ParaView. Parallel Data Analysis and Visualization Application, Kitware
    • Record.Evolution. Data-warehouse and Business Intelligence
    28

    View full-size slide

  123. WAMP: real projects
    • Kadecot API Server. Sony Computer Science Laboratories
    • ParaView. Parallel Data Analysis and Visualization Application, Kitware
    • Record.Evolution. Data-warehouse and Business Intelligence
    • SmartME smart city project. MDS Lab at the University of Messina
    28

    View full-size slide

  124. WAMP: real projects
    • Kadecot API Server. Sony Computer Science Laboratories
    • ParaView. Parallel Data Analysis and Visualization Application, Kitware
    • Record.Evolution. Data-warehouse and Business Intelligence
    • SmartME smart city project. MDS Lab at the University of Messina
    • ButterflyDNS. Web UI frontend for BIND DLZ
    • Gollard VISION Server Management Subsystem
    28

    View full-size slide

  125. Health monitor
    Nginx
    Server Management Subsystem
    29
    WAMP
    Router
    Admin
    App
    (c#)
    Shaman
    RPC: set.network
    RPC: get.network Publish: status.change
    RPC: get.status
    RPC: get.time
    RPC: set.time

    View full-size slide

  126. Loowy: WAMP client in Lua
    30

    View full-size slide

  127. Loowy: WAMP client in Lua
    30
    • Works in Lua/Luajit environment on top of lua-ev

    View full-size slide

  128. Loowy: WAMP client in Lua
    30
    • Works in Lua/Luajit environment on top of lua-ev
    • Supports JSON and Msgpack serializers

    View full-size slide

  129. Loowy: WAMP client in Lua
    30
    • Works in Lua/Luajit environment on top of lua-ev
    • Supports JSON and Msgpack serializers
    • Supports a number of features from Advanced Profile

    View full-size slide

  130. Loowy: WAMP client in Lua
    30
    • Works in Lua/Luajit environment on top of lua-ev
    • Supports JSON and Msgpack serializers
    • Supports a number of features from Advanced Profile
    • Automatic reconnection and re-subscription

    View full-size slide

  131. Loowy: WAMP client in Lua
    30
    • Works in Lua/Luajit environment on top of lua-ev
    • Supports JSON and Msgpack serializers
    • Supports a number of features from Advanced Profile
    • Automatic reconnection and re-subscription
    • TODO: Raw socket transport
    • TODO: Meta API
    • TODO: Challenge-Response Authorization (WAMP-CRA)
    • TODO: work on the basis of coroutines

    View full-size slide

  132. Loowy: api calls examples
    31
    client = loowy.new("ws://localhost/ws/", { realm = "gv" })
    client:publish('sensor.events', { sensorId = 12, temperature = 27})
    client:subscribe('sensor.events', function(event)
    -- process received event
    end)
    client:call('dcs.fan.control', true, {
    onSuccess = function()
    -- fan turned on successfully
    end,
    onError = function(err)
    -- error occurred
    end
    })

    View full-size slide

  133. Loowy: Technology stack
    32

    View full-size slide

  134. Loowy: Technology stack
    32
    • Lua 5.1+, Luajit 2.0
    • lua-websockets (which uses luasocket under the hood)
    • lua-ev
    • lua-rapidjson
    • lua-MessagePack (optional)

    View full-size slide

  135. Wiola: WAMP router in Lua
    33

    View full-size slide

  136. Wiola: WAMP router in Lua
    • Works on top of Nginx/Lua module
    33

    View full-size slide

  137. Wiola: WAMP router in Lua
    • Works on top of Nginx/Lua module
    • Uses Redis for runtime storage
    33

    View full-size slide

  138. Wiola: WAMP router in Lua
    • Works on top of Nginx/Lua module
    • Uses Redis for runtime storage
    • Supports JSON and Msgpack serializers
    33

    View full-size slide

  139. Wiola: WAMP router in Lua
    • Works on top of Nginx/Lua module
    • Uses Redis for runtime storage
    • Supports JSON and Msgpack serializers
    • Supports a number of features from Advanced Profile
    33

    View full-size slide

  140. Wiola: WAMP router in Lua
    • Works on top of Nginx/Lua module
    • Uses Redis for runtime storage
    • Supports JSON and Msgpack serializers
    • Supports a number of features from Advanced Profile
    • TODO: Raw socket transport
    • TODO: Meta API
    • TODO: lua-resty-postgres
    33

    View full-size slide

  141. Wiola: Technology stack
    34

    View full-size slide

  142. Wiola: Technology stack
    34
    • Nginx or OpenResty, simply put lua-nginx-module
    • lua-resty-websocket
    • lua-resty-redis
    • Redis Server
    • lua-rapidjson
    • lua-resty-hmac (optional, is required for WAMP-CRA)
    • lua-MessagePack (optional)

    View full-size slide

  143. Wiola: Nginx config
    35
    location /ws/ {
    set $wiola_socket_timeout 10;
    set $wiola_max_payload_len 65535;
    lua_check_client_abort on;
    header_filter_by_lua_file /lib/wiola/headers.lua;
    content_by_lua_file /lib/wiola/handler.lua;
    }

    View full-size slide

  144. Nginx
    Wiola: Common scheme
    36
    Web
    Client
    init_by_lua
    headers_filter_by_lua
    content_by_lua
    Redis
    Server

    View full-size slide

  145. Wiola: JSON caveats and limitations
    37

    View full-size slide

  146. Wiola: JSON caveats and limitations
    • cJSON
    37

    View full-size slide

  147. Wiola: JSON caveats and limitations
    • cJSON
    • you cannot specify how to serialize empty tables
    37

    View full-size slide

  148. Wiola: JSON caveats and limitations
    • cJSON
    • you cannot specify how to serialize empty tables
    • lua-resty-libcjson
    37

    View full-size slide

  149. Wiola: JSON caveats and limitations
    • cJSON
    • you cannot specify how to serialize empty tables
    • lua-resty-libcjson
    • not able to work with large numbers (int > 32bit)
    37

    View full-size slide

  150. Wiola: JSON caveats and limitations
    • cJSON
    • you cannot specify how to serialize empty tables
    • lua-resty-libcjson
    • not able to work with large numbers (int > 32bit)
    lua-rapidjson
    37

    View full-size slide

  151. Wiola: JSON caveats and limitations
    • cJSON
    • you cannot specify how to serialize empty tables
    • lua-resty-libcjson
    • not able to work with large numbers (int > 32bit)
    lua-rapidjson
    • So far, no new problems have been found :)
    37

    View full-size slide

  152. Wiola: Runtime storage options
    38

    View full-size slide

  153. Wiola: Runtime storage options
    38
    • Global variables in memory

    View full-size slide

  154. Wiola: Runtime storage options
    38
    • Global variables in memory
    • are created every time on request handler

    View full-size slide

  155. Wiola: Runtime storage options
    38
    • Global variables in memory
    • are created every time on request handler
    • problems with concurrent requests

    View full-size slide

  156. Wiola: Runtime storage options
    38
    • Global variables in memory
    • are created every time on request handler
    • problems with concurrent requests
    • Module variables loaded in init_by_lua

    View full-size slide

  157. Wiola: Runtime storage options
    38
    • Global variables in memory
    • are created every time on request handler
    • problems with concurrent requests
    • Module variables loaded in init_by_lua
    • You can read in all workers

    View full-size slide

  158. Wiola: Runtime storage options
    38
    • Global variables in memory
    • are created every time on request handler
    • problems with concurrent requests
    • Module variables loaded in init_by_lua
    • You can read in all workers
    • But the write, thanks to CoW, will create a copy of the module for the VM

    View full-size slide

  159. Wiola: Runtime storage options
    38
    • Global variables in memory
    • are created every time on request handler
    • problems with concurrent requests
    • Module variables loaded in init_by_lua
    • You can read in all workers
    • But the write, thanks to CoW, will create a copy of the module for the VM
    • ngx.shared.DICT

    View full-size slide

  160. Wiola: Runtime storage options
    38
    • Global variables in memory
    • are created every time on request handler
    • problems with concurrent requests
    • Module variables loaded in init_by_lua
    • You can read in all workers
    • But the write, thanks to CoW, will create a copy of the module for the VM
    • ngx.shared.DICT
    • The size of each dictionary is specified in the config file and can not be changed

    View full-size slide

  161. Wiola: Runtime storage options
    38
    • Global variables in memory
    • are created every time on request handler
    • problems with concurrent requests
    • Module variables loaded in init_by_lua
    • You can read in all workers
    • But the write, thanks to CoW, will create a copy of the module for the VM
    • ngx.shared.DICT
    • The size of each dictionary is specified in the config file and can not be changed
    External storage: Redis, Memcache, PostgreSQL, MySQL and others

    View full-size slide

  162. Wiola: Особенности. lua_code_cache
    39

    View full-size slide

  163. Wiola: Особенности. lua_code_cache
    39
    • lua_code_cache off;

    View full-size slide

  164. Wiola: Особенности. lua_code_cache
    39
    • lua_code_cache off;
    • it is convenient to debug the code

    View full-size slide

  165. Wiola: Особенности. lua_code_cache
    39
    • lua_code_cache off;
    • it is convenient to debug the code
    • every require() is executed again in each request

    View full-size slide

  166. Wiola: Особенности. lua_code_cache
    39
    • lua_code_cache off;
    • it is convenient to debug the code
    • every require() is executed again in each request
    • Even the modules loaded into init_by_lua are re-executed

    View full-size slide

  167. Wiola: Особенности. lua_code_cache
    39
    • lua_code_cache off;
    • it is convenient to debug the code
    • every require() is executed again in each request
    • Even the modules loaded into init_by_lua are re-executed
    • lua_code_cache on;

    View full-size slide

  168. Wiola: Особенности. lua_code_cache
    39
    • lua_code_cache off;
    • it is convenient to debug the code
    • every require() is executed again in each request
    • Even the modules loaded into init_by_lua are re-executed
    • lua_code_cache on;
    • for production environment

    View full-size slide

  169. Wiola: Особенности. lua_code_cache
    39
    • lua_code_cache off;
    • it is convenient to debug the code
    • every require() is executed again in each request
    • Even the modules loaded into init_by_lua are re-executed
    • lua_code_cache on;
    • for production environment
    • each require() is executed once and is cached

    View full-size slide

  170. Wiola: Особенности. lua_code_cache
    39
    • lua_code_cache off;
    • it is convenient to debug the code
    • every require() is executed again in each request
    • Even the modules loaded into init_by_lua are re-executed
    • lua_code_cache on;
    • for production environment
    • each require() is executed once and is cached
    • whenever you change the code, you need to reload nginx

    View full-size slide

  171. Wiola: Publication in luarocks, opm
    40

    View full-size slide

  172. Wiola: Publication in luarocks, opm
    40
    • luarocks: there is one part of
    the dependencies, there is no
    other:

    View full-size slide

  173. Wiola: Publication in luarocks, opm
    40
    • luarocks: there is one part of
    the dependencies, there is no
    other:
    - lua-resty-websocket

    View full-size slide

  174. Wiola: Publication in luarocks, opm
    40
    • luarocks: there is one part of
    the dependencies, there is no
    other:
    - lua-resty-websocket
    - lua-resty-redis

    View full-size slide

  175. Wiola: Publication in luarocks, opm
    40
    • luarocks: there is one part of
    the dependencies, there is no
    other:
    - lua-resty-websocket
    - lua-resty-redis
    ✓ rapidjson

    View full-size slide

  176. Wiola: Publication in luarocks, opm
    40
    • luarocks: there is one part of
    the dependencies, there is no
    other:
    - lua-resty-websocket
    - lua-resty-redis
    ✓ rapidjson
    ✓ lua-resty-hmac

    View full-size slide

  177. Wiola: Publication in luarocks, opm
    40
    • luarocks: there is one part of
    the dependencies, there is no
    other:
    - lua-resty-websocket
    - lua-resty-redis
    ✓ rapidjson
    ✓ lua-resty-hmac
    ✓ lua-messagepack

    View full-size slide

  178. Wiola: Publication in luarocks, opm
    40
    • luarocks: there is one part of
    the dependencies, there is no
    other:
    - lua-resty-websocket
    - lua-resty-redis
    ✓ rapidjson
    ✓ lua-resty-hmac
    ✓ lua-messagepack
    • opm (OpenResty Package
    Manager): accurate to
    "reverse":

    View full-size slide

  179. Wiola: Publication in luarocks, opm
    40
    • luarocks: there is one part of
    the dependencies, there is no
    other:
    - lua-resty-websocket
    - lua-resty-redis
    ✓ rapidjson
    ✓ lua-resty-hmac
    ✓ lua-messagepack
    • opm (OpenResty Package
    Manager): accurate to
    "reverse":
    ✓ lua-resty-websocket

    View full-size slide

  180. Wiola: Publication in luarocks, opm
    40
    • luarocks: there is one part of
    the dependencies, there is no
    other:
    - lua-resty-websocket
    - lua-resty-redis
    ✓ rapidjson
    ✓ lua-resty-hmac
    ✓ lua-messagepack
    • opm (OpenResty Package
    Manager): accurate to
    "reverse":
    ✓ lua-resty-websocket
    ✓ lua-resty-redis

    View full-size slide

  181. Wiola: Publication in luarocks, opm
    40
    • luarocks: there is one part of
    the dependencies, there is no
    other:
    - lua-resty-websocket
    - lua-resty-redis
    ✓ rapidjson
    ✓ lua-resty-hmac
    ✓ lua-messagepack
    • opm (OpenResty Package
    Manager): accurate to
    "reverse":
    ✓ lua-resty-websocket
    ✓ lua-resty-redis
    - rapidjson

    View full-size slide

  182. Wiola: Publication in luarocks, opm
    40
    • luarocks: there is one part of
    the dependencies, there is no
    other:
    - lua-resty-websocket
    - lua-resty-redis
    ✓ rapidjson
    ✓ lua-resty-hmac
    ✓ lua-messagepack
    • opm (OpenResty Package
    Manager): accurate to
    "reverse":
    ✓ lua-resty-websocket
    ✓ lua-resty-redis
    - rapidjson
    ✓ lua-resty-hmac

    View full-size slide

  183. Wiola: Publication in luarocks, opm
    40
    • luarocks: there is one part of
    the dependencies, there is no
    other:
    - lua-resty-websocket
    - lua-resty-redis
    ✓ rapidjson
    ✓ lua-resty-hmac
    ✓ lua-messagepack
    • opm (OpenResty Package
    Manager): accurate to
    "reverse":
    ✓ lua-resty-websocket
    ✓ lua-resty-redis
    - rapidjson
    ✓ lua-resty-hmac
    - lua-messagepack

    View full-size slide

  184. Useful links about WAMP
    41

    View full-size slide

  185. Useful links about WAMP
    • WAMP main site: http://wamp-proto.org/
    • WAMP spec on github: github.com/wamp-proto/wamp-proto
    • Mailing list: https://groups.google.com/forum/#!forum/wampws
    • Wiola: https://github.com/KSDaemon/wiola
    • Loowy: https://github.com/KSDaemon/Loowy
    • Wampy.js: https://github.com/KSDaemon/wampy.js
    • Wiola docker image: https://hub.docker.com/r/421p/wiola/
    • Crossbar Router: https://crossbar.io/ и https://demo.crossbar.io/
    41

    View full-size slide

  186. WAMP: Conclusion
    42

    View full-size slide

  187. WAMP: Conclusion
    • A simple and open Protocol
    42

    View full-size slide

  188. WAMP: Conclusion
    • A simple and open Protocol
    • RPC and PubSub in one transport/protocol
    42

    View full-size slide

  189. WAMP: Conclusion
    • A simple and open Protocol
    • RPC and PubSub in one transport/protocol
    • Any transport and serialization
    42

    View full-size slide

  190. WAMP: Conclusion
    • A simple and open Protocol
    • RPC and PubSub in one transport/protocol
    • Any transport and serialization
    • Allows you to build distributed applications with loosely coupled
    components
    42

    View full-size slide

  191. WAMP: Conclusion
    • A simple and open Protocol
    • RPC and PubSub in one transport/protocol
    • Any transport and serialization
    • Allows you to build distributed applications with loosely coupled
    components
    • There are implementations in many languages
    42

    View full-size slide

  192. WAMP: Conclusion
    • A simple and open Protocol
    • RPC and PubSub in one transport/protocol
    • Any transport and serialization
    • Allows you to build distributed applications with loosely coupled
    components
    • There are implementations in many languages
    • Open source
    42

    View full-size slide

  193. WAMP: Conclusion
    • A simple and open Protocol
    • RPC and PubSub in one transport/protocol
    • Any transport and serialization
    • Allows you to build distributed applications with loosely coupled
    components
    • There are implementations in many languages
    • Open source
    • A small but friendly community
    42

    View full-size slide

  194. WAMP: Conclusion
    43

    View full-size slide

  195. WAMP: Conclusion
    • Useful architectural solution
    43

    View full-size slide

  196. WAMP: Conclusion
    • Useful architectural solution
    • A great option for your IoT project! (IMHO: better than MQTT)
    43

    View full-size slide

  197. WAMP: Conclusion
    • Useful architectural solution
    • A great option for your IoT project! (IMHO: better than MQTT)
    • Try WAMP:
    43

    View full-size slide

  198. WAMP: Conclusion
    • Useful architectural solution
    • A great option for your IoT project! (IMHO: better than MQTT)
    • Try WAMP:
    • Already have nginx/openresty? — try Wiola (bit.ly/wiola-router)
    43

    View full-size slide

  199. WAMP: Conclusion
    • Useful architectural solution
    • A great option for your IoT project! (IMHO: better than MQTT)
    • Try WAMP:
    • Already have nginx/openresty? — try Wiola (bit.ly/wiola-router)
    • Are you using a docker?
    43

    View full-size slide

  200. WAMP: Conclusion
    • Useful architectural solution
    • A great option for your IoT project! (IMHO: better than MQTT)
    • Try WAMP:
    • Already have nginx/openresty? — try Wiola (bit.ly/wiola-router)
    • Are you using a docker?
    • docker pull 421p/wiola
    43

    View full-size slide

  201. WAMP: Conclusion
    • Useful architectural solution
    • A great option for your IoT project! (IMHO: better than MQTT)
    • Try WAMP:
    • Already have nginx/openresty? — try Wiola (bit.ly/wiola-router)
    • Are you using a docker?
    • docker pull 421p/wiola
    • docker pull crossbario/crossbar
    43

    View full-size slide

  202. WAMP: Conclusion
    • Useful architectural solution
    • A great option for your IoT project! (IMHO: better than MQTT)
    • Try WAMP:
    • Already have nginx/openresty? — try Wiola (bit.ly/wiola-router)
    • Are you using a docker?
    • docker pull 421p/wiola
    • docker pull crossbario/crossbar
    • WAMP client for every taste and color (wamp-proto.org/implementations/)
    43

    View full-size slide

  203. Thank you for attention!
    And your questions :)
    44
    Konstantin Burkalev
    • Mail: [email protected]
    • Twitter: @KSDaemon
    • GitHub: KSDaemon
    • Blog: blog.ksdaemon.ru
    • SDCast: sdcast.ksdaemon.ru

    View full-size slide