|
11 | 11 |
|
12 | 12 | '''
|
13 | 13 |
|
| 14 | +import thread |
| 15 | +import zmq |
14 | 16 | import signal, socket, optparse, time, os, sys, subprocess, logging, errno
|
15 | 17 | try: from socketserver import ForkingMixIn
|
16 | 18 | except: from SocketServer import ForkingMixIn
|
|
25 | 27 | from cgi import parse_qs
|
26 | 28 | from urlparse import urlparse
|
27 | 29 |
|
| 30 | + |
28 | 31 | class ProxyRequestHandler(websocket.WebSocketRequestHandler):
|
29 | 32 |
|
30 | 33 | traffic_legend = """
|
@@ -352,6 +355,23 @@ def logger_init():
|
352 | 355 | h.setFormatter(logging.Formatter("%(message)s"))
|
353 | 356 | logger.addHandler(h)
|
354 | 357 |
|
| 358 | +def mq_listen(threadName, topic): |
| 359 | + |
| 360 | + print("mq_listen now") |
| 361 | + context = zmq.Context() |
| 362 | + |
| 363 | + # First, connect our subscriber socket |
| 364 | + subscriber = context.socket(zmq.SUB) |
| 365 | + subscriber.connect('tcp://172.16.17.240:16161') |
| 366 | + subscriber.setsockopt(zmq.SUBSCRIBE, "") |
| 367 | + |
| 368 | + while True: |
| 369 | + msg = subscriber.recv() |
| 370 | + print("mq recv mesg : "+msg) |
| 371 | + if msg == 'shutdown '+ str(topic): |
| 372 | + break |
| 373 | + print("zeromq listening end") |
| 374 | + os._exit(1) |
355 | 375 |
|
356 | 376 | def websockify_init():
|
357 | 377 | logger_init()
|
@@ -424,6 +444,10 @@ def websockify_init():
|
424 | 444 | parser.add_option("--log-file", metavar="FILE",
|
425 | 445 | dest="log_file",
|
426 | 446 | help="File where logs will be saved")
|
| 447 | + #parser.add_option("--control-url", default="tcp://localhost:61616", |
| 448 | + # help="url from where to get exiting command ") |
| 449 | + #parser.add_option("--control-topic", default=None, |
| 450 | + # help="topic to ensure the command is to current websockify") |
427 | 451 |
|
428 | 452 |
|
429 | 453 | (opts, args) = parser.parse_args()
|
@@ -521,6 +545,15 @@ def websockify_init():
|
521 | 545 | opts.auth_plugin = auth_plugin_cls(opts.auth_source)
|
522 | 546 |
|
523 | 547 | del opts.auth_source
|
| 548 | + |
| 549 | + topic = opts.listen_port |
| 550 | + #if opts.control_topic is not None: |
| 551 | + # topic = opts.control_topic |
| 552 | + #cmd_url = 'tcp://localhost:61616' |
| 553 | + #if opts.control_url is not None: |
| 554 | + # cmd_url = opts.control_url |
| 555 | + |
| 556 | + thread.start_new_thread(mq_listen, ("Thread", opts.listen_port)); |
524 | 557 |
|
525 | 558 | # Create and start the WebSockets proxy
|
526 | 559 | libserver = opts.libserver
|
|
0 commit comments