Last active
September 21, 2018 08:41
-
-
Save haizaar/208e4c63954db1cbc3aa1de4b8e5951f to your computer and use it in GitHub Desktop.
Wiola minimal setup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
from autobahn.asyncio.wamp import ApplicationSession, ApplicationRunner | |
from autobahn.wamp import RegisterOptions | |
class Component(ApplicationSession): | |
async def onJoin(self, details): | |
print("Join:", details) | |
self.register(self.ping, "com.myapp.ping", options=RegisterOptions(details_arg="details")) | |
counter = 0 | |
while True: | |
print("publish: com.myapp.hello", counter) | |
self.publish("com.myapp.hello", counter) | |
counter += 1 | |
await asyncio.sleep(1) | |
def ping(self, details=None): | |
print("ping called. details=", details) | |
if __name__ == "__main__": | |
url = "ws://127.0.0.1:8080/ws" | |
realm = "realm1" | |
runner = ApplicationRunner(url, realm) | |
runner.run(Component) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# NOTE: This is a really quick & dirty version | |
FROM openresty/openresty:1.13.6.2-0-alpine-fat | |
RUN apk add --no-cache cmake openssl-dev git | |
RUN /usr/local/openresty/luajit/bin/luarocks install wiola 0.9.1-2 | |
CMD ["/usr/local/openresty/bin/openresty"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
daemon off; | |
worker_processes 1; | |
error_log /dev/stderr info; | |
pid /var/run/nginx.pid; | |
events { | |
worker_connections 1024; | |
} | |
http { | |
server_tokens off; | |
include mime.types; | |
log_format main '$remote_addr - $remote_user [$time_local] "$request" ' | |
'$status $body_bytes_sent "$http_referer" ' | |
'"$http_user_agent" "$http_x_forwarded_for" ' | |
'$request_time $upstream_response_time $pipe'; | |
access_log /dev/stdout main; | |
# include /etc/nginx/conf.d/*.conf; | |
init_by_lua_block { | |
local cfg = require "wiola.config" | |
cfg.config({ | |
realms = {"realm1"}, | |
store = "redis", | |
storeConfig = { | |
host = "127.0.0.1", | |
port = 6379, | |
}, | |
metaAPI = { | |
session = true, | |
subscription = true, | |
registration = true, | |
} | |
}) | |
ngx.log(ngx.ERR, "Wiola configured") | |
} | |
# Configure a vhost | |
server { | |
listen 80; | |
# example location for websocket WAMP connection | |
location /ws { | |
set $wiola_max_payload_len 65535; # Optional parameter. Set the value to suit your needs | |
lua_socket_log_errors off; | |
lua_check_client_abort on; | |
# This is needed to set additional websocket protocol headers | |
header_filter_by_lua_file /usr/local/openresty/luajit/share/lua/5.1/wiola/headers.lua; | |
# Set a handler for connection | |
content_by_lua_file /usr/local/openresty/luajit/share/lua/5.1/wiola/ws-handler.lua; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# --publish is for wiola that reuses our network | |
docker run \ | |
--rm -d \ | |
--name=redis \ | |
--publish 8080:80 \ | |
redis |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
exec docker run \ | |
--rm \ | |
-ti \ | |
--name=wiola \ | |
--net container:redis \ | |
--volume $PWD/nginx.conf:/usr/local/openresty/nginx/conf/nginx.conf \ | |
wiola $@ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment