#!/usr/bin/perl -w
use Frontier::Daemon;
use Frontier::Client;
use xmlBlaster::Exception ;
use xmlBlaster::XmlBlaster ;
use xmlBlaster::MessageUnit ;
use xmlBlaster::EraseRetQos ;
my $start_port=9095;
my $max_clients=4;
my $login;
my $count=0;
sub do_update {
print "GOT AN UPDATE (CLIENT $login)\n";
return "OK";
}
sub do_ping {
print "got ping (CLIENT $login)\n";
return "OK";
}
sub fork_server($) {
my ($port) = @_;
$login="dk:$port";
my $pid=fork();
if ($pid) {
# Parent
return;
}
Frontier::Daemon->new(
LocalPort => $port,
methods => {
'update' => \&do_update,
'ping' => \&do_ping
});
}
my $server_url = $ARGV[0];
#
# Create a bunch of separate callback servers,
# then log them all in.
#
# Sorry - no way to stop them yet - kill them
# by hand for now.
#
for (my $x=0; $x < $max_clients; $x++) {
print "Starting callback server client $x\n";
fork_server($start_port + $x);
}
sleep(2);
# Now, log them all in
for (my $x=0; $x < $max_clients; $x++) {
my $p=$start_port+$x;
my $local_url="http://127.0.0.1:$p/RPC2";
my $server = Frontier::Client->new(url => $server_url);
print "Connected to xmlBlaster server on $server_url \n";
# Call the remote server and get our result.
my $sessionId = $server->call('authenticate.login', "dk$x", "dk$x",
"$local_url".
"false", "");
print "\nLogin success client dk$x with sessionId=$sessionId \n";
$server->call('xmlBlaster.subscribe',
$sessionId,
"//service",
"false");
print "\nSubscribe success client dk$x\n";
}
# Wait a moment, then publish one message, sleep a bit, then
# publish the same message again.
sleep 2;
my $server = Frontier::Client->new(url => $server_url);
print "Connected to xmlBlaster server on $server_url \n";
# Call the remote server and get our result.
$sessionId = $server->call('authenticate.login', "dkpub", "dkpub", "false", "");
print "\nLogin client success with sessionId=$sessionId \n";
$message = $server->call('xmlBlaster.publish', $sessionId,
"".
"post".
"request".
"123".
"",
"testing",
"truefalse");
print "Published one message... (expect 4 updates)\n";
#sleep, then publish again.
sleep 5;
$message = $server->call('xmlBlaster.publish', $sessionId,
"".
"post".
"request".
"123".
"",
"testing",
"truefalse");
print "Published one message again... (expect 4 updates)\n";
# Logout from xmlBlaster
$server->call('authenticate.logout', $sessionId);
print "\nLogout done, bye.\n";