Show Table of Contents

Creating and Sending FIX Messages

For each message type defined in the XML schema (e.g., NewOrderSingle), the Chronicle FIX CodeGenerator creates a corresponding interface. It is recommended to use these interfaces whenever possible. For each interface, the CodeGenerator generates two implementations:

  • DefaultXXX (e.g., DefaultNewOrderSingle): These are Data Transfer Objects (DTOs) or Plain Old Java Objects (POJOs) that support a straightforward programming model. Fields have standard getters and setters, and there is a toString() method available. See Creating Messages as DTOs for more details.

  • MessageGenerator: This implementation is more concise and performance-optimized, but does not support getters. Setters are non-idempotent, meaning each message field should be set only once. Once a field is set, it cannot be read or changed, as data is streamed directly to a buffer rather than stored in a DTO. If a setter is called twice for the same field, the value is written to the buffer twice. The order in which fields are set determines the order they are written to the buffer. This method is ideal for scenarios where the order of fields matters and is the highest performing way to send messages. See Creating Messages Using MessageGenerator for more information.

Writing data directly to a buffer is more efficient than writing to a DTO, as it avoids making an intermediate copy. However, because data is streamed directly, if any field in a message changes, the entire message must be rewritten. Thus, messages created this way are write-only.

The table below summarises the key differences between MessageGenerator and DTO messages:

MessageGenerator

DTO

  • Faster, with one less copy than DTOs

  • No toString() method

  • Non-idempotent setters; fields should be set only once

  • No getters; fields cannot be read or changed after being set

  • Fields are written to the buffer in the order they are set

  • Session fields (e.g., PossDupFlag) can be set

  • Supports a straightforward programming model with getters, setters, and toString()

  • Easier to debug; you can set watches on individual getters or fields

  • Message fields are written in the order defined in the XML dictionary, enabling optimal parsing by Chronicle FIX

  • Does not require a FixSessionContext

  • No need to manage a Bytes object or its lifecycle/thread safety

  • Messages are validated before being sent (see Validation)

  • If session fields (e.g., PossDupFlag) are set in DTOs, they are ignored when sendMessage() is called