Chapter 3: Getting Started Publish a Message to the inbound.PickupDroppoff Queue The example below publishes a PickupDroppoff message to the inbound.PickupDropoff queue. import os import ssl import pika import logging logging.basicConfig(level=logging.INFO) def get_connection(host, username, password, cert_path): cp = pika.ConnectionParameters( host=host, port=5671, ssl=True, credentials=pika.PlainCredentials(username, password), ssl_options=dict( ssl_version=ssl.PROTOCOL_TLSv1, ca_certs=cert_path, cert_reqs=ssl.CERT_OPTIONAL ) ) return pika.BlockingConnection(cp) def publish_message_to_queue(conn, inbound_queue, message):
ch = conn.channel() assert ch.is_open ch.basic_publish(exchange='', routing_key=inbound_queue, body=message) #nameless ('') exchange should be used. print(" [x] published message %r to queue %r" % (message, inbound_queue)) if __name__ == '__main__': import sys user = 'toolkitadmin' password = 'uzJny0tb3FyhteE9BCuQ' # Change password to the generated password. FMIP = '10.151.26.181' # Change to the Fleet Manager IP FMIP, user, password, os.path.join(os.path.expanduser("~"), "Desktop\\itk-1-tests\\cert.crt") # Change the path to the path used in your application. conn = get_connection( ) inbound_queue = 'inbound.PickupDropoff' # Change the queue to the desired inbound queue.
message = '{ "pickupGoal": "Goal01", "dropoffGoal": "Goal02" }' # Change this message the the desired input value. publish_message_to_queue(conn, inbound_queue, message) 20964-000 Rev. C Fleet Operation Workspace Core Integration Toolkit 21 User's Manual