AMPS provides the ability for incoming commands to be modified, or filtered.
Making changes
When one or more transport filters are specified, AMPS provides each incoming command to those filters as soon as the header for the message is parsed. Each filter can modify the message data or a subset of the headers, and can choose to have AMPS stop processing the command (or can request that AMPS disconnect the connection that submitted the command).
The filters for a Transport
, if any, are defined in the configuration for the transport. When more than one filter is specified, AMPS runs each filter in the order in which they appear in the configuration file.
Transport filters are implemented as extension modules. To create an extension module, contact AMPS support for the server SDK.
The following table doesn't really contain the most accurate since it is solely for testing purposes.
An internal function used to check if the configured retry has been exceeded, and if so, throw MaximumRetryExceeded to cause the calling HAClient to give up on reconnecting to a server.
AMPS loads the following transport filters by default:
Module | Description |
---|---|
amps-topic-translator |
Translates topic names on incoming commands. This module requires one or more of the following options: Specifies the translation to use. This option takes the following format:
|
{
if (_currentFree == 0)
{
return null;
}
if (_current >= _currentFree)
{
_current = 0;
}
return _uris[_current];
}
The original parameter can be a literal topic name or a PCRE regex. Any topic on any command that matches that parameter will be converted to the translated topic.
For example, to convert the topic legacy
to the topic new
, you would specify the following option:
<Options> <Topic>legacy:new</Topic> </Options>
To translate any topic beginning with /orders/northamerica
to NAorders
, you would specify the following option:
Gets the connection wait duration based on the provided URI:
public int getConnectWaitDuration(String uri_) throws Exception
{
_throwIfMaximumExceeded();
if(_lastUri == null || !lastUri.equals(uri))
{
lastUri = uri;
if(_firstUri != null && firstUri.equals(uri))
{
// we've wrapped around the "list." Delay.
return _currentDurationAndIncrease();
}
else if(_firstUri == null)
{
firstUri = uri;
}
return 0;
}
return _currentDurationAndIncrease();
}
Options and DefaultServerChooser Code:
Have a condition.
<Options>
<Topic>^/orders/northamerica:NAorders</Topic>
</Options>
public DefaultServerChooser add(String uri) { if (_currentFree >= _uris.length) { String[] newUris = new String[_uris.length * 2]; System.arraycopy(_uris, 0, newUris, 0, _uris.length); _uris = newUris; }
_uris[_currentFree] = uri; ++_currentFree; return this; }
Gets the connection wait duration based on the provided URI.
| |public <T extends Collection<String> > DefaultServerChooser addAll(T uris) { int urisSize = uris.size(); if (_currentFree >= _uris.length - urisSize) { int newLength = (_uris.length<urisSize)?_uris.length+urisSize:_uris.length*2; String[] newUris = new String[newLength]; System.arraycopy(_uris, 0, newUris, 0, _uris.length); _uris = newUris; }
for (String uri : uris) { _uris[_currentFree] = uri; ++_currentFree; } return this; }
amps-conflated-topic-translator
| Translates an incoming subscribe
, sow_and_subscribe
, delta_subscribe
, or sow_and_delta_subscribe
command for a specific topic name as follows:
- Translates the topic name on the command to a different topic name.
- Adds a conflation interval to the command, if there is no conflation interval specified on the incoming command.
This module can be useful for removing a conflated topic that is infrequently-used, or for which subscribers only monitor a small number of messages out of the overall topic.
This module requires one or more of the following options: Topic
Specifies the translation to use. This option takes the following format:
original :
translated :
interval
The interval specifies the conflation interval to apply to the translated commands if one is not provided.
For example, to convert all subscriptions to the topic orders-C
to the topic orders
, and guarantee that each translated subscription has a conflation specified, with a 500 millisecond default for conflation, you would use the following options:
<Options> <Topic>orders-C:orders:500ms</Topic> </Options>
To convert all subscriptions to the topics slowUpdates
and verySlowUpdates
to the topic updates
and guarantee that each translated subscription has a conflation specified, with a 2 second default for conflation, you would use the following options:
<Options> <Topic>slowUpdates:updates:2s</Topic> <Topic>verySlowUpdates:updates:2s</Topic> </Options>