Created
November 15, 2017 04:07
-
-
Save tienthanh2509/78faa6fa09379ea1b67c7eca573b5c28 to your computer and use it in GitHub Desktop.
Test RabbitMQ with validating server certificates
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pika | |
import urlparse | |
import ssl | |
url_str = 'amqps://admin:xxxxxx@localhost//' | |
channel_id = 'some-rabbitmq-channel' | |
url = urlparse.urlparse(url_str) | |
ssl_options = { | |
"ca_certs": "./ca-bundle.crt", | |
"cert_reqs": ssl.CERT_REQUIRED | |
} | |
params = pika.ConnectionParameters(host=url.hostname, | |
virtual_host=url.path[1:], | |
credentials=pika.PlainCredentials(url.username, url.password), | |
ssl=True, | |
ssl_options=ssl_options, | |
) | |
connection = pika.BlockingConnection(params) # Connect to CloudAMQP | |
channel = connection.channel() # start a channel | |
# send a message | |
payload = '{some json/text}' | |
channel.basic_publish(exchange='', routing_key=channel_id, body=payload) | |
print " [ok] Sent ' with payload " + payload | |
connection.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Exception if validating falied