From 9cfbc21443faaea66af7677b57060e4ad2fe536c Mon Sep 17 00:00:00 2001 From: David Cook Date: Tue, 20 Oct 2020 11:54:46 +1100 Subject: [PATCH] Bug 26742: Add configuration to koha-conf.xml for message broker The connection details for the message broker should be configurable. This patch adds configuration options to koha-conf.xml. If they are not specified, then default connection details will be used. Signed-off-by: Michal Denar Signed-off-by: Victor Grousset/tuxayo Signed-off-by: Martin Renvoize Signed-off-by: Jonathan Druart (cherry picked from commit 8663f23a931edea9f8fcd341e67804f613bb1d8d) Signed-off-by: Fridolin Somers --- Koha/BackgroundJob.pm | 24 ++++++++++++++++++++++-- debian/templates/koha-conf-site.xml.in | 8 ++++++++ etc/koha-conf.xml | 8 ++++++++ 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/Koha/BackgroundJob.pm b/Koha/BackgroundJob.pm index d375dfa0d5..1a25c32721 100644 --- a/Koha/BackgroundJob.pm +++ b/Koha/BackgroundJob.pm @@ -62,8 +62,28 @@ Connect to the message broker using default guest/guest credential sub connect { my ( $self ); - my $stomp = Net::Stomp->new( { hostname => 'localhost', port => '61613' } ); - $stomp->connect( { login => 'guest', passcode => 'guest' } ); + my $hostname = 'localhost'; + my $port = '61613'; + my $config = C4::Context->config('message_broker'); + my $credentials = { + login => 'guest', + passcode => 'guest', + }; + if ($config){ + $hostname = $config->{hostname} if $config->{hostname}; + $port = $config->{port} if $config->{port}; + $credentials->{login} = $config->{username} if $config->{username}; + $credentials->{passcode} = $config->{password} if $config->{password}; + $credentials->{host} = $config->{vhost} if $config->{vhost}; + } + my $stomp = Net::Stomp->new( { hostname => $hostname, port => $port } ); + my $frame = $stomp->connect( $credentials ); + unless ($frame && $frame->command eq 'CONNECTED'){ + if ($frame){ + warn $frame->as_string; + } + die "Cannot connect to message broker"; + } return $stomp; } diff --git a/debian/templates/koha-conf-site.xml.in b/debian/templates/koha-conf-site.xml.in index 1480ddeb88..956549b659 100644 --- a/debian/templates/koha-conf-site.xml.in +++ b/debian/templates/koha-conf-site.xml.in @@ -455,5 +455,13 @@ __END_SRU_PUBLICSERVER__ __SMTP_DEBUG__ + + localhost + 61613 + guest + guest + + + diff --git a/etc/koha-conf.xml b/etc/koha-conf.xml index 8b15553066..b9154108dc 100644 --- a/etc/koha-conf.xml +++ b/etc/koha-conf.xml @@ -272,5 +272,13 @@ __PAZPAR2_TOGGLE_XML_POST__ __SMTP_DEBUG__ + + localhost + 61613 + guest + guest + + + -- 2.39.5