In-memory data context
- 1 Overview
- 2 Configuration
- 3 Examples
- 3.1 ClOrdID replacement
- 3.2 Saving/updating data
- 3.2.1 rules.groovy
- 3.3 Getting/removing data
- 3.3.1 rules.groovy
- 3.4 Saving repeating group
- 3.4.1 rules.groovy
- 3.5 Getting repeating group
- 3.5.1 rules.groovy
Overview
FIXEdge/J provides an ability to store information in the memory for purposes of message enrichment during the routing process. This functionality is based on a key-value storage.
While processing a message from one endpoint to another, FIXEdge/J may store any information in the storage and then retrieve it while routing in the opposite direction.
Advantages: in-memory data storing confers performance advantages.
Disadvantages: FIXEdge/J will lose all stored information on restart.
Configuration
There are several methods in the Groovy rules that can be used for this functionality:
Method name | Methods signature | Description | Example | ||
|---|---|---|---|---|---|
saveContext | Object saveContext(Object key, Object value) | Associates the specified value with the specified key in this storage. If the storage previously contained a mapping for the key, the former value is replaced by the specified value.
Params:
Returns:
|
or
| ||
removeContext | Object removeContext(Object key) | Removes the mapping for the key from the given storage if it is present. The storage will not contain a mapping for the specified key once the call returns. Params:
Returns:
|
| ||
getContext | Object getContext(Object key) | Returns the value to which the specified key is mapped, or NULL if this map contains no mapping for the key. Params:
Returns:
|
or
| ||
cleanContext | void cleanContext(Predicate<Map.Entry<Object, Object>> consumer) | Removes entries from the context according to the provided predicate. |
|
Examples
ClOrdID replacement
Business case: Broker should replace the identificators provided by the Clients to the IDs corresponding to Exchange's requirements and format.
Saving/updating data
rules.groovy
...
def senderCompID = msg.getTagValueAsString(49)
def clOrdId = msg.getTagValueAsString(11)
def uniqueId = generateUniqueId()
saveContext(uniqueId, [49: senderCompID, 11: clOrdId])
msg.set(11, uniqueId)
//route message
...Getting/removing data
rules.groovy
...
def uniqueId = msg.getTagValueAsString(11)
def savedContext = getContext(uniqueId)
removeContext(uniqueId)
msg.set(11, savedContext.get(11))
msg.set(56, savedContext.get(49))
//route message
...