/usr/share/pyshared/fedmsg/consumers/gateway.py is in python-fedmsg 0.7.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | # This file is part of fedmsg.
# Copyright (C) 2012 Red Hat, Inc.
#
# fedmsg is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# fedmsg is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with fedmsg; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
# Authors: Ralph Bean <rbean@redhat.com>
#
import fedmsg
import threading
import weakref
import zmq
from fedmsg.consumers import FedmsgConsumer
class GatewayConsumer(FedmsgConsumer):
config_key = 'fedmsg.consumers.gateway.enabled'
jsonify = False
def __init__(self, hub):
self.hub = hub
# The consumer should pick up *all* messages.
self.topic = self.hub.config.get('topic_prefix', 'org.fedoraproject')
if not self.topic.endswith('*'):
self.topic += '*'
super(GatewayConsumer, self).__init__(hub)
# If fedmsg doesn't think we should be enabled, then we should quit
# before setting up all the extra special zmq machinery.
# _initialized is set in moksha.api.hub.consumer
if not getattr(self, "_initialized", False):
return
self.port = hub.config['fedmsg.consumers.gateway.port']
self.validate_signatures = False
self._setup_special_gateway_socket()
# Register a destructor? This might be a bad idea inside Twisted.
weakref.ref(threading.current_thread(), self.destroy)
def _setup_special_gateway_socket(self):
self.log.info("Setting up special gateway socket on " +
"port %r" % self.port)
self._context = zmq.Context(1)
self.gateway_socket = self._context.socket(zmq.PUB)
# Set this to an absurdly high number to increase the number of clients
# we can serve. To be effective, also increase nofile for fedmsg in
# /etc/security/limits.conf to near fs.file-limit. Try 160000.
hwm = self.hub.config['fedmsg.consumers.gateway.high_water_mark']
if hasattr(zmq, 'HWM'):
# zeromq2
self.gateway_socket.setsockopt(zmq.HWM, hwm)
else:
# zeromq3
self.gateway_socket.setsockopt(zmq.SNDHWM, hwm)
self.gateway_socket.setsockopt(zmq.RCVHWM, hwm)
self.gateway_socket.bind("tcp://*:{port}".format(port=self.port))
self.log.info("Gateway socket established.")
def destroy(self):
self.log.info("Destroying GatewayConsumer")
if getattr(self, 'gateway_socket', None):
self.gateway_socket.close()
self.gateway_socket = None
if getattr(self, '_context', None):
self._context.term()
self._context = None
def consume(self, msg):
self.log.debug("Gateway: %r" % msg.topic)
self.gateway_socket.send_multipart([msg.topic, msg.body])
|