Example
The following is a code block that demonstrates how to invoke the CrossDataCenterFailover composite operator within an Streams application:
use com.teracloud.streams.crossdc.failover.types::*;
use com.teracloud.streams.crossdc.failover::*;
// Any application that wants to make use of the
// CrossDataCenterFailover technique explained above must
// invoke the following reusable composite.
(stream<HeartbeatMessageType> DataSnapshotSignal;
stream<RemoteDataCenterStatusType> RemoteDataCenterStatus;
stream<HeartbeatMessageType> ProcessDataFromRemoteDC) as CrossDCFailover =
CrossDataCenterFailover(SerializedDataSnapshotMessage; SpecialMessage) {
param
configFileName: $configFileName;
}
// As you can see above, the CrossDCFailover composite has its own
// input streams and output streams all of which will be used by one or
// more operators in this application.
//
// At this point, application code can consume the tuples coming via the
// output streams of the CrossDCFailover layer and application code feed
// into the input streams of the CrossDCFailover layer as needed.
The following list details the input streams from the operator:
- SerializedDataSnapshotMessage: In response to the periodic cross-DC data replication notification from the CrossDCFailover composite operator, application logic can serialize its in-memory state into a blob and feed it into this input stream.
-
SpecialMessage: Application logic can send special messages into CrossDCFailover via this input stream when needed. This stream has a single rstring attribute. The following are valid attribute values:
- OrderlyShutdown: When a given DC's application requires a planned orderly shutdown, then this activity can be informed to the remote DC to anticipate a normal outage thereby avoiding any accidental failover operation. In this case, the application logic can send this special message to CrossDCFailover.
- SendMeDataFromSnapshotFiles: During the application start-up time, if the application wants to inherit the remote DC's replicated data that was received during the previous application run, then it can send this special message to CrossDCFailover which will start sending the previously replicated data. During the application start-up, by default remote DC's replicated data from a previous run is deleted. So, this special message has to work in conjunction with a CrossDC configuration named retainOlderDataSnapshotsAtStartup.
The following list details the output streams from the operator:
- DataSnapshotSignal: If the optional periodic data replication is enabled, then the application logic will be notified via this stream whenever it is time for the application logic to create a snapshot of its in-memory state data to be replicated to the remote DC.
-
RemoteDataCenterStatus: This stream notifies the application logic about any status change happening in the remote DC i.e. when a remote DC comes up active or when a remote DC goes down.
-
ProcessDataFromRemoteDC: When a remote DC failure or outage is detected and if the optional cross DC data replication is ON, then this stream will provide the application logic with a serialized blob representing the replicated in-memory state from the failed remote DC. This blob will carry an application specific origin of this data so that the corresponding operator in the local DC's application can deserialize the blob and take over that data.
The CrossDataCenterFailover composite takes one parameter through which users can specify the fully qualified name for a text-based configuration file. If configuration is specified by an Application configuration then users can pass an empty string ("") as a value for this parameter.