Пример #1
0
def setup_connection(consumer_name) -> Tuple[QueueClient, QueueListener]:
    """
    Starts the ActiveMQ connection and registers the event listener
    :return: A client connected and subscribed to the queue specified in credentials, and
             a listener instance which will handle incoming messages
    """
    # Connect to ActiveMQ
    activemq_client = QueueClient()
    activemq_client.connect()

    # Register the event listener
    listener = QueueListener(activemq_client)

    # Subscribe to queues
    activemq_client.subscribe_autoreduce(consumer_name, listener)
    return activemq_client, listener
Пример #2
0
def setup_connection(consumer_name):
    """
    Starts the ActiveMQ connection and registers the event listener
    :return: (Listener) A listener instance which has subscribed to an
             ActiveMQ queue
    """
    # Connect to ActiveMQ
    activemq_client = QueueClient()
    activemq_client.connect()

    # Register the event listener
    listener = QueueListener(activemq_client)

    # Subscribe to queues
    activemq_client.subscribe_autoreduce(consumer_name, listener)
    return activemq_client
Пример #3
0
 def test_subscribe_to_all_queues(self, mock_subscribe):
     """
     Test: subscribe_autoreduce calls subscribe_queues with given arguments,
     including a list of multiple queues (all)
     When: subscribe_autoreduce is called once with the arguments given
     """
     client = QueueClient()
     client.subscribe_autoreduce('consumer', None, 'auto')
     expected_args = {'queue_list': ['/queue/DataReady',
                                     '/queue/ReductionStarted',
                                     '/queue/ReductionComplete',
                                     '/queue/ReductionError',
                                     '/queue/ReductionSkipped'],
                      'ack': 'auto',
                      'listener': None,
                      'consumer_name': 'consumer'}
     mock_subscribe.assert_called_once_with(**expected_args)