diff options
Diffstat (limited to 'deps/rabbitmq_stomp/test/python_SUITE_data/src/amqp_headers.py')
-rw-r--r-- | deps/rabbitmq_stomp/test/python_SUITE_data/src/amqp_headers.py | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/deps/rabbitmq_stomp/test/python_SUITE_data/src/amqp_headers.py b/deps/rabbitmq_stomp/test/python_SUITE_data/src/amqp_headers.py new file mode 100644 index 0000000000..2c5ee45a8e --- /dev/null +++ b/deps/rabbitmq_stomp/test/python_SUITE_data/src/amqp_headers.py @@ -0,0 +1,42 @@ +## This Source Code Form is subject to the terms of the Mozilla Public +## License, v. 2.0. If a copy of the MPL was not distributed with this +## file, You can obtain one at https://mozilla.org/MPL/2.0/. +## +## Copyright (c) 2007-2020 VMware, Inc. or its affiliates. All rights reserved. +## + +import pika +import base +import os + +class TestAmqpHeaders(base.BaseTest): + def test_headers_to_stomp(self): + self.listener.reset(1) + queueName='test-amqp-headers-to-stomp' + + # Set up STOMP subscription + self.subscribe_dest(self.conn, '/topic/test', None, headers={'x-queue-name': queueName}) + + # Set up AMQP connection + amqp_params = pika.ConnectionParameters(host='localhost', port=int(os.environ["AMQP_PORT"])) + amqp_conn = pika.BlockingConnection(amqp_params) + amqp_chan = amqp_conn.channel() + + # publish a message with headers to the named AMQP queue + amqp_headers = { 'x-custom-hdr-1': 'value1', + 'x-custom-hdr-2': 'value2', + 'custom-hdr-3': 'value3' } + amqp_props = pika.BasicProperties(headers=amqp_headers) + amqp_chan.basic_publish(exchange='', routing_key=queueName, body='Hello World!', properties=amqp_props) + + # check if we receive the message from the STOMP subscription + self.assertTrue(self.listener.wait(2), "initial message not received") + self.assertEquals(1, len(self.listener.messages)) + msg = self.listener.messages[0] + self.assertEquals('Hello World!', msg['message']) + self.assertEquals('value1', msg['headers']['x-custom-hdr-1']) + self.assertEquals('value2', msg['headers']['x-custom-hdr-2']) + self.assertEquals('value3', msg['headers']['custom-hdr-3']) + + self.conn.disconnect() + amqp_conn.close() |