|
Lines 63-68
Connect to the message broker using default guest/guest credential
Link Here
|
| 63 |
|
63 |
|
| 64 |
sub connect { |
64 |
sub connect { |
| 65 |
my ( $self ); |
65 |
my ( $self ); |
|
|
66 |
my $notification_method = C4::Context->preference('JobsNotificationMethod') // 'STOMP'; |
| 67 |
return undef |
| 68 |
unless $notification_method eq 'STOMP'; |
| 69 |
|
| 66 |
my $hostname = 'localhost'; |
70 |
my $hostname = 'localhost'; |
| 67 |
my $port = '61613'; |
71 |
my $port = '61613'; |
| 68 |
my $config = C4::Context->config('message_broker'); |
72 |
my $config = C4::Context->config('message_broker'); |
|
Lines 77-84
sub connect {
Link Here
|
| 77 |
$credentials->{passcode} = $config->{password} if $config->{password}; |
81 |
$credentials->{passcode} = $config->{password} if $config->{password}; |
| 78 |
$credentials->{host} = $config->{vhost} if $config->{vhost}; |
82 |
$credentials->{host} = $config->{vhost} if $config->{vhost}; |
| 79 |
} |
83 |
} |
| 80 |
my $stomp = Net::Stomp->new( { hostname => $hostname, port => $port } ); |
84 |
|
| 81 |
$stomp->connect( $credentials ); |
85 |
my $stomp; |
|
|
86 |
|
| 87 |
try { |
| 88 |
$stomp = Net::Stomp->new( { hostname => $hostname, port => $port } ); |
| 89 |
$stomp->connect( $credentials ); |
| 90 |
} catch { |
| 91 |
warn "Cannot connect to broker " . $_; |
| 92 |
$stomp = undef; |
| 93 |
}; |
| 94 |
|
| 82 |
return $stomp; |
95 |
return $stomp; |
| 83 |
} |
96 |
} |
| 84 |
|
97 |
|
|
Lines 123-134
sub enqueue {
Link Here
|
| 123 |
|
136 |
|
| 124 |
$job_args->{job_id} = $self->id; |
137 |
$job_args->{job_id} = $self->id; |
| 125 |
|
138 |
|
| 126 |
my $conn; |
139 |
my $conn = $self->connect; |
| 127 |
try { |
|
|
| 128 |
$conn = $self->connect; |
| 129 |
} catch { |
| 130 |
warn "Cannot connect to broker " . $_; |
| 131 |
}; |
| 132 |
return $self->id unless $conn; |
140 |
return $self->id unless $conn; |
| 133 |
|
141 |
|
| 134 |
$json_args = $json->encode($job_args); |
142 |
$json_args = $json->encode($job_args); |