Welcome to cli-proton-python’s documentation!¶
CLI-PROTON-PYTHON¶
Proton Python clients is a collection of reactive messaging test clients built on python-qpid-proton AMQP1.0 based messaging library. cli-proton-python is a part of Unified Messaging Test Clients that offers equivalent functionality when using different programing languages or APIs.
current related projects:
Using¶
Using the command line clients (please refer to –help to discover the available options)
$ cli-proton-python-sender --broker-url "username:password@localhost:5672/queue_test" --count 1 --msg-content "text message" --log-msgs dict
$ cli-proton-python-receiver --broker-url "username:password@localhost:5672/queue_test" --count 1 --log-msgs dict
Using in script
import proton
from cli_proton_python import sender
parser = sender.options.SenderOptions()
opts, _ = parser.parse_args()
opts.broker_url = 'username:password@localhost:5672/examples'
opts.count = 1
opts.msg_content = 'text message'
opts.log_msgs = 'dict'
container = proton.reactor.Container(sender.Send(opts))
container.run()
License¶
cli_proton_python.connector module¶
Proton reactive API python connector client
-
class
cli_proton_python.connector.
Connector
(opts)[source]¶ Bases:
cli_proton_python.coreclient.CoreClient
Proton reactive API python connector client
-
get_conn_result
()[source]¶ returns the connection statistics triplet
connection statistictriplets are:* connections opened, connections errors, connection requests* connection requests stat is ignored, set to 1 for backwards compatibilityReturns: connector statistics triplet Return type: tuple
-
on_connection_opened
(event)[source]¶ called when the connection is opened
Parameters: event (proton.Event) – reactor event
-
on_connection_remote_open
(event)[source]¶ called when the remote connection is opening
Parameters: event (proton.Event) – reactor event
-
on_link_opened
(event)[source]¶ called when the link is opened
Parameters: event (proton.Event) – reactor event
-
on_session_opened
(event)[source]¶ called when the session is opened
Parameters: event (proton.Event) – reactor event
-
-
cli_proton_python.connector.
run_connectors
(opts, results, errors, stats=None)[source]¶ thread worker function
Parameters: - opts (optparse.Values instance) – connector client options
- results (list) – list of connection results
- errors (int) – number of connection errors
- stats (list) – list containing statistics dictionary (default: None)
cli_proton_python.coreclient module¶
Proton reactive API python core client module
-
exception
cli_proton_python.coreclient.
ClientException
(message)[source]¶ Bases:
exceptions.Exception
custom client exception class (just to know source of exception)
-
class
cli_proton_python.coreclient.
CoreClient
(opts, reactor_opts=None)[source]¶ Bases:
proton.handlers.MessagingHandler
Proton reactive API python core client
implements various support methods for sender, recevier and connector
-
static
calculate_delay
(in_count, in_duration)[source]¶ calculates delay between sending/receiving messages used by shecduler when requested by duration option (uses logic from deprecated utils.sleep4next)
Parameters: - in_count (int) – number of messages to be sent/received
- in_duration (int) – send/receive process total execution time
Returns: computed time to wait before or after message is sent/received
Return type: float
-
on_transport_error
(event)[source]¶ handler called when any error related to transport occurs
See also
MessagingHandler::on_transport_error
Parameters: event (proton.Event) – reactor event
-
parse_connection_options
()[source]¶ Prepare options passed to container connect
Returns: connection options Return type: dict
-
print_message
(message)[source]¶ prints or store a message
utils.print_message wrapper
Parameters: - msg (proton.Message) – message
- msg_format (str) – pre-defined message format
-
set_delay_after
()[source]¶ returns delay duration after sending a message (in seconds)
Returns: time to wait after message is sent/received Return type: float
-
set_delay_before
()[source]¶ returns delay duration before sending a message (in seconds)
Returns: time to wait before message is sent/received Return type: float
-
set_up_ssl_client_auth
(event)[source]¶ sets-up SSLDomain for the client authentication
Parameters: event (proton.Event) – reactor event
-
static
-
class
cli_proton_python.coreclient.
CustomBackoff
(interval=None, limit=None, timeout=None)[source]¶ Bases:
proton.reactor.Backoff
a reconnect strategy involving an increasing delay between retries, up to a maximum or 60 seconds. This is a modified version supporting limit to the number of reconnect attempts before giving up.
-
class
cli_proton_python.coreclient.
DelayedNoop
[source]¶ Bases:
object
callback object that does nothing.
cli_proton_python.formatter module¶
Clients output formatter module
-
class
cli_proton_python.formatter.
Formatter
(message)[source]¶ Bases:
object
Output formatter class for clients
-
static
format_dict
(in_data)[source]¶ formats dictionary
Parameters: in_data (dict) – input data Returns: input data string formated as dict Return type: str
-
static
format_float
(in_data)[source]¶ formats float value
Parameters: in_data (float) – input data Returns: input data string formated as float Return type: str
-
static
format_int
(in_data)[source]¶ formats integer value
Parameters: in_data (int, long) – input data Returns: input data string formated as int Return type: str
-
static
format_list
(in_data)[source]¶ formats list
Parameters: in_data (list) – input data Returns: input data string formated as list Return type: str
-
static
format_object
(in_data)[source]¶ formats general object
Parameters: in_data (None, bool, int, long, float, dict, list, str, unicode, bytes) – input data Returns: input data converted to string Return type: str
-
static
format_string
(in_data)[source]¶ formats string
Parameters: in_data (str, unicode, bytes) – input data Returns: input data string formated as string Return type: str
-
print_error
()[source]¶ print error information
Returns: prefix message with string indicating error Return type: str
-
print_message
()[source]¶ prints message in default upstream format
Returns: message to be printed in upstream format Return type: str
-
print_message_as_dict
()[source]¶ prints message in python dictionary form
Returns: message to be printed in dictionary format Return type: str
-
print_message_as_interop
()[source]¶ Print message in AMQP interoperable format
Returns: message to be printed in interoperable format Return type: str
-
print_message_as_json
()[source]¶ Print message in JSON form
Returns: message to be printed in JSON form Return type: str
-
static
cli_proton_python.options module¶
Proton reactive API python client options module
-
class
cli_proton_python.options.
ConnectorOptions
[source]¶ Bases:
cli_proton_python.options.CoreOptions
Proton reactive API python connector specific client options
-
class
cli_proton_python.options.
CoreOptions
[source]¶ Bases:
optparse.OptionParser
,object
Proton reactive API python core client options
-
class
cli_proton_python.options.
ReceiverOptions
[source]¶ Bases:
cli_proton_python.options.SRCoreOptions
Proton reactive API python receiver specific client options
-
class
cli_proton_python.options.
SRCoreOptions
[source]¶ Bases:
cli_proton_python.options.CoreOptions
Proton reactive API python sender/receiver client options
-
class
cli_proton_python.options.
SenderOptions
[source]¶ Bases:
cli_proton_python.options.SRCoreOptions
Proton reactive API python sender specific client options
-
cli_proton_python.options.
convert_to_unicode
(value)[source]¶ Python 2.x: converts value to unicode
Parameters: value (str) – value to be converted to unicode Returns: unicode string Return type: str (unicode)
cli_proton_python.receiver module¶
Proton reactive API python reciever client
-
class
cli_proton_python.receiver.
Recv
(opts, prefetch=None)[source]¶ Bases:
cli_proton_python.coreclient.CoreClient
Proton reactive API python receiver client
implements various handler methods for reactor events triggered by proton.reactor
-
check_empty
(event)[source]¶ checks whether there are messages to dispatch
Parameters: event (proton.Event) – reactor event
-
do_message_action
(delivery)[source]¶ performs requested action on received message
Parameters: delivery (proton.Delivery) – delivery disposition
-
on_connection_opened
(event)[source]¶ called when connection is opened
Parameters: event (proton.Event) – reactor event
-
on_delivery
(event)[source]¶ called when a message is delivered
Parameters: event (proton.Event) – reactor event
-
on_link_opened
(event)[source]¶ called when link is opened
Parameters: event (proton.Event) – reactor event
-
on_message
(event)[source]¶ called when a message is received
Parameters: event (proton.Event) – reactor event
-
on_settled
(event)[source]¶ called when the remote peer has settled the outgoing message this is the point at which it should never be retransmitted
Parameters: event (proton.Event) – reactor event
-
on_start
(event)[source]¶ called when the event loop starts, creates a receiver for given url
Parameters: event (proton.Event) – reactor event
-
-
class
cli_proton_python.receiver.
Timeout
(parent, event)[source]¶ Bases:
object
Scheduler object for timeout control
-
class
cli_proton_python.receiver.
TxRecv
(opts)[source]¶ Bases:
cli_proton_python.receiver.Recv
,proton.handlers.TransactionHandler
Proton reactive API python transactional receiver client
implements various handler methods for reactor events triggered by proton.reactor
-
is_empty
(event)[source]¶ check if queue is empty
Parameters: event (proton.Event) – reactor event Returns: True if the source is empty, False otherwise Return type: bool
-
on_delivery
(event)[source]¶ called when a message is delivered
Parameters: event (proton.Event) – reactor event
-
on_message
(event)[source]¶ called when a message is received
Parameters: event (proton.Event) – reactor event
-
on_start
(event)[source]¶ called when the event loop starts, creates a transactional receiver for given url
Parameters: event (proton.Event) – reactor event
-
on_transaction_aborted
(event)[source]¶ called when the transaction is aborted
Parameters: event (proton.Event) – reactor event
-
on_transaction_committed
(event)[source]¶ called when the transaction is committed
Parameters: event (proton.Event) – reactor event
-
on_transaction_declared
(event)[source]¶ called when the transaction is declared
Parameters: event (proton.Event) – reactor event
-
cli_proton_python.sender module¶
Proton reactive API python sender client
-
class
cli_proton_python.sender.
Send
(opts)[source]¶ Bases:
cli_proton_python.coreclient.CoreClient
Proton reactive API python sender client
implements various handler methods for reactor events triggered by proton.reactor
-
on_accepted
(event)[source]¶ called when the remote peer accepts an outgoing message
Parameters: event (proton.Event) – reactor event
-
on_disconnected
(event)[source]¶ called when the socket is disconnected
Parameters: event (proton.Event) – reactor event
-
on_rejected
(event)[source]¶ called when the remote peer rejects an outgoing message
Parameters: event (proton.Event) – reactor event
-
on_sendable
(event)[source]¶ called when sending can proceed
Parameters: event (proton.Event) – reactor event
-
on_settled
(event)[source]¶ called when the remote peer has settled the outgoing message, this is the point at which it should never be retransmitted
Parameters: event (proton.Event) – reactor event
-
on_start
(event)[source]¶ called when the event loop starts, creates a sender for given url
Parameters: event (proton.Event) – reactor event
-
on_timer_task
(_)[source]¶ next send action scheduler
the Send object itself is shecduled to perform next send action, that is why it contains timer_task method method
incoming event object does not contain many fields, that is why self.event is used
-
prepare_content
()[source]¶ prepares the content depending on type
Note
- if self.opts.msg_list_items are set amqp/map content is constructed,
- elif self.opts.msg_map_items are set amqp/list content is constructed,
- else the content is considered as text/plain
Returns: string message content Return type: str (unicode) or list or dict
-
static
prepare_content_from_file
(filename)[source]¶ reads and returns file contents
Parameters: filename (str) – path to file to be opened and read Returns: contents of filename as unicode string Return type: str (unicode) or None
-
prepare_list_content
()[source]¶ prepares list content
Returns: list constructed from options list items Return type: list
-
prepare_map_content
()[source]¶ prepares map content
Returns: flat map constructed from options map items Return type: dict
-
prepare_message
()[source]¶ compose and return the message
Returns: message to be sent Return type: proton.Message
-
prepare_string_content
(content)[source]¶ prepares string content
re-types content accoding content-type given, enables message sequence numbering if formatting string (%[ 0-9]*d) is found
Parameters: content (str (unicode)) – message content string Returns: string message content Return type: str (unicode)
-
-
class
cli_proton_python.sender.
TxSend
(opts)[source]¶ Bases:
cli_proton_python.sender.Send
,proton.handlers.TransactionHandler
Proton reactive API python transactional sender client
implements various handler methods for reactor events triggered by proton.reactor
-
on_accepted
(event)[source]¶ suppressed in transactional, no actions are performed
Parameters: event (proton.Event) – reactor event
-
on_disconnected
(event)[source]¶ suppressed in transactional, no actions are performed
Parameters: event (proton.Event) – reactor event
-
on_sendable
(event)[source]¶ suppressed in transactional, no actions are performed
Parameters: event (proton.Event) – reactor event
-
on_settled
(event)[source]¶ suppressed in transactional, no actions are performed
Parameters: event (proton.Event) – reactor event
-
on_start
(event)[source]¶ called when the event loop starts, creates a transactional sender for given url
Parameters: event (proton.Event) – reactor event
-
on_timer_task
(_)[source]¶ suppressed in transactional, no actions are performed
Parameters: event (proton.Event) – reactor event
-
on_transaction_aborted
(event)[source]¶ called when the transaction is aborted
Parameters: event (proton.Event) – reactor event
-
on_transaction_committed
(event)[source]¶ called when the transaction is committed
Parameters: event (proton.Event) – reactor event
-
on_transaction_declared
(event)[source]¶ called when the transaction is declared
Parameters: event (proton.Event) – reactor event
-
cli_proton_python.utils module¶
Various client’s common utils functions
-
cli_proton_python.utils.
dump_error
(err_message)[source]¶ dump error message in parsable format
Parameters: err_message (str) – error massage to be logged
-
cli_proton_python.utils.
dump_event
(event)[source]¶ dumps proton event object
Parameters: event (proton.Event) – reactor event to be dumped
-
cli_proton_python.utils.
hard_retype
(value)[source]¶ tries to converts value to relevant type by re-typing
Parameters: value (str (unicode)) – value to be converted Returns: re-typed value Return type: int, float, bool, str
-
cli_proton_python.utils.
nameval
(in_string)[source]¶ converts given string to key, value and separator triplets
Parameters: in_string (str (unicode)) – key/value pair Returns: key, value and separator triplet Return type: tuple
-
cli_proton_python.utils.
prepare_flat_map
(entries, e_type=None)[source]¶ prepares map content from multiple key, value pairs
Note
only flat map is currently supported
Parameters: - entries (list) – list of key, separator, value triplets
- e_type (str) – map entries desired content type (default: None)
Returns: flat map containing given entries of given type
Return type: dict
-
cli_proton_python.utils.
print_message
(msg, msg_format)[source]¶ prints a message in coresponding format
Parameters: - msg (proton.Message) – message
- msg_format (str) – pre-defined message format
-
cli_proton_python.utils.
retype_content
(content, content_type)[source]¶ converts the content depending on type
Parameters: - content (str (unicode)) – message content
- content_type (str) – message content type
Returns: re-typed content according to given content_type
Return type: int, float, long, bool, str
Indices and tables¶
Changelog¶
v1.0.0 – November 20, 2017
v1.0.1 – November 24, 2017
- json message output format support added
- minor documentation and packaging changes
- API documentation generation
v1.0.2 – February 02, 2018 * address / amqp-to message field support * authentication mechanisms option support * existing bug references added to tests
v1.0.3 – February 05, 2018 * message numbering fix * use anonymous authentication mechanism in p2p tests
v1.0.4 – TBD, not yet live * message group sequence option support