9. State-of-the-World (SOW) Features¶
The SOW
section of the configuration file holds the configuration
for the AMPS State of the World.
Element | Description |
---|---|
Topic |
Specifies that AMPS will record distinct messages for this topic in the State of the
World. SOW topic definitions are used directly as a last-value cache, and are
required for many of the advanced messaging features in AMPS such as out-of-focus
notifications and delta messaging. SOW topic definitions can also be used as the
underlying topics for views, aggregates, and conflated topics. SOW Topic
configuration is described in SOW/Topic. |
Queue |
Defines a message queue. Rather than delivering each message to all matching subscriptions, message queues provide features to help ensure that each message is delivered to and processed by a single subscriber. See the User Guide for a full description of the functionality of message queues. Queue configuration is described in SOW/Queue. |
View |
Defines a View over one or more SOW topics, conflated topics, or other views. A view can perform aggregation, can JOIN multiple topics together. A view can be based on a SOW topic of one message type and project results of a different message type. View configuration is described in SOW/View. |
ConflatedTopic |
Defines a copy of a SOW topic or view that receives current value updates at a specified interval, conflating any changes to values that occur between the scheduled updates. ConflatedTopic configuration is described in SOW/ConflatedTopic. |
Table 9.1: SOW section configuration elements
The elements within the SOW section are described in detail in the following sections.
SOW/Topic¶
SOW/Topic
Creating a Topic
element in the SOW configuration section
declares that AMPS will maintain state of the world for that topic. When
a topic is recorded in the State of the World (SOW), AMPS maintains the
most recent value of each distinct message in that topic. In this
respect, the SOW for a topic is similar to a table in a relational
database.
Notice that AMPS does not require topics to be predeclared. Creating this configuration item is declaring that the State of the World will be maintained for this topic: the configuration does not define a topic. Creating this configuration item is not required to publish messages to the topic.
There are several sets of options required when a topic is added to the State of the World. General options define the topic name and the overall behavior of the State of the World for this topic. Key specification options define how AMPS identifies unique messages within the topic (much like declaring a primary key for a table in a relational database). Growth specification options define how AMPS grows storage for the State of the World for this topic as messages are added.
Example 9.1
contains a listing of the parameters for a Topic
section in the SOW
section of an AMPS configuration file. AMPS
accepts TopicDefinition
as a synonym for Topic
,
since this was the element name used in versions before 5.0.
This section presents brief descriptions of the options for recording the State of the World for a topic. For full information on the State of the World, see State of the World in the AMPS User Guide.
Element | Description |
---|---|
FileName
|
The file where the State of the World (SOW) data will be stored. This element is required for SOW topics with a |
MessageType
|
Type of messages to be stored. To use AMPS generated SOW keys, the message type specified must
support content filtering so that AMPS can determine the SOW key for the message. All of the
default message types, except See the Message Types chapter in the AMPS User Guide for a discussion of the message types that AMPS loads by default. Some message types (such as Google Protocol Buffers) require additional configuration, and must be configured before using the message type in a SOW topic. |
Name
|
The name of the SOW topic - all unique messages on this topic will be stored in a topic-specific SOW database. Every SOW requires a method of determining which messages are unique. Several methods are provided within AMPS. See the AMPS User Guide for a discussion on SOW keys, and Key Table for relevant configuration items. If no |
HashIndex |
AMPS provides the ability to do fast lookup for SOW records based on specific fields. When one or more The AMPS uses a hash index when a query uses a exact matching for all of the fields in the index. AMPS does not use hash indexes for range queries or regular expressions. AMPS automatically creates a hash index for the set of fields specified in the set of |
Index |
AMPS supports the ability to precreate memo indexes for specific fields using the When one or more |
RecoveryPoint |
For SOW topics that are covered by the transaction log, the point from which to recover the SOW
if the SOW file is removed, or if the SOW topic has This configuration item allows two values:
Defaults to |
Expiration |
Time for how long a record should live in the SOW database for this topic. The expiration time is stored on each message, so changing the expiration time in the configuration file will not affect the expiration of messages currently in the SOW. AMPS accepts interval values for the Expiration, using the interval format described in the AMPS Configuration Guide section on units, or one of the following special values:
Default: |
Durability |
Defines the data durability of a SOW topic. SOW databases listed as Notice that when the durability is Default: Valid values: Synonyms: |
History |
Enable historical query for this SOW. This element contains a
|
Window |
For a historical SOW, the length of time to store history. For example, when the value is Used within the Default: By default, AMPS does not expire historical SOW data. |
Granularity |
For a historical SOW, the granularity of the history to store. For many applications, it is not
necessary for AMPS to store all of the updates to the SOW. This parameter sets the resolution at
which AMPS will save the state of a message. A value of For example, when you set a granularity of Used within the |
ExpectedKeyCountHint |
For SOW topics that will contain a large number of distinct keys, providing an expected key count allows AMPS to pre-size the data structure that holds the key. This can provide a performance improvement for publishers by avoiding cases where AMPS has to resize the data structure. There is no default for this value. When no value is provided, AMPS does not pre-size data structures for the SOW. When provided, the value of this option should be the power of 2 closest to the maximum
number of keys the topic is expected to hold. For example, a topic that is expected to hold
500,000,000 distinct records could set a value of |
Preprocessing |
When present, specifies the message enrichment to be performed before AMPS determines the SOW key for the message. The |
Enrichment |
When present, specifies the message enrichment to be performed after AMPS determines the SOW key for the message. The |
Table 9.2: SOW/Topic General Options
Each SOW topic must define how AMPS will determine which messages are
unique. An application can either have AMPS determine the key by
specifying one or more Key
fields, provide a SOW key with the
publish
command each time a message is published to AMPS. AMPS also
provides the ability to provide a custom SowKey generator with a plugin
module.
See the Sow Key Generation section in the AMPS User Guide for for a full discussion. The following table lists the available configuration items for specifying how AMPS determines the SowKey for a message:
Element | Description | ||||||
---|---|---|---|---|---|---|---|
Key |
Specifies an XPath within each message that AMPS will use to generate a SOW key, which
determines whether a message is unique. This element can be specified multiple times to create a
composite key from the combined value of the specified When one or more 60East recommends configuring a AMPS automatically creates a hash index for the set of fields specified in the There is no default for this element. |
||||||
KeyDomain |
The seed value for For example, if your application has a This option can only be specified when one or more Default: the name of the SOW topic. |
||||||
KeyGenerator |
Specifies the SOW key generator module to use for this topic. When this configuration element is present, AMPS calls the specified module to generate a SOW key for each incoming message. Default: no SOW key generator module. When there is no SOW key generator module specified, AMPS
uses the specified A KeyGenerator element contains the following elements:
|
Table 9.3: SOW/Topic Key Specification Options
The SOW topic configuration also specifies how the SOW file is allowed to grow. See the AMPS User Guide for details on SOW growth. The configuration options for controlling how the file is allocated and how the file grows are listed below:
Element | Description |
---|---|
SlabSize |
The size of each allocation for the SOW file, as a number of bytes. When AMPS needs more space for the SOW, it requests this amount of space from the operating system. This effectively sets the maximum message size that AMPS guarantees can be stored in the SOW. This size includes headers set by AMPS on the message. 60East recommends setting this value only if you will be storing messages larger than the
default If it becomes necessary to tune the Default: |
InitialSlabCount |
The number of SOW slabs that AMPS will allocate on startup. Default: Maximum: |
DEPRECATED:
|
This parameter is deprecated beginning in AMPS 5.0. Use Default: |
DEPRECATED:
|
This parameter is deprecated beginning in AMPS 5.0. Use the Default: |
DEPRECATED:
|
This parameter is deprecated beginning in AMPS 5.0. Use the Default: |
Table 9.4: SOW/Topic Growth Specification Options
An example of a SOW configuration looks like the following:
<SOW>
<!-- Simple SOW topic definition -->
<Topic>
<Name>orders</Name>
<Key>/orderId</Key>
<MessageType>nvfix</MessageType>
<FileName>./sow/%n.sow</FileName>
</Topic>
<!-- SOW with hash indexes -->
<Topic>
<Name>customers</Name>
<Key>/customerId</Key>
<MessageType>json</MessageType>
<FileName>./sow/%n.sow</FileName>
<HashIndex>
<Key>/customerName</Key>
</HashIndex>
<HashIndex>
<Key>/zipCode</Key>
<Key>/customerType</Key>
</HashIndex>
</Topic>
<!-- Historical SOW -->
<Topic>
<Name>catalog</Name>
<Key>/sku</Key>
<MessageType>json</MessageType>
<FileName>./sow/%n.sow</FileName>
<History>
<Window>7d</Window>
<Granularity>15m</Granularity>
</History>
</Topic>
<!-- SOW with enrichment Add a /fullName field constructed
from /firstName and /lastName. -->
<Topic>
<Name>sales-reps</Name>
<Key>/employeeId</Key>
<MessageType>bflat</MessageType>
<Enrichment>
<Field>CONCAT(/firstName, " ", /lastName) AS /fullName</Field>
</Enrichment>
</Topic>
</SOW>
Example 9.1: SOW Topic Configuration
SOW/Queue, SOW/LocalQueue, and SOW/GroupLocalQueue¶
This section lists configuration parameters for queues.
The Queue
tag, the LocalQueue
tag, and the GroupLocalQueue
tag
are used to configure message queues.
When an AMPS queue is defined with the Queue
tag, the queue will be
a distributed queue. To make a queue that is limited to the local
instance, use the LocalQueue
configuration element. To make a queue
that is restricted to a subset of instances in a set of replicated instances
(typically all in the same group), use the GroupLocalQueue
tag.
AMPS accepts QueueDefinition
as a synonym for Queue
.
The following configuration items apply to queues regardless of whether they are fully distributed, local, or distributed within a replication group:
Element | Description |
---|---|
Name
|
The name of the queue topic. This name is the name that consumers subscribe to. If no |
MessageType
|
The message type of the queue. |
UnderlyingTopic |
A topic name or regular expression for the topic that contains the messages to capture in the queue. These topics must be recorded in a transaction log, and all must be of the same message type as the queue. If an |
DefaultPublishTarget |
The topic to publish to when an application publishes a message to the queue. For simplicity, AMPS allows applications to publish messages to the queue, and for those messages to be routed to one of the underlying topics. The This element is required if the |
LeasePeriod |
The amount of time that a subscriber has ownership of the message before
the message is returned to the queue. For The Default: |
Semantics |
The delivery semantics to use for this queue. Regardless of the delivery semantics, AMPS queues deliver a given message to a single subscriber at a time. When a subscriber fails to process a message (that is, the connection to the subscriber closes before the message is acknowledged, or the lease expires before the message is acknowledged), the semantics specify how the failure is handled.
Default: |
MaxBacklog |
The maximum number of outstanding, unacknowledged messages in the queue at any one time. This parameter allows you to set limits on the number of pending messages from the queue overall. When the queue reaches the MaxBacklog, no incoming messages are delivered from the queue until a message is removed from the queue (either by expiring, or being acknowledged by a client). This parameter allows you to avoid overwhelming clients during periods of heavy activity. Notice that this does not set a limit of any sort on the capacity of the queue. This parameter allows you to limit the number of messages that the queue will make available to subscribers at a given time, but does not restrict the capacity of the queue to track messages. This backlog number is applied per instance of the queue. That is,
each instance of AMPS that hosts an instance of a replicated queue will
deliver messages up to the Default: |
MaxPerSubscriptionBacklog |
The maximum number of outstanding, unacknowledged messages in the queue for an individual subscription. This parameter allows you to avoid overwhelming a single subscriber during a period of heavy activity. Subscribers can declare the maximum number of messages that the subscription is prepared to lease at a given time. This maximum defaults to 1 when there is no maximum explicitly specified for a subscription. AMPS will lease the number specified in the subscription or the maximum set for the queue, whichever is lower. Notice that this does not set a limit of any sort on the capacity of the queue. This parameter allows you to limit the number of messages that the queue will make available for a single subscription at a given time, but does not restrict the capacity of the queue to track messages. Default: |
Expiration |
The length of time a message can remain in the queue before AMPS considers the message undeliverable. Messages may expire while a subscriber has a lease on the message. AMPS does not send an additional notification in this case. A publisher can override this setting by providing an expiration value on an incoming message. If an individual message in the transaction log has an expiration value, AMPS will use that expiration value for the message rather than the default for the queue. Default: |
Filter |
An AMPS By default, there is no filter and all messages from the UnderlyingTopic are presented in the queue. |
RecoveryPoint |
This option allows you to specify the point at which AMPS begins reviewing the transaction log to recover the state of the queue when AMPS restarts and there is no existing information about the state of the queue. By default, in this case AMPS reviews the full log to determine the contents and state of the queue. If AMPS has a record of the last point in the transaction log at which
all previous messages are acknowledged (stored in the The
Default: |
FairnessModel |
AMPS provides different methods to distribute messages across active subscriptions:
Default: |
Leasing |
Ownership model for leased messages. AMPS supports the following models:
Default: |
MaxDeliveries |
Specifies an upper bound to the number of times AMPS may deliver a queue
message before automatically expiring it. For example if AMPS delivers
a message twice and This counter is reset if the server restarts, and the counter is not replicated to other instances. Default: no maximum ( |
MaxCancels |
Specifies a limit to the number of times a subscriber may cancel a lease
on a message before it is expired. For example if a message is canceled
for the second time and This counter is reset if the server restarts, and the counter is not replicated to other instances. Default: no maximum ( |
Priority |
Specifies the order in which messages will be distributed from the queue. When present, this element constructs a value that specifies the priority for messages in the queue. Higher priority messages are delivered first, regardless of the order in which messages have been published to the queue. The contents of the element can be either the name of a field in the
message or an AMPS expression. Either way, the result is treated as an
For example, to order message delivery based on the <Priority>/priority</Priority>
To order message delivery based on the product of the <Priority>/price * /qty</Priority>
Default: there is no default for this value. When not provided, the delivery order is the order in which messages were processed by this instance of AMPS. This option cannot be specified on a queue if |
BarrierExpression |
Specifies the filter used to identify a barrier message (synchronization point) for this queue. When a message matches this expression, it will be delivered to all current subscribers on the queue when every previous message in the queue has been acknowledged. This provides a simple, reliable way to synchronize workers. <BarrierExpression>/isSyncPoint IS NOT NULL</BarrierExpression>
The Default: there is no default for this value. When not provided, no messages are considered to be barrier messages This option cannot be specified on a queue if |
DeferredAckExpiration |
Specifies the amount of time for AMPS to retain information about an
acknowledgment ( This element is configured as an interval, for example, The default value is generally recommended. However, in cases where an instance may receive large volumes of acknowledgments for messages that are not currently in the queue, and are not expected to arrive, setting this to a lower value may somewhat reduce the memory required for managing these acknowledgments. Default: |
Table 9.5: Queue configuration elements
When a queue is defined as a GroupLocalQueue
, the following configuration item must be provided:
Element | Description |
---|---|
InitialOwner
|
For a group local queue, provides the instance This configuration element is required for a All instances in a replicated system that define this queue must
define the same Notice that AMPS does not validate that the This element is required. There is no default for this element. |
Table 9.6: Additional configuration elements for GroupLocalQueue
The following configuration snippet shows one way to configure a queue.
<!-- Notice that the topics to use for the queue (ORDERS_.*) must be
recorded in a transaction log. -->
<SOW>
<Queue>
<Name>MQ</Name>
<MessageType>json</MessageType>
<UnderlyingTopic>ORDERS_.*</UnderlyingTopic>
<DefaultPublishTarget>ORDERS_DIRECT</DefaultPublishTarget>
<LeasePeriod>60s</LeasePeriod>
<Expiration>1d</Expiration>
<MaxBacklog>3</MaxBacklog>
</Queue>
</SOW>
SOW/View¶
Table 9.6 contains a listing of the parameters for a View
section in the SOW
section of an AMPS configuration file. For
backward compatibility, AMPS accepts ViewDefinition
as a synonym for View
.
Element | Definition |
---|---|
MessageType
|
The message type of the view. This does not need to be the same type as any of the topics in the aggregation, but does need to be a message type that supports views. The message type must be one of the message types
configured for the instance. AMPS includes Notice that the Other message types provided with AMPS may have limitations in their support for views. see the Message Types chapter in the AMPS User Guide for a discussion of the limitations. |
Name
|
Defines the topic name for this view. If no |
UnderlyingTopic
|
Defines the SOW topic or topics on which this view is
based. This element can contain a single topic name,
or any number of Join elements. |
Projection/Field
|
Defines what the view will contain. This element can be specified multiple times to compose a complex view. Complex expressions that use aggregation functions and conditional branching can also be used. |
Grouping/Field
|
Defines how the records in the underlying topic will be grouped. This is analogous to a SQL GROUP BY clause. |
KeyDomain |
The seed value for SowKeys used within this topic.
The default is the topic name, but it can be changed
to a string value to unify SowKey values between
different topics. |
Join |
Within an An |
Conflation |
Defines whether AMPS will attempt to conflate updates to the view. This item accepts two values:
Default: |
Filter |
Defines a filter for the view. When provided, only messages from the underlying topic that match this filter will be included in the view. This option is only valid when the view uses a
single Default: No filter, which includes all messages from
the |
HashIndex |
AMPS provides the ability to do fast query lookup for records in a view based on specific fields. When one or more The AMPS uses a hash index when a query uses an exact string match for all of the fields in the index. AMPS does not use hash indexes for range queries or regular expressions, or for numeric comparisions. AMPS automatically creates a hash index for the fields
specified in the |
JoinNullEquivalency |
Specifies whether the Default: |
FileName |
File location to store view data. Unused in this version of AMPS. |
Table 9.6: SOW/View
<SOW>
<!-- Single topic aggregation -->
<Topic>
<Topic>/ett/order</Topic>
<MessageType>fix</MessageType>
<Key>/orderId</Key>
</Topic>
<View>
<MessageType>nvfix</MessageType>
<Topic>TOTAL_VALUE</Topic>
<UnderlyingTopic>/ett/order</UnderlyingTopic>
<Projection>
<Field>/109</Field>
<Field>SUM(/14 * /6) AS /71406</Field>
</Projection>
<Grouping>
<Field>/109</Field>
</Grouping>
</View>
<!-- Single topic aggregation with filter -->
<Topic>
<Name>orders</Name>
<MessageType>json</MessageType>
<Key>/orderId</Key>
<FileName>./sow/%n.sow</FileName>
</Topic>
<View>
<Name>CompleteByRegion</Name>
<UnderlyingTopic>orders</UnderlyingTopic>
<MessageType>json</MessageType>
<Projection>
<Field>COUNT(/orderId) AS /completedOrders</Field>
<Field>/region AS /region</Field>
</Projection>
<Grouping>
<Field>/region</Field>
</Grouping>
<Filter>/status = 'complete'</Filter>
</View>
<!-- Single topic aggregation with a hash index
for faster query. -->
<Topic>
<Name>source-for-hash-sample</Name>
<MessageType>json</MessageType>
<Key>/id</Key>
<FileName>./sow/%n.sow</FileName>
</Topic>
<View>
<Name>hash-sample-view</Name>
<MessageType>json</MessageType>
<UnderlyingTopic>source-for-hash-sample</UnderlyingTopic>
<Projection>
<Field>SUM(/qty) as /quantity</Field>
<Field>/customerName</Field>
<Field>/orderType</Field>
</Projection>
<Grouping>
<Field>/customerName</Field>
<Field>/orderType</Field>
</Grouping>
<!-- provide fast query for exact matches on
*either* name or orderType -->
<HashIndex>
<Key>/name</Key>
</HashIndex>
<HashIndex>
<Key>/orderType</Key>
</HashIndex>
</View>
<!-- Project from one message type to another -->
<Topic>
<Name>example</Name>
<MessageType>json</MessageType>
<Key>/id</Key>
<FileName>./sow/%n.sow</FileName>
</Topic>
<View>
<!-- notice that nvfix topic named 'example' is not the same topic as the json
topic named 'example' -->
<Name>example</Name>
<MessageType>nvfix</MessageType>
<UnderlyingTopic>[json].[example]</UnderlyingTopic>
<Projection>
<Field>[json].[example]./id AS /id</Field>
</Projection>
<Grouping>
<Field>[json].[example]./id</Field>
</Grouping>
</View>
<!-- JOIN topics -->
<Topic>
<Name>ORDERS</Name>
<MessageType>nvfix</MessageType>
<Key>/OrderID</Key>
<FileName>./sow/%n.sow</FileName>
</Topic>
<Topic>
<Name>COMPANIES</Name>
<MessageType>nvfix</MessageType>
<Key>/CompanyId</Key>
<FileName>./sow/%n.sow</FileName>
</Topic>
<View>
<Name>TOTAL_COMPANY_VOLUME</Name>
<UnderlyingTopic>
<Join>[ORDERS]./Tick = [COMPANIES]./Tick</Join>
</UnderlyingTopic>
<MessageType>nvfix</MessageType>
<Projection>
<Field>[COMPANIES]./CompanyId</Field>
<Field>[COMPANIES]./Tick</Field>
<Field>[COMPANIES]./Name</Field>
<Field>SUM([ORDERS]./Shares) AS /TotalVolume</Field>
</Projection>
<Grouping>
<Field>[ORDERS]./Tick</Field>
</Grouping>
</View>
</SOW>
Example 9.2: View Example
SOW/ConflatedTopic¶
AMPS provides the ability to create ongoing snapshots of a SOW topic, called conflated topics (also called topic replicas in previous releases of AMPS). Topic replicas are updated on an interval, and store a snapshot of the current state of the world at each interval. This helps to manage bandwidth to clients that do not act on each update, such as a client UI that refreshes every second rather than with every update.
For compatibility with previous versions of AMPS, AMPS allows you to use
ReplicaDefinition
as a synonym for ConflatedTopic
.
Element | Description |
---|---|
Name
|
String used to define the name of the conflated topic.
While AMPS doesn’t enforce naming conventions, it can
be convenient to name the conflated topic based on the
underlying topic name. For example, if the underlying
topic is If no |
UnderlyingTopic
|
String used to define the SOW topic which provides updates to the conflated topic. This must exactly match the name of a SOW topic. |
MessageType
|
The message format of the underlying topic. This
MessageType must be the MessageType of the
provided UnderlyingTopic . |
Interval |
The frequency at which AMPS updates the data in the conflated topic. Default: Minimum: |
Filter |
Content filter that is applied to the underlying topic. Only messages that match the content filter are stored in the conflated topic. |
HashIndex |
AMPS provides the ability to do fast lookup for SOW records based on specific fields. When one or more The AMPS uses a hash index when a query uses a exact matching for all of the fields in the index. AMPS does not use hash indexes for range queries or regular expressions. AMPS automatically creates a hash index for the set of fields specified in the set of |
Table 9.7: SOW/ConflatedTopic Parameters
<ConflatedTopic>
<Topic>FastPublishTopic-C</Topic>
<MessageType>nvfix</MessageType>
<UnderlyingTopic>FastPublishTopic</UnderlyingTopic>
<Interval>5s</Interval>
<Filter>/region = 'A'</Filter>
</ConflatedTopic>
<ConflatedTopic>
<Topic>LongIntervalTopic-C</Topic>
<MessageType>json</MessageType>
<UnderlyingTopic>FastPublishTopic</UnderlyingTopic>
<Interval>120s</Interval>
<HashIndex>
<Key>/order/status</Key>
</HashIndex>
</ConflatedTopic>