How to send messages always synchronously

FIX Antenna Java supports few modes for sending messages: SYNC, ASYNC and SYNC_NOQUEUE. The strategy for FIX session is configured by preferredSendingMode option.

The main difference between SYNC and SYNC_NOQUEUE is that SYNC mode support internal queuing and you can push messages even for a disconnected session - FIX Antenna will send them later. But, at the same time, it means that session may switch to the asynchronous message sending to handle messages from the queue. Also, due to internal logic, such session may use queue if few threads are trying to send messages at the same time. For example, the engine may try to send ResendRequest to close detected gap or send HeartBeat/TestRequest withing the other than customer's thread.

SYNC_NOQUEUE mode doesn't use the internal message queue at all and always send messages synchronously. But it means that any queuing should be done in client's code. Additionally, it needs to handle any errors during sending.


SessionParameters details = new SessionParameters();
...
// Set SYNC_NOQUEUE sending mode for session
details.getConfiguration().setProperty(Configuration.PREFERRED_SENDING_MODE, SendingMode.SYNC_NOQUEUE.name());
FIXFieldList messageContent = new FIXFieldList();

try {
    session.sendMessage(messageContent);
} catch (MessageNotSentException ex) {
    // Message wasn't delivered to counterparty.
    // You can try to repeat sending of this message after session reconnect.
    externalQueue.add(messageContent);

} catch (IllegalStateException e) {
    // Session was disconnected.
    // You can try to repeat sending of this message after session reconnect.
    externalQueue.add(messageContent);
}