When should I subscribe to multiple server URIs with a single client object?
book
Article ID: KB0076359
calendar_today
Updated On:
Description
Questions about the functionality of StreamBaseClient class when subscribing to multiple URIs within one client:
- Does the Enqueue method attempt to enqueue a given tuple onto both servers to which it is connected, provided there is a stream with the same name on both?
- Does the Dequeue method automatically attempt to dequeue tuples from both servers?
- If so, is there a way to find out whether a particular server is a leader using this?
Resolution
Yes to all three questions.
Note: If the StreamBase servers are running different applications, use at least one client object for each different server.
When multiple StreamBase servers are running the same application logic in a High-Availability scenario with one leader and one or more non-leaders, then use one client object with a reference to all servers. The enqueue() and dequeue() methods then send to all servers and read results from all servers respectively.
The following C# code fragment is an example:
// Connect to StreamBase servers
StreamBaseClient sbc = new StreamBaseClient("sb://localhost:10000, sb://localhost:10001");
sbc.Subscribe(OUT_STREAM);
// Start dequeueing
DequeueResult dr;
while (true)
{
dr = sbc.Dequeue(100);
if (dr.GetStatus() == DequeueResult.TIMEOUT)
continue; // Nothing dequeued; try again
if (dr.GetLeadershipStatus() != LeadershipStatus.LEADER)
continue; // These tuples did not come from the leader; ignore them
if (dr.GetStatus() != DequeueResult.GOOD)
break; // Error occurred or (more likely) server closed connection
// Get each tuple from the dequeue result
foreach (Tuple tuple in dr)
{
// Process tuples here...
}
}
In any situation where leadership changes, it may take the non-leader a period of time to recognize that it should be the leader. During this time no tuples will be received from the failed leader and all the results sent by DequeueResult on the active server will still be marked as non-leader. In this case you might consider having the application use non-leader results in anticipation that the leadership is about to change.
Issue/Introduction
When should I subscribe to multiple server URIs with a single client object?
Feedback
thumb_up
Yes
thumb_down
No