diff --git a/Koha/BackgroundJob.pm b/Koha/BackgroundJob.pm index 33a6872ec0..c21fdd2510 100644 --- a/Koha/BackgroundJob.pm +++ b/Koha/BackgroundJob.pm @@ -63,6 +63,10 @@ Connect to the message broker using default guest/guest credential sub connect { my ( $self ); + my $notification_method = C4::Context->preference('JobsNotificationMethod') // 'STOMP'; + return undef + unless $notification_method eq 'STOMP'; + my $hostname = 'localhost'; my $port = '61613'; my $config = C4::Context->config('message_broker'); @@ -77,8 +81,17 @@ sub connect { $credentials->{passcode} = $config->{password} if $config->{password}; $credentials->{host} = $config->{vhost} if $config->{vhost}; } - my $stomp = Net::Stomp->new( { hostname => $hostname, port => $port } ); - $stomp->connect( $credentials ); + + my $stomp; + + try { + $stomp = Net::Stomp->new( { hostname => $hostname, port => $port } ); + $stomp->connect( $credentials ); + } catch { + warn "Cannot connect to broker " . $_; + $stomp = undef; + }; + return $stomp; } @@ -123,12 +136,7 @@ sub enqueue { $job_args->{job_id} = $self->id; - my $conn; - try { - $conn = $self->connect; - } catch { - warn "Cannot connect to broker " . $_; - }; + my $conn = $self->connect; return $self->id unless $conn; $json_args = $json->encode($job_args); diff --git a/about.pl b/about.pl index 6233d8be23..4e54b5a2fd 100755 --- a/about.pl +++ b/about.pl @@ -906,10 +906,15 @@ sub message_broker_check { my $template = shift; { # BackgroundJob - test connection to message broker - eval { Koha::BackgroundJob->connect; }; - if ($@) { - warn $@; - $template->param( warnConnectBroker => $@ ); + my $conn = Koha::BackgroundJob->connect; + if (! $conn) { + if (C4::Context->preference('JobsNotificationMethod') eq 'STOMP' ) { + $template->param( warnConnectBroker => 'Error connecting' ); + } else { + $template->param( + warnConnectBroker => C4::Context->preference('JobsNotificationMethod') + ); + } } } } diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/about.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/about.tt index 0713215662..13e7c652c3 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/about.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/about.tt @@ -202,7 +202,9 @@ Message broker: - [% IF warnConnectBroker %] + [% IF warnConnectBroker == 'Error connecting' %] + Using SQL polling (Fallback, Error connecting to RabbitMQ) + [% ELSIF warnConnectBroker %] Using SQL polling [% ELSE %] Using RabbitMQ