Completed
Pull Request — master (#2556)
by Edward
07:20
created

main()   A

Complexity

Conditions 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 4
rs 10
cc 1
1
#!/usr/bin/env python
2
# Licensed to the StackStorm, Inc ('StackStorm') under one or more
3
# contributor license agreements.  See the NOTICE file distributed with
4
# this work for additional information regarding copyright ownership.
5
# The ASF licenses this file to You under the Apache License, Version 2.0
6
# (the "License"); you may not use this file except in compliance with
7
# the License.  You may obtain a copy of the License at
8
#
9
#     http://www.apache.org/licenses/LICENSE-2.0
10
#
11
# Unless required by applicable law or agreed to in writing, software
12
# distributed under the License is distributed on an "AS IS" BASIS,
13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
# See the License for the specific language governing permissions and
15
# limitations under the License.
16
17
"""
18
A utility script which sends test messages to a queue.
19
"""
20
21
import argparse
22
23
from kombu import Exchange
24
25
from st2common import config
26
27
from st2common.transport import utils as transport_utils
28
from st2common.transport.publishers import PoolPublisher
29
30
31
def main(exchange, routing_key, payload):
32
    exchange = Exchange(exchange, type='topic')
33
    publisher = PoolPublisher(urls=transport_utils.get_messaging_urls())
34
    publisher.publish(payload=payload, exchange=exchange, routing_key=routing_key)
35
36
37
if __name__ == '__main__':
38
    config.parse_args(args={})
39
    parser = argparse.ArgumentParser(description='Queue producer')
40
    parser.add_argument('--exchange', required=True,
41
                        help='Exchange to publish the message to')
42
    parser.add_argument('--routing-key', required=True,
43
                        help='Routing key to use')
44
    parser.add_argument('--payload', required=True,
45
                        help='Message payload')
46
    args = parser.parse_args()
47
48
    main(exchange=args.exchange, routing_key=args.routing_key,
49
         payload=args.payload)
50