Vertx package

Submodules

Vertx.eventbus module

class Vertx.eventbus.Eventbus(host='localhost', port=7000, options=None, onError=None, timeOut=None, connect=True, debug=False)[source]

Bases: object

Vert.x TCP eventbus client for python

Variables:
  • headers – any headers to be sent as per the vertx-tcp-eventbus-bridge specification
  • state (State.CONNECTING: State) – the state of the the eventbus
  • host (str) – ‘localhost’ the host the eventbus is connected to
  • port (int) – 7000 : the port to be used for the socket connection

:ivar pingInterval:5000:the ping interval in millisecs :vartype pingInterval: int

:ivar pongCount:0:the number of pongs received :vartype pongCount: int

Variables:
  • timeOut (float) – DEFAULT_TIMEOUT:time in secs to be used as the socket timeout
  • debug (bool) – False: True if debugging should be enabled

:ivar onError:onError:the function to handle errors messages with no address :vartype onError: function

:ivar handlers:{}: the dict of handlers for incoming messages :vartype handlers: dict

:ivar replyHandler:{}: the dict of handlers for reply messages :vartype replyHandlers: dict

DEFAULT_TIMEOUT = 60.0
__init__(host='localhost', port=7000, options=None, onError=None, timeOut=None, connect=True, debug=False)[source]

constructor

Parameters:
  • host (str) – the host to connect to - default: ‘localhost’
  • port (int) – the port to use - default: 7000
  • options (dict) – e.g. { vertxbus_ping_interval=5000 }
  • onError (function) – the handler to use for erromessages with no address- default: None will be replaced by default onError
  • timeOut (float) – time in secs to be used as the socket timeout - default: 60 secs - the minimium timeOut is 10 msecs and will be enforced
  • connect (bool) – True if the eventbus should automatically be opened - default: True
  • debug (bool) – True if debugging should be enabled - default: False
Raise:
IOError:
  • the socket could not be opened
Exception:
  • some other issue e.g. with starting the listening thread
addHeader(header, value)[source]

add a header with the given header key and value

Parameters:
  • header (str) – the key of the header value to add
  • value (object) – the value of the header value to add
close()[source]

close the eventbus connection after staying in the CLOSING state for the given timeInterval

Parameters:timeInterval (float) – the number of seconds to sleep before actually closing the eventbus - default: 30 seconds
isOpen()[source]

Checks if the eventbus state is OPEN.

Returns:True if State is OPEN else False
Return type:bool
onErrorHandler(message)[source]

default onError Handler - only gives debug output

open()[source]

open the eventbus by connecting the eventbus socket and starting a listening thread by default the connection is opened on construction of an Eventbus instance

Raise:
IOError:
  • the socket could not be opened
Exception:
  • some other issue e.g. with starting the listening thread
ping()[source]

send a ping

Raise:
Exception:
  • eventbus is not open
pongHandler()[source]

default pong Handler - counts the number of pongs Received

publish(address, body=None, headers=None)[source]

publish a message

Parameters:
  • address (str) – the target address to send the message to
  • body (str) – the body of the message e.g. a JSON object
  • headers (dict) – headers to be added - default: None
Raise:
Exception:
  • eventbus is not open
registerHandler(address, callback, headers=None)[source]

register a handler

Parameters:
  • address (str) – the address to register a handler for
  • callback (function) – a callback for the address
  • headers (dict) – headers to be added - default: None
Raise:
Exception:
  • eventbus is not open
  • callback not callable
send(address, body=None, callback=None, headers=None)[source]

send a message

Parameters:
  • address (str) – the target address to send the message to
  • body (str) – the body of the message e.g. a JSON object- default: None
  • headers (dict) – headers to be added - default: None
Raise:
Exception:
  • eventbus is not open
unregisterHandler(address, callback, headers=None)[source]

unregister a callback for a given address if there is more than one callback for the address it will be remove from the handler list if there is only one callback left an unregister message will be sent over the bus and then the address is fully removed

Parameters:
  • address (str) – the address to unregister the handler for
  • callback (function) – the callback to unregister
  • headers (dict) – headers to be added - default: None
Raise:
Exception:
  • eventbus is not open
  • address not registered
  • callback not registered
wait(state=<State.OPEN: 1>, timeOut=5.0, timeStep=0.01)[source]

wait for the eventbus to reach the given state

Parameters:
  • state (State) – the state to wait for - default: State.OPEN
  • timeOut (float) – the timeOut in secs after which the wait fails with an Exception
  • timeStep (float) – the timeStep in secs in which the state should be regularly checked
Raise:
Exception:wait timed out
class Vertx.eventbus.RepeatTimer(interval, function, args=None, kwargs=None)[source]

Bases: threading.Timer

repeating timer

run()[source]

Method representing the thread’s activity.

You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.

class Vertx.eventbus.State[source]

Bases: enum.IntEnum

Eventbus state see https://github.com/vert-x3/vertx-bus-bower/blob/master/vertx-eventbus.js

CLOSED = 3
CLOSING = 2
CONNECTING = 0
OPEN = 1
class Vertx.eventbus.TcpEventBusBridgeStarter(port, jar=None, waitFor='EchoVerticle started', debug=False)[source]

Bases: object

starter for the java based TcpEventBusBridge and test EchoVerticle

__init__(port, jar=None, waitFor='EchoVerticle started', debug=False)[source]

construct me

Parameters:
  • port (int) – the port to listen to
  • jar (str) – the path to the TcpEventBusBridge jar file
  • waitFor (str) – the output string on stderr of the java process to waitFor
  • debug (bool) – True if debugging output should be shown else False - default: False
checkPort()[source]

check that a socket connection is possible on the given port

Parameters:port (int) – the port to check
Returns:True if the port is available else False
Return type:bool
start()[source]

start the jar file

stop()[source]

stop the jar file

wait(timeOut=30.0, timeStep=0.1)[source]

wait for the java server to be started

Parameters:
  • timeOut (float) – the timeOut in secs after which the wait fails with an Exception
  • timeStep (float) – the timeStep in secs in which the state should be regularly checked
Raise:
Exception:wait timed out

Module contents

Vertx module