From: Bill Erickson Date: Wed, 15 Mar 2023 16:26:46 +0000 (-0400) Subject: append service name for service worker addrs X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=676f64cfc94c46d4b717cf5f283617c38e1ad687;p=working%2FOpenSRF.git append service name for service worker addrs Signed-off-by: Bill Erickson --- diff --git a/include/opensrf/transport_client.h b/include/opensrf/transport_client.h index 8d58e45..255bfe2 100644 --- a/include/opensrf/transport_client.h +++ b/include/opensrf/transport_client.h @@ -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 ); diff --git a/src/extras/timer.pl b/src/extras/timer.pl index 2e0fcdd..41db222 100755 --- a/src/extras/timer.pl +++ b/src/extras/timer.pl @@ -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 = <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()"); diff --git a/src/perl/lib/OpenSRF/Transport/Redis/BusConnection.pm b/src/perl/lib/OpenSRF/Transport/Redis/BusConnection.pm index a93b705..fe826ee 100644 --- a/src/perl/lib/OpenSRF/Transport/Redis/BusConnection.pm +++ b/src/perl/lib/OpenSRF/Transport/Redis/BusConnection.pm @@ -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; } diff --git a/src/perl/lib/OpenSRF/Transport/Redis/Client.pm b/src/perl/lib/OpenSRF/Transport/Redis/Client.pm index 7bdab28..53ac681 100644 --- a/src/perl/lib/OpenSRF/Transport/Redis/Client.pm +++ b/src/perl/lib/OpenSRF/Transport/Redis/Client.pm @@ -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();