コード例 #1
0
ファイル: wave.py プロジェクト: abousselmi/osnoise
    def run(self, confdir=None):
        try:
            global LOG
            c = config.ConfigBase(confdir=confdir)
            conf = c.get_conf()

            # init tsunami log
            LOG = logging.getLogger(__name__)
            LOG.info('Start Tsunami..')
            print 'Start Tsunami..'
            # init messaging config
            msg = messaging.BasicMessaging(conf)

            channel = msg.get_channel()

            counter = 0
            start_time = time.time()

            while counter < msg.get_tsunami_message_count():
                channel.basic_publish(exchange=msg.get_exchange(),
                                      routing_key=msg.get_routing_key(),
                                      body=msg.get_message_body(),
                                      properties=msg.get_message_properties()
                                      )
                counter += 1
            print 'This wave took %s seconds to publish %s messages.' % (
                time.time()-start_time, msg.get_tsunami_message_count())
            LOG.info('This wave took %s seconds to publish %s messages.' % (
                time.time()-start_time, msg.get_tsunami_message_count()))
            LOG.info('Stop Tsunami..')
            print 'Stop Tsunami..'
        except KeyboardInterrupt:
            LOG.warning('Program interrupted by user..')
            LOG.info('Stopping tsunami..')
コード例 #2
0
ファイル: generator.py プロジェクト: abousselmi/osnoise
    def run(self, confdir=None):
        try:
            global LOG
            # ini config
            c = config.ConfigBase(confdir=confdir)
            conf = c.get_conf()

            # init osnoise log
            LOG = logging.getLogger(__name__)
            LOG.info('Start OSNoise..')

            # init messaging config
            msg = messaging.BasicMessaging(conf)

            # init publisher and start publish
            pub = publisher.Publisher(pub_id=uuid.uuid4(),
                                      duration=msg.get_duration(),
                                      publish_rate=msg.get_publish_rate(),
                                      connection=msg.get_connection(),
                                      channel=msg.get_channel(),
                                      exchange=msg.get_exchange(),
                                      routing_key=msg.get_routing_key(),
                                      body=msg.get_message_body(),
                                      properties=msg.get_message_properties())

            # start publishing
            pub.do_publish()

            while threading.activeCount() != 0:
                time.sleep(0.1)
                pass
        except KeyboardInterrupt:
            LOG.warning('Program interrupted by user..')
            LOG.info('Stopping..')
コード例 #3
0
    def run(self, confdir=None):
        try:
            global LOG
            # update config file
            if confdir:
                config.update_conf_dir(confdir=confdir)

            # init config
            conf = config.init_config()
            opts.list_opts()

            # init main log
            LOG = logging.getLogger(__name__)
            LOG.info('Start OSNoise..')


            exc = listq.ReplyExchanges()
            for replyExchange in exc.listQueues():
               # init publisher and start publish
               # JFP get reply and routing-keys
               LOG.info('Exchange %s',replyExchange)
               # init messaging config
               msg = messaging.BasicMessaging(conf)
               #pdb.set_trace()
               comp = msg.get_exchange()
               pub = publisher.Publisher(pub_id=uuid.uuid4(),
                                         duration=msg.get_duration(),
                                         publish_rate=msg.get_publish_rate(),
                                         connection=msg.get_connection(),
                                         channel=msg.get_channel(),
                                         # JFP send on all replyExchanges
                                         #exchange=msg.get_exchange(),
                                         #routing_key=msg.get_routing_key(),
                                         exchange=replyExchange,
                                         routing_key=replyExchange,
                                     
                                         body=msg.get_message_body(),
                                         properties=msg.get_message_properties()
                                         )

               # start publishing
               pub.do_publish()

               # JFP go behind 1
               while threading.activeCount() > MAXTHREADS:
                   time.sleep(0.1)
                   pass
            # in case of daemon threads so that they do not stop when main program exits
            #time.sleep(msg.get_duration())

        except KeyboardInterrupt:
            LOG.warning('Program interrupted by user..')
            LOG.info('Stopping..')
コード例 #4
0
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from osnoise.common import logger as logging
import threading
import time

LOG = logging.getLogger(__name__)


def do_thread(function):
    def wrapper(*args, **kwargs):
        t = threading.Thread(target=function, args=args, kwargs=kwargs)
        # Not daemonizing the thread makes publication slow. When try to
        # publish too many messages, the rate will decrease eventually..
        # JFP when a daemon, it will end the threads at the end of program exec, so make normal threads
        t.daemon = False
        t.start()

    return wrapper


class Publisher(object):