append service name for service worker addrs
authorBill Erickson <berickxx@gmail.com>
Wed, 15 Mar 2023 16:26:46 +0000 (12:26 -0400)
committerBill Erickson <berickxx@gmail.com>
Thu, 20 Apr 2023 14:18:05 +0000 (10:18 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
include/opensrf/transport_client.h
src/extras/timer.pl
src/libopensrf/osrf_system.c
src/libopensrf/transport_client.c
src/perl/lib/OpenSRF/Transport/Redis/BusConnection.pm
src/perl/lib/OpenSRF/Transport/Redis/Client.pm

index 8d58e45..255bfe2 100644 (file)
@@ -45,7 +45,10 @@ typedef struct transport_client_struct transport_client;
 transport_client* client_init(const char* server, 
     int port, const char* username, const char* password);
 
+/// Top-level service connection
 int client_connect_as_service(transport_client* client, const char* service);
+/// Client connecting on behalf of a service
+int client_connect_for_service(transport_client* client, const char* service);
 int client_connect(transport_client* client); 
 
 int client_disconnect( transport_client* client );
index 2e0fcdd..41db222 100755 (executable)
@@ -13,7 +13,7 @@ use Time::HiRes qw/time/;
 #my $test_service = "open-ils.storage";
 my $test_service = "opensrf.settings";
 
-my $iterations = 500;
+my $iterations = 50;
 
 my $small_echo_data = <<TEXT;
     1237012938471029348170197908709870987098709870987098709809870987098709870
index 3a56002..c9156b3 100644 (file)
@@ -461,6 +461,10 @@ int osrf_system_bootstrap_common(const char* config_file,
            if (client_connect_as_service(client, appname)) {
                    osrfGlobalTransportClient = client;
            }
+    } else if (appname != NULL && strcmp(appname, "client") != 0) {
+           if (client_connect_for_service(client, appname)) {
+                   osrfGlobalTransportClient = client;
+           }
     } else {
            if (client_connect(client)) {
                    osrfGlobalTransportClient = client;
index 435f1aa..c337dd9 100644 (file)
@@ -80,6 +80,24 @@ int client_connect_as_service(transport_client* client, const char* service) {
         con, client->port, client->username, client->password);
 }
 
+int client_connect_for_service(transport_client* client, const char* service) {
+    osrfLogInternal(OSRF_LOG_MARK, 
+        "TCLIENT client_connect_for_service() service=%s", service);
+
+    client->service = strdup(service);
+
+    transport_con* con = client_connect_common(client, client->primary_domain);
+
+    // Append the service name to the bus address
+    transport_con_set_address(con, service);
+
+    client->primary_connection = con;
+
+    return transport_con_connect(
+        con, client->port, client->username, client->password);
+}
+
+
 int client_connect(transport_client* client) {
     osrfLogInternal(OSRF_LOG_MARK, "TCLIENT client_connect()");
 
index a93b705..fe826ee 100644 (file)
@@ -7,7 +7,7 @@ use OpenSRF::Utils::Logger qw/$logger/;
 
 # domain doubles as the host of the Redis instance.
 sub new {
-    my ($class, $domain, $port, $username, $password, $max_queue) = @_;
+    my ($class, $domain, $port, $username, $password, $service) = @_;
 
     $logger->debug("Creating new bus connection $domain:$port user=$username");
 
@@ -16,7 +16,7 @@ sub new {
         port => $port || 6379,
         username => $username,
         password => $password,
-        max_queue => $max_queue
+        service => $service
     };
 
     return bless($self, $class);
@@ -40,8 +40,12 @@ sub domain {
 sub set_address {
     my ($self) = @_;
 
+    # If this is a client operating on behalf of a service, include the
+    # service name in the bus address for improved debugability.
+    my $svc = $self->{service} ? ':' . $self->{service} . ':' : '';
+
     my $address = sprintf(
-        "opensrf:client:%s:%s:$$:%s", $self->{domain}, hostfqdn(), int(rand(10_000)));
+        "opensrf:client:%s:%s:$svc$$:%s", $self->{domain}, hostfqdn(), int(rand(10_000_000)));
 
     $self->{address} = $address;
 }
index 7bdab28..53ac681 100644 (file)
@@ -61,12 +61,12 @@ sub add_connection {
     my $username = $conf->bootstrap->username;
     my $password = $conf->bootstrap->passwd;
     my $port = $conf->bootstrap->port;
-    my $max_queue = 1024; # TODO
 
     # Assumes other connection parameters are the same across
     # Redis instances, apart from the hostname.
     my $connection = OpenSRF::Transport::Redis::BusConnection->new(
-        $domain, $port, $username, $password, $max_queue
+        $domain, $port, $username, $password, 
+        $self->service ne 'client' ? $self->service : undef
     );
 
     $connection->set_address();