コード例 #1
0
 def test_create_binding(self):
     create_exchange(self.exchange_address,
                     exchange_type=ExchangeType.topic,
                     durable=False)
     create_queue(self.queue_address, durable=False, auto_delete=True)
     create_binding(self.exchange_address,
                    self.queue_address,
                    binding_name='one_ring')
コード例 #2
0
def route_config(args):
    try:
        route_mapping = yaml.safe_load(args.file)
    except yaml.YAMLError:
        print("Invalid YAML config mapping\n")
        args.parser.print_help()
        exit(EX_DATAERR)

    for exchange in route_mapping:
        valid_bindings = set()
        if args.force_creation:
            try:
                create_exchange(exchange,
                                ExchangeType.headers,
                                server_url=args.broker_url)
            except QMF2ObjectExists:
                print("Exchange {} already exists, moving on...".format(
                    exchange))
        for queue in route_mapping[exchange]:
            if args.force_creation:
                try:
                    create_queue(queue, server_url=args.broker_url)
                except QMF2ObjectExists:
                    print(
                        "Queue {} already exists, moving on...".format(queue))
            for binding in route_mapping[exchange][queue]:
                binding_name = get_headers_binding_name(
                    exchange, queue, binding)
                valid_bindings.add((exchange, queue, binding_name))
                # A binding with an existing name will be updated.
                # Since we generate the name from the header match properties,
                # this is equivalent to ignoring.
                try:
                    create_binding(exchange,
                                   queue,
                                   headers_match=binding,
                                   binding_name=binding_name,
                                   server_url=args.broker_url)
                except ValueError as e:
                    print(str(e) + '\n')
                    args.parser.print_help()
                    exit(EX_USAGE)
                except ObjectNotFound as e:
                    print(str(e) + '\n')
                    args.parser.print_help()
                    exit(EX_USAGE)

        binding_keys = get_binding_keys(exchange, server_url=args.broker_url)
        # Delete old bindings
        for binding_key in binding_keys - valid_bindings:
            delete_binding(binding_key[0],
                           binding_key[1],
                           binding_key[2],
                           server_url=args.broker_url)
コード例 #3
0
 def test_create_headers_binding(self):
     create_exchange(self.exchange_address,
                     exchange_type=ExchangeType.headers,
                     durable=False)
     create_queue(self.queue_address, durable=False, auto_delete=True)
     create_binding(self.exchange_address,
                    self.queue_address,
                    headers_match={
                        'type': 'food',
                        'timing': 'early'
                    },
                    binding_name='breakfast')
コード例 #4
0
 def test_create_binding_match_on_wrong_exchange(self):
     create_exchange(self.exchange_address,
                     exchange_type=ExchangeType.direct,
                     durable=False)
     create_queue(self.queue_address, durable=False, auto_delete=True)
     with self.assertRaises(RuntimeError):
         create_binding(self.exchange_address,
                        self.queue_address,
                        headers_match={
                            'type': 'food',
                            'timing': 'late'
                        },
                        binding_name='dinner')
コード例 #5
0
 def test_create_binding_no_queue(self):
     create_exchange(self.exchange_address,
                     exchange_type=ExchangeType.direct,
                     durable=False)
     with self.assertRaises(QMF2NotFound):
         create_binding(self.exchange_address, self.queue_address)
コード例 #6
0
 def test_create_binding_no_exchange(self):
     create_queue(self.queue_address, durable=False, auto_delete=True)
     with self.assertRaises(ObjectNotFound):
         create_binding(self.exchange_address, self.queue_address)