Message Generator

Synopsis

Example:

import messaging.generator as generator;

# create the generator
mg = generator.Generator(
    body_content = "binary",
    body_size = 1024,
)

# use it to generate 10 messages
for i in range(10):
    msg = mg.message()
    ... do something with it ...

Description

This module provides a versatile message generator that can be useful for stress testing or benchmarking messaging brokers or libraries.

Copyright (C) 2013-2016 CERN

class messaging.generator.Generator(**kwargs)

A message generator tool.

message()

Returns a newly generated Message object

Options

When creating a message generator, the following options can be given:

body-content

  • string: specifying the body content type; depending on this value, the body will be made of:
  • base64: only Base64 characters
  • binary: anything
  • index: the message index number, starting at 1, optionally adjusted to match the C<body-size> (this is the default)
  • text: only printable 7-bit ASCII characters
body-size
integer specifying the body size
header-count
integer specifying the number of header fields
header-value-size
integer specifying the size of each header field value (default is -32)
header-name-size
integer specifying the size of each header field name (default is -16)
header-name-prefix
string to prepend to all header field names (default is C<rnd->)

Note: all integer options can be either positive (meaning exactly this value) or negative (meaning randomly distributed around the value).

For instance:

mg = Generator(
    header_count = 10,
    header_value_size = -20,
)

It will generate messages with exactly 10 random header fields, each field value having a random size between 0 and 40 and normally distributed around 20.

set(option, value)

Set Generator option to value provided.

messaging.generator.maybe_randomize(size)

Maybe randomize int.

messaging.generator.rndb64(size)

Returns a random text string of the given size (Base64 characters).

messaging.generator.rndbin(size)

Returns a random binary string of the given size.

messaging.generator.rndint(size)

Returns a random integer between 0 and 2*size with a normal distribution.

See Irwin-Hall in http://en.wikipedia.org/wiki/Normal_distribution

messaging.generator.rndstr(size)

Returns a random text string of the given size (all printable characters).