예제 #1
0
    def run(self, debug=False):
        """Run microservice in loop, where handle connections

        :param debug: enable/disable debug mode
        :type debug: bool
        """
        if debug:
            from microservices.utils import set_logging

            set_logging('DEBUG')
        self.drain_events(infinity=True)
예제 #2
0
    def run(self, debug=False):
        """Run microservice in loop, where handle connections

        :param debug: enable/disable debug mode
        :type debug: bool
        """
        if debug:
            from microservices.utils import set_logging

            set_logging('DEBUG')

        def _run():
            self._start()
            self.drain_events(infinity=True)

        while not self._stopped:
            _run()
예제 #3
0
import gevent.monkey
from microservices.utils import set_logging, get_logger

set_logging()
logger = get_logger('Gevent Service Queue')

gevent.monkey.patch_all()

from microservices.queues.runners import gevent_run
from microservices.queues.service import Microservice
from microservices.queues.client import Client


app1 = Microservice()
app2 = Microservice()
app3 = Microservice()
app4 = Microservice()

@app1.queue('gevent_basic1')
@app2.queue('gevent_basic2')
@app3.queue('gevent_basic3')
def gevent_basic(payload, context):
    logger.info(
        'Payload: %s, queue name: %s',
        payload,
        context.rule.name,
    )

gevent_run(app1, start=False, monkey_patch=False, debug=True)
gevent_run(app2, start=False, monkey_patch=False, debug=True)
gevent_run(app3, start=False, monkey_patch=False, debug=True)
예제 #4
0
import gevent.monkey

gevent.monkey.patch_all()

from microservices.queues.service import Microservice
from microservices.queues.client import Client
from microservices.utils import set_logging, get_logger
from microservices.queues.runners import gevent_run
from microservices.http.client import Client as HTTPClient
import time
import logging

set_logging('INFO')
logger = get_logger(__name__)
mlo = get_logger('microservices.http.client')
mlo.setLevel(logging.ERROR)

service = Microservice()
timeout = 10
http_client = HTTPClient('http://*****:*****@service.queue('test')
def handle(payload, context):
    global timeout
    logger.info('Start handling: %s, timeout=%s', payload, timeout)
    start_time = time.time()
    a = 0
    while time.time() - start_time < timeout:
예제 #5
0
import unittest
from microservices.utils import set_logging
from threading import Thread, Event

set_logging()


class TestService(unittest.TestCase):
    def test_service(self):
        from microservices.queues.service import Microservice
        from microservices.queues.client import Client
        from kombu.connection import Connection

        microservice = Microservice('memory:///', timeout=0.01)

        connection = Connection('memory:///')

        ev1 = Event()
        ev2 = Event()
        ev3 = Event()

        @microservice.queue('test', connection=None)
        def handle_message(data, context):
            self.assertEqual(data, 'data')
            microservice.logger.info(data)
            ev1.set()

        @microservice.queue('one_q', connection=connection)
        def handle_message(data, context):
            self.assertEqual(data, 'data')
            microservice.logger.info(data)
from microservices.http.client import Client
from microservices.utils import set_logging, get_logger

set_logging(level='INFO')
logger = get_logger('microservices client')

client = Client(
    'http://localhost:5000/',
)

logger.info(client.get(key='response'))
logger.info(client.post(data={'test': 'tested'}))

second_resource = client.resource('second')

logger.info(second_resource.get(key='response'))
logger.info(second_resource.post(data={'test': 'tested'}))

logger.info(second_resource.get('test', key='response'))
logger.info(second_resource.post('test'))

one_two_resource = second_resource.resource('one', '2')
logger.info(one_two_resource.get(key='response'))
logger.info(one_two_resource.post(data={'test': 'tested'}))