helyos_agent_sdk.client module
- helyos_agent_sdk.client.connect_rabbitmq(rabbitmq_host, rabbitmq_port, username, passwd, enable_ssl=False, ca_certificate=None, temporary=False)
- class helyos_agent_sdk.client.HelyOSClient(rabbitmq_host, rabbitmq_port=5672, uuid=None, enable_ssl=False, ca_certificate=None, helyos_public_key=None, agent_privkey=None, agent_pubkey=None)
Bases:
object
- __init__(rabbitmq_host, rabbitmq_port=5672, uuid=None, enable_ssl=False, ca_certificate=None, helyos_public_key=None, agent_privkey=None, agent_pubkey=None)
HelyOS client class
The client implements several functions to facilitate the interaction with RabbitMQ. It reads the RabbitMQ exchange names from environment variables and it provides the helyOS routing-key names as properties. For SSL connections, the RabbitMQ server CA certificate should be provided as a string in PEM format. If the agent public and private keys are not provided, they are generated by the client at the initialization, and the public key is sent to helyOS during the check-in procedure. If the helyOS public key is not provided, it is retrieved during the check-in procedure.
- Parameters
rabbitmq_host (str) – RabbitMQ host name (e.g rabbitmq.mydomain.com)
rabbitmq_port (int) – RabbitMQ port, defaults to 5672
uuid (str) – universal unique identifier fot the agent
enable_ssl (bool, optional) – Enable rabbitmq SSL connection, default False.
ca_certificate (string (PEM format), optional) – Certificate authority of the RabbitMQ server, defaults to None
helyos_public_key (string (PEM format), optional) – helyOS RSA public key to verify the helyOS message signature.
agent_privkey (string (PEM format), optional) – Agent RSA private key, defaults to None
agent_pubkey (string (PEM format), optional) – Agent RSA public key is saved in helyOS core, defaults to None
- property is_connection_open
Check if the connection is open
- property checking_routing_key
Routing key value used for check in messages
- property status_routing_key
Routing key value used to publish agent and assigment states
- property sensors_routing_key
Routing key value used for broadingcasting of positions and sensors
- property mission_routing_key
Routing key value used to publish mission requests
- property summary_routing_key
Routing key value used to publish summary requests
- property database_routing_key
Routing key value used to publish summary requests
- property yard_visualization_routing_key
Routing key value used to broadcast yard visualization data
- property yard_update_routing_key
Routing key value used to publish updates for the yard
- property instant_actions_routing_key
Routing key value used to read instant actions
- property update_routing_key
Routing key value used for agent update messages
- property assignment_routing_key
Routing key value used to read assigment messages
- get_checkin_result()
get_checkin_result() read the checkin data published by helyOS and save into the HelyOSClient instance as checkin_data.
- auth_required()
- connect_rabbitmq(username, password)
- reconnect()
- connect(username, password)
Creates the connection between agent and the RabbitMQ server.
helyos_client = HelyOSClient(host='myrabbitmq.com', port=5672, uuid='3452345-52453-43525') helyos_client.connect_rabbitmq('my_username', 'secret_password') # <===
- Parameters
username (str) – username previously registered in RabbitMQ server
password (str) – password previously registered in RabbitMQ server’
- perform_checkin(yard_uid, status=AGENT_STATE.FREE, agent_data={}, signed=False, checkin_guard_interceptor=None)
Registers the agent to a specific yard and retrieves relevant data about the yard and the CA certificate of the RabbitMQ server, which is relevant for SSL connections. Use the method get_checkin_result() to retrieve these data.
The method connect_rabbitmq() should run before the check-in, otherwise, it will be assumed that the agent does not have yet a RabbitMQ account. In this case, if the environment variable REGISTRATION_TOKEN is set, helyOS will create a RabbitMQ account using the uuid as username and returns a password, which can be found in the property rbmq_password. This password should be safely stored.
helyos_client = HelyOSClient(host='myrabbitmq.com', port=5672, uuid='3452345-52453-43525') helyos_client.connect_rabbitmq('my_username', 'secret_password') helyos_client.perform_checkin(yard_uid='yard_A', status='free') # <=== helyOS_client.get_checkin_result() # <===
- Parameters
yard_uid (str) – Yard UID
status (str) – Agent status, defaults to ‘free’
agent_data (dict) – Additional data to be sent with the check-in message, defaults to an empty dictionary
signed (bool) – Whether or not to sign the check-in message, defaults to False
checkin_guard_interceptor (function) – An optional interceptor function to be called to validate the check-in response, returning True or False, defaults to None
- publish(routing_key, message, signed=False, reply_to=None, corr_id=None, exchange='xchange_helyos.agents.ul')
Publish message in RabbitMQ :param message: Message to be transmitted :type message: str :param routing_key: RabbitMQ routing_key :type routing_key: str :param signed: If this message should be signed, defaults to False :type signed: boolean :param exchange: RabbitMQ exchange, defaults to env.AGENTS_UL_EXCHANGE :type exchange: str
- set_assignment_queue(exchange='xchange_helyos.agents.dl')
- set_instant_actions_queue(exchange='xchange_helyos.agents.dl')
- consume_assignment_messages(assignment_callback)
- consume_instant_actions_messages(instant_actions_callback)
Receive instant actions messages. Instant actions are used by helyOS to reserve, release or cancel an assignment.
- Parameters
instant_actions_callback (func) – call back for instant actions
- start_listening()
- stop_listening()
- close_connection()
Close the AMQP connection with RabbitMQ server