MigratoryData Client API for DotNet
Developer's Guide and Reference Manual
|
This class implements all the necessary operations for connecting to a cluster of one or more MigratoryData servers, subscribing to subjects, getting real-time messages for the subscribed subjects, and publishing real-time messages. More...
Public Member Functions | |
MigratoryDataClient () | |
Create a MigratoryDataClient object. | |
void | SetLogListener (Object logListener, MigratoryDataLogType logType) |
Define a log listener object and configure the logging level. More... | |
void | SetListener (MigratoryDataListener listener) |
Attach a MigratoryDataListener for handling real-time messages and status notifications. More... | |
void | SetServers (string[] servers) |
Specify a cluster of one or more MigratoryData servers to which the client will connect to. More... | |
void | Subscribe (List< string > subjects) |
Subscribe to one or more subjects. More... | |
void | SubscribeWithConflation (List< string > subjects, int conflationTimeMillis) |
Subscribe to one or more subjects with conflation. More... | |
void | SubscribeWithHistory (List< string > subjects, int numberOfHistoricalMessages) |
Subscribe to one or more subjects after getting historical messages for those subjects. More... | |
void | Unsubscribe (List< string > subjects) |
Unsubscribe from one or more subjects. More... | |
void | SetEncryption (bool b) |
Configure whether to use SSL/TLS encryption when connecting to a MigratoryData server. More... | |
void | SetEntitlementToken (string token) |
Assign an authorization token to the client. More... | |
List< string > | GetSubjects () |
Return the list of subscribed subjects. More... | |
void | SetServersDownBeforeNotify (int n) |
Define the number of failed attempts to connect to one or more MigratoryData servers before triggering a status notification MigratoryDataClient.NOTIFY_SERVER_DOWN. More... | |
void | Disconnect () |
Disconnect from the connected MigratoryData server and dispose the resources used by the connection. More... | |
void | Publish (MigratoryDataMessage message) |
Publish a message. More... | |
void | NotifyAfterReconnectRetries (int retries) |
Define the number of failed attempts to connect to one or more MigratoryData servers before triggering a status notification MigratoryDataClient.NOTIFY_SERVER_DOWN. More... | |
void | SetQuickReconnectMaxRetries (int retries) |
Define the maximum number of retries for the Quick Reconnect failover phase. More... | |
void | SetQuickReconnectInitialDelay (int seconds) |
Define the number of seconds to wait before attempting to reconnect to the cluster after a connection failure is detected. More... | |
void | SetReconnectPolicy (string policy) |
Define the reconnect policy to be used after the Quick Reconnect phase. More... | |
void | setReconnectTimeInterval (int seconds) |
Define the time interval used for the reconnect schedule after the Quick Reconnect phase. More... | |
void | setReconnectMaxDelay (int seconds) |
Define the maximum reconnect delay for the MigratoryDataClient.TRUNCATED_EXPONENTIAL_BACKOFF policy. More... | |
Static Public Attributes | |
static readonly string | NOTIFY_SERVER_UP = "NOTIFY_SERVER_UP" |
Indicate that the client successfully connected to a MigratoryData server. More... | |
static readonly string | NOTIFY_SERVER_DOWN = "NOTIFY_SERVER_DOWN" |
Indicate that the client failed to connect to a MigratoryData server. More... | |
static readonly string | NOTIFY_DATA_SYNC = "NOTIFY_DATA_SYNC" |
After a failover reconnection, the client resynchronized a subscribed subject with the latest message available for that subject, as well as with all messages published during the failover for that subject. More... | |
static readonly string | NOTIFY_DATA_RESYNC = "NOTIFY_DATA_RESYNC" |
After a failover reconnection, the client resynchronized a subscribed subject with the latest message available for that subject, but not with the potential messages published during the failover, therefore behaving as a new client. More... | |
static readonly string | NOTIFY_SUBSCRIBE_ALLOW = "NOTIFY_SUBSCRIBE_ALLOW" |
Indicate that the client was authorized to subscribe to a subject. More... | |
static readonly string | NOTIFY_SUBSCRIBE_DENY = "NOTIFY_SUBSCRIBE_DENY" |
Indicate that the client was not authorized to subscribe to a subject. More... | |
static readonly string | NOTIFY_SUBSCRIBE_TIMEOUT = "NOTIFY_SUBSCRIBE_TIMEOUT" |
static readonly string | NOTIFY_PUBLISH_OK = "NOTIFY_PUBLISH_OK" |
Indicate that the client successfully published a message. More... | |
static readonly string | NOTIFY_PUBLISH_FAILED = "NOTIFY_PUBLISH_FAILED" |
Indicate that the client was unable to publish a message. More... | |
static readonly string | NOTIFY_PUBLISH_DENIED = "NOTIFY_PUBLISH_DENIED" |
Indicate that the client was unable to publish a message because it is not allowed by the entitlement system. More... | |
static readonly string | NOTIFY_PUBLISH_NO_SUBSCRIBER = "NOTIFY_PUBLISH_NO_SUBSCRIBER" |
Indicate that the client was unable to publish a message because there is no client subscribed to the subject of the message. More... | |
static readonly string | CONSTANT_WINDOW_BACKOFF = "CONSTANT_WINDOW_BACKOFF" |
A constant used to define the reconnect policy. More... | |
static readonly string | TRUNCATED_EXPONENTIAL_BACKOFF = "TRUNCATED_EXPONENTIAL_BACKOFF" |
A constant used to define the reconnect policy. More... | |
This class implements all the necessary operations for connecting to a cluster of one or more MigratoryData servers, subscribing to subjects, getting real-time messages for the subscribed subjects, and publishing real-time messages.
void MigratoryDataClient.SetLogListener | ( | Object | logListener, |
MigratoryDataLogType | logType | ||
) |
Define a log listener object and configure the logging level.
The log listener object should belong to a class which implements the MigratoryDataLogListener interface.
It is advisable to configure this API call first if you want to log as much as possible.
logListener | An instance of a class which implements the MigratoryDataLogListener interface |
logType | The logging verbosity (MigratoryDataLogType.ERROR, MigratoryDataLogType.INFO, MigratoryDataLogType.DEBUG or MigratoryDataLogType.TRACE ); by default there is no logging. |
void MigratoryDataClient.SetListener | ( | MigratoryDataListener | listener | ) |
Attach a MigratoryDataListener for handling real-time messages and status notifications.
listener | An instance of a class which implements the MigratoryDataListener interface |
void MigratoryDataClient.SetServers | ( | string [] | servers | ) |
Specify a cluster of one or more MigratoryData servers to which the client will connect to.
If you specify two or more MigratoryData servers, then all these MigratoryData servers should provide the same level of data redundancy, by making available for subscription the same set of subjects. This is required for achieving (weighted) load balancing, failover, and guaranteed message delivery of the system. In this way, the MigratoryData servers of the servers
list form a cluster.
For example, to connect to a cluster formed of two MigratoryData servers installed at the addresses p1.example.com
and p2.example.com
, and configured to accept connections on the standard HTTP port 80
, the following code can be used:
client.SetServers(new string[] {"p1.example.com:80", "p2.example.com:80"});
To achieve load-balancing, the API connects the client to a MigratoryData server chosen randomly from the servers
list. In this way, the load is balanced among all the members of the cluster.
Moreover, the API supports weighted load-balancing. This feature is especially useful if the MigratoryData servers in the cluster are installed on machines with different capacities. You can assign to each member of the cluster a weight ranging from
0
to100
. This weight assignment is a hint provided to the API to select with a higher probability a MigratoryData server with a higher weight either initially when the client connects to the cluster or later during a failover reconnection.Supposing the address
p1.example.com
corresponds to a machine that is twice more powerful than the machine having the addressp2.example.com
, then you can assign top1.example.com
a weight100
and top2.example.com
a weight50
by prefixing each address with the assigned weight as follows:
client.SetServers(new string[] {"100 p1.example.com:80", "50 p2.example.com:80"});
The API assigns a default weight
100
to the addresses not prefixed with a specific weight.
To achieve failover, if the connection between the client and a MigratoryData server is broken, then the API will automatically detect the failure and will select another MigratoryData server from the servers
list. If the client fails to connect to the new selected server, a status notification MigratoryDataClient.NOTIFY_SERVER_DOWN will be triggered (unless you modify the number of failed attempts with MigratoryDataClient.SetServersDownBeforeNotify()), and a new MigratoryData server in the cluster will be selected again and again until the client will be able to connect to one of the MigratoryData servers in the cluster. When successfully connected, the API will trigger a status notification MigratoryDataClient.NOTIFY_SERVER_UP.
Furthermore, if certified message delivery is enabled, then the potential messages published during the failover period for a subscribed subject, will be automatically retrieved from the cache of the MigratoryData server to which the client reconnects to and a status notification MigratoryDataClient.NOTIFY_DATA_SYNC will be triggered for that subject.
If, for example, the failover period is abnormally long, and the client is not able to retrieve, after a failover reconnection, the messages published during the failover period for one of its subscribed subjects, then the API will retrieve only the most recent message for that subject and will trigger a MigratoryDataClient.NOTIFY_DATA_RESYNC status notification for that subject, the client behaving as a new client which connects to the cluster at the moment of the failover reconnection.
For a complete discussion concerning the load balancing, failover, and certified message delivery features see the MigratoryData Architecture Guide (PDF, HTML).
servers | An array of strings where each string represents the network address (IP address or DNS domain name and its corresponding port) of a MigratoryData server, optionally prefixed by a weight ranging from 0 to 100 . If the weight prefix is not provided to an address, then the API will automatically assign to that address a default weight 100 . |
NullReferenceException | If the address of a MigratoryData server is null. |
SocketException | If the connection to the address of a MigratoryData server could not be established. |
FormatException | If the address of a MigratoryData server is not valid. |
void MigratoryDataClient.Subscribe | ( | List< string > | subjects | ) |
Subscribe to one or more subjects.
Subscribe for real-time messages having as subjects the strings provided in the subjects
parameter.
As an example, supposing the messages are market data updates having as subjects stock names. Then, to subscribe for the messages having as subjects /stocks/NYSE/IBM
and /stocks/Nasdaq/MSFT
the following code will be used:
List<string> subjects = new List<string>(); subjects.Add("/stocks/NYSE/IBM"); subjects.Add("/stocks/Nasdaq/MSFT"); client.Subscribe(subjects);
The subjects are strings having a particular particular syntax. See the Chapter "Concepts" in the MigratoryData Architecture Guide (PDF, HTML) to learn about the syntax of the subjects.
subjects | An array of strings representing subjects. |
void MigratoryDataClient.SubscribeWithConflation | ( | List< string > | subjects, |
int | conflationTimeMillis | ||
) |
Subscribe to one or more subjects with conflation.
Subscribe for real-time messages having as subjects the strings provided in the subjects
parameter.
If the optional parameter conflationTimeMillis
is used, then for each subject in the subjects
list given in argument, its messages will be aggregated in the MigratoryData server and published every conflationTimeMillis
milliseconds as aggregated data (containing only the latest value for that subject and its latest field values). The value of conflationTimeMillis
should be a multiple of 100
milliseconds, otherwise the MigratoryData server will round it to the nearest value multiple of 100
milliseconds (e.g. 76
will be rounded to 0
, 130
will be rounded to 100
, 789
will be rounded to 700
, ...). If the value of conflationTimeMillis
is 0
(or is rounded to 0
), then no conflation will apply, and data publication will be message-by-message with no message aggregation.
As an example, supposing the messages are market data updates having as subjects stock names. Then, to subscribe for the messages having as subjects /stocks/NYSE/IBM
and /stocks/Nasdaq/MSFT
using 1-second conflation the following code will be used:
List<string> subjects = new List<string>(); subjects.Add("/stocks/NYSE/IBM"); subjects.Add("/stocks/Nasdaq/MSFT"); client.SubscribeWithConflation(subjects, 1000);
The subjects are strings having a particular particular syntax. See the Chapter "Concepts" in the MigratoryData Architecture Guide (PDF, HTML) to learn about the syntax of the subjects.
subjects | An array of strings representing subjects. |
conflationTimeMillis | An optional argument defining the number of milliseconds used to aggregate ("conflate") the messages for each subject in the subjects list; default value is 0 meaning that no conflation will apply, and data publication will be message-by-message with no message aggregation. |
void MigratoryDataClient.SubscribeWithHistory | ( | List< string > | subjects, |
int | numberOfHistoricalMessages | ||
) |
Subscribe to one or more subjects after getting historical messages for those subjects.
Attempt to get the number of historical messages as defined by the argument numberOfHistoricalMessages
, for each subject in the argument subjects
, then subscribe for real-time messages having as subjects the strings provided in the subjects
parameter.
When Guranteed Message Delivery is enabled, each MigratoryData server in the cluster maintains an in-memory cache with historical messages for each subject. The cache of each subject is available in all servers of the cluster. The maximum number of messages held in cache is defined by the parameter MaxCachedMessagesPerSubject
of the MigratoryData server which defaults to 1,000 messages. The historical messages are continuously removed from the cache, but it is guaranteed that they are available in the cache at least the number of seconds defined by the parameter CacheExpireTime
which defaults to 180 seconds.
If the value of numberOfHistoricalMessages
is higher then the number of historical messages available in the cache, then the client will receive only the messages available in the cache. As a consequence, if you use a value higher than the value of the parameter MaxCachedMessagesPerSubject
of the MigratoryData server (which defaults to 1000), then you will get the entire cache before subscribing for real-time messages for the subjects specified with the API call.
List<string> subjects = new List<string>(); subjects.Add("/stocks/NYSE/IBM"); subjects.Add("/stocks/Nasdaq/MSFT"); client.SubscribeWithHistory(subjects, 10);
The subjects are strings having a particular syntax. See the Chapter "Concepts" in the MigratoryData Architecture Guide (PDF, HTML) to learn about the syntax of the subjects.
subjects | An array of strings representing subjects. |
numberOfHistoricalMessages | The number of historical messages to be retrieved from the cache of the MigratoryData server. A value 0 means that no historical messages has to be retrieved and, in this case, this API method is equivalent to the API method MigratoryDataClient.Subscribe(). A value larger that the value of the parameter MaxCachedMessagesPerSubject means the entire cache is retrieved. |
void MigratoryDataClient.Unsubscribe | ( | List< string > | subjects | ) |
Unsubscribe from one or more subjects.
Unsubscribe from the subscribed subjects provided in the subjects
parameter.
subjects | An array of strings representing subjects. |
void MigratoryDataClient.SetEncryption | ( | bool | b | ) |
Configure whether to use SSL/TLS encryption when connecting to a MigratoryData server.
When using encryption you have to connect to the ports of the MigratoryData servers that are configured to listen for encrypted connections. See the parameter ListenEncrypted
in the MigratoryData Configuration Guide (PDF, HTML).
b | Determine whether the client connects to the MigratoryData server using an encrypted SSL/TLS connection |
void MigratoryDataClient.SetEntitlementToken | ( | string | token | ) |
Assign an authorization token to the client.
To define which users of your application have access to which subjects, you will first have to set the parameter Entitlement
on true
in the configuration file of the MigratoryData server - see the parameter Entitlement
in the MigratoryData Configuration Guide (PDF, HTML).
Then, you will have to use the entitlement-related part of the MigratoryData Extension API to allow or deny certain users to subscribe to certain subjects.
token | A string representing an authorization token. |
List<string> MigratoryDataClient.GetSubjects | ( | ) |
Return the list of subscribed subjects.
void MigratoryDataClient.SetServersDownBeforeNotify | ( | int | n | ) |
Define the number of failed attempts to connect to one or more MigratoryData servers before triggering a status notification MigratoryDataClient.NOTIFY_SERVER_DOWN.
n | The number of the failed attempts to connect to one or more MigratoryData servers before triggering a status notification MigratoryDataClient.NOTIFY_SERVER_DOWN; default value is 1 . |
void MigratoryDataClient.Disconnect | ( | ) |
Disconnect from the connected MigratoryData server and dispose the resources used by the connection.
This method should be called when the connection is no longer necessary.
void MigratoryDataClient.Publish | ( | MigratoryDataMessage | message | ) |
Publish a message.
If you attach a closure to the message, you will receive a status notification about this message publication via MigratoryDataListener.OnStatus().
message | A MigratoryDataMessage message |
void MigratoryDataClient.NotifyAfterReconnectRetries | ( | int | retries | ) |
Define the number of failed attempts to connect to one or more MigratoryData servers before triggering a status notification MigratoryDataClient.NOTIFY_SERVER_DOWN.
retries | The number of the failed attempts to connect to one or more MigratoryData servers before triggering a status notification MigratoryDataClient.NOTIFY_SERVER_DOWN; default value is 1 . |
void MigratoryDataClient.SetQuickReconnectMaxRetries | ( | int | retries | ) |
Define the maximum number of retries for the Quick Reconnect failover phase.
retries | The maximum number of quick reconnect retries; default value is 3 . |
void MigratoryDataClient.SetQuickReconnectInitialDelay | ( | int | seconds | ) |
Define the number of seconds to wait before attempting to reconnect to the cluster after a connection failure is detected.
Connection failure is detected immediately for almost all users. For a few users which are subject to temporary, atypical network conditions, connection failure is detected after 30-40 seconds.
When a connection failure is detected, the API will attempt to reconnect to the servers of the MigratoryData cluster as follows: First, it will attempt to reconnect up to a number of times as defined by MigratoryDataClient.SetQuickReconnectMaxRetries() using small delays between retries (Quick Reconnection Phase). If the connection cannot be established after the Quick Reconnection Phase, then the API will attempt to reconnect less frequently according to the policy defined by MigratoryDataClient.SetReconnectPolicy().
The delays between retries are computed according to the following algorithm where the values of the variables involved are defined by the API methods having substantially the same names:
Quick Reconnect Phase (retries <= quickReconnectMaxRetries) -----------------------------------------------------------
(retries starts with 1 and increment by 1 at each quick reconnect)
reconnectDelay = quickReconnectInitialDelay * retries - random(0, quickReconnectInitialDelay)
After Quick Reconnect Phase (retries > quickReconnectMaxRetries) ----------------------------------------------------------------
(reset retries to start with 1 and increment by 1 at each reconnect)
If reconnectPolicy is CONSTANT_WINDOW_BACKOFF, then
reconnectDelay = reconnectTimeInterval
else if reconnectPolicy is TRUNCATED_EXPONENTIAL_BACKOFF, then
reconnectDelay = min(reconnectTimeInterval * (2 ^ retries) - random(0, reconnectTimeInterval * retries), reconnectMaxDelay)
For a few users which are subject to temporary, atypical network conditions, if reconnectDelay
computed with the algorithm above is less than 10 seconds, then it is rounded to 10 seconds.
seconds | The number of seconds to wait before attempting to reconnect to the cluster; default value is 5 seconds. |
void MigratoryDataClient.SetReconnectPolicy | ( | string | policy | ) |
Define the reconnect policy to be used after the Quick Reconnect phase.
See MigratoryDataClient.SetQuickReconnectInitialDelay() to learn about the Quick Reconnect phase and the reconnect schedule for the policy defined by this method.
policy | The reconnect policy to be used after the Quick Reconnect phase. The possible values are MigratoryDataClient.CONSTANT_WINDOW_BACKOFF and MigratoryDataClient.TRUNCATED_EXPONENTIAL_BACKOFF; the default value is MigratoryDataClient.TRUNCATED_EXPONENTIAL_BACKOFF. |
void MigratoryDataClient.setReconnectTimeInterval | ( | int | seconds | ) |
Define the time interval used for the reconnect schedule after the Quick Reconnect phase.
See MigratoryDataClient.SetQuickReconnectInitialDelay() to learn about the Quick Reconnect phase and how the value defined by this API method is used for the reconnect schedule.
seconds | A time interval expressed in seconds used for reconnect schedule; default is 20 seconds. |
void MigratoryDataClient.setReconnectMaxDelay | ( | int | seconds | ) |
Define the maximum reconnect delay for the MigratoryDataClient.TRUNCATED_EXPONENTIAL_BACKOFF policy.
See MigratoryDataClient.SetQuickReconnectInitialDelay() to learn how the value defined by this API method is used.
seconds | The maximum reconnect delay when the policy MigratoryDataClient.TRUNCATED_EXPONENTIAL_BACKOFF is used; default value is 360 seconds. |
|
static |
Indicate that the client successfully connected to a MigratoryData server.
This constant indicates that the client successfully connected to one of the MigratoryData servers defined with the API method MigratoryDataClient.SetServers().
|
static |
Indicate that the client failed to connect to a MigratoryData server.
This constant indicates that the client failed to connect to one of the MigratoryData servers defined with the API method MigratoryDataClient.SetServers().
|
static |
After a failover reconnection, the client resynchronized a subscribed subject with the latest message available for that subject, as well as with all messages published during the failover for that subject.
This constant indicates that the client successfully synchronized the subject provided in the detail information of the status notification. Also, the potential messages published for that subject during the failover period have been successfully retrieved at the moment of the reconnection.
|
static |
After a failover reconnection, the client resynchronized a subscribed subject with the latest message available for that subject, but not with the potential messages published during the failover, therefore behaving as a new client.
This constant indicates that the client successfully synchronized the subject provided in the detail information of the status notification. However, the client was unable to get the messages published during the failover. Therefore, it behaves like a new client which connects to the MigratoryData server at the moment of the failover reconnection.
|
static |
Indicate that the client was authorized to subscribe to a subject.
This constant indicates that the client identified with the token defined with the API method MigratoryDataClient.SetEntitlementToken() is allowed to subscribe to the subject provided in the detail information of the status notification.
|
static |
Indicate that the client was not authorized to subscribe to a subject.
This constant indicates that the client identified with the token defined with the API method MigratoryDataClient.SetEntitlementToken() is not allowed to subscribe to the subject provided in the detail information of the status notification.
|
static |
Indicate that the client successfully published a message.
This constant is used to indicate that the publication of the message, having the closure provided in the detail information of the status notification, has succeeded.
|
static |
Indicate that the client was unable to publish a message.
This constant is used to indicate that the publication of the message, having the closure provided in the detail information of the status notification, has failed.
|
static |
Indicate that the client was unable to publish a message because it is not allowed by the entitlement system.
This constant is used to indicate that the publication of the message, having the closure provided in the detail information of the status notification, has failed. The publication failed because the client identified with the token defined with the API method MigratoryDataClient.SetEntitlementToken() is not allowed to publish on the subject of the message.
|
static |
Indicate that the client was unable to publish a message because there is no client subscribed to the subject of the message.
This constant is used to indicate that the publication of the message, having the closure provided in the detail information of the status notification, has failed. The publication failed because there is no client then subscribed to the subject of the message.
|
static |
A constant used to define the reconnect policy.
See MigratoryDataClient.SetQuickReconnectInitialDelay() for more details about this policy.
|
static |
A constant used to define the reconnect policy.
See MigratoryDataClient.SetQuickReconnectInitialDelay() for more details about this policy.