diff --git a/Koha/BackgroundJob.pm b/Koha/BackgroundJob.pm index 33a6872ec0..6e066e51c7 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..c8ff0658b2 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/installer/data/mysql/atomicupdate/bug_35655.pl b/installer/data/mysql/atomicupdate/bug_35655.pl new file mode 100755 index 0000000000..2755d70c8b --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_35655.pl @@ -0,0 +1,22 @@ +use Modern::Perl; +use Koha::Installer::Output qw(say_warning say_failure say_success say_info); + +return { + bug_number => "35655", + description => "Add a way to disable RabbitMQ", + up => sub { + my ($args) = @_; + my ( $dbh, $out ) = @$args{qw(dbh out)}; + + $dbh->do( + q{ + INSERT IGNORE INTO systempreferences + (`variable`, `value`, `options`, `explanation`, `type` ) + VALUES + ('JobsNotificationMethod', 'STOMP', 'polling|STOMP', 'Define the preferred job worker notification method', 'Choice') + } + ); + + say $out "Added new system preference 'JobsNotificationMethod'"; + }, +}; diff --git a/installer/data/mysql/mandatory/sysprefs.sql b/installer/data/mysql/mandatory/sysprefs.sql index a865f86cb2..54fbc47dac 100644 --- a/installer/data/mysql/mandatory/sysprefs.sql +++ b/installer/data/mysql/mandatory/sysprefs.sql @@ -358,6 +358,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('itemBarcodeInputFilter','','whitespace|T-prefix|cuecat|libsuite8|EAN13','If set, allows specification of a item barcode input filter','Choice'), ('itemcallnumber','',NULL,'The MARC field/subfield that is used to calculate the itemcallnumber (Dewey would be 082ab or 092ab; LOC would be 050ab or 090ab) could be 852hi from an item record','free'), ('ItemsDeniedRenewal','','','This syspref allows to define custom rules for denying renewal of specific items.','Textarea'), +('JobsNotificationMethod','STOMP','polling|STOMP','Define the preferred job worker notification method','Choice'), ('KohaAdminEmailAddress','root@localhost','','Define the email address where patron modification requests are sent','free'), ('KohaManualBaseURL','https://koha-community.org/manual/','','Where is the Koha manual/documentation located?','Free'), ('KohaManualLanguage','en','en|ar|cs|de|es|fr|it|pt_BR|tr|zh_TW','What is the language of the online manual you want to use?','Choice'), 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 diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref index 511341f044..b44075a9b0 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref @@ -189,6 +189,15 @@ Administration: None: "None" Common Name: Common Name emailAddress: emailAddress + Jobs: + - + - "Use " + - pref: JobsNotificationMethod + default: STOMP + choices: + STOMP: "STOMP" + polling: "polling" + - as the preferred job worker notification method. STOMP (default) requires RabbitMQ running. Polling will be used as a fallback if RabbitMQ is not accessible. Google OpenID Connect: - - "Use Google OpenID Connect login in the OPAC: "