Skip to content

Commit fb962ce

Browse files
add zmq command interface
1 parent 1a6e0bb commit fb962ce

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
packages=['websockify'],
3636
include_package_data=True,
37-
install_requires=['numpy','stomp'],
37+
install_requires=['numpy','zmq'],
3838
zip_safe=False,
3939
entry_points={
4040
'console_scripts': [

websockify/websocketproxy.py

+33
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
1212
'''
1313

14+
import thread
15+
import zmq
1416
import signal, socket, optparse, time, os, sys, subprocess, logging, errno
1517
try: from socketserver import ForkingMixIn
1618
except: from SocketServer import ForkingMixIn
@@ -25,6 +27,7 @@
2527
from cgi import parse_qs
2628
from urlparse import urlparse
2729

30+
2831
class ProxyRequestHandler(websocket.WebSocketRequestHandler):
2932

3033
traffic_legend = """
@@ -352,6 +355,23 @@ def logger_init():
352355
h.setFormatter(logging.Formatter("%(message)s"))
353356
logger.addHandler(h)
354357

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)
355375

356376
def websockify_init():
357377
logger_init()
@@ -424,6 +444,10 @@ def websockify_init():
424444
parser.add_option("--log-file", metavar="FILE",
425445
dest="log_file",
426446
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")
427451

428452

429453
(opts, args) = parser.parse_args()
@@ -521,6 +545,15 @@ def websockify_init():
521545
opts.auth_plugin = auth_plugin_cls(opts.auth_source)
522546

523547
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));
524557

525558
# Create and start the WebSockets proxy
526559
libserver = opts.libserver

0 commit comments

Comments
 (0)