make stomp server work with username and password

This commit is contained in:
Evan Prodromou 2009-06-24 19:17:41 -07:00
parent 5f1b97e2ad
commit 63f12c48a8
3 changed files with 93 additions and 76 deletions

View File

@ -125,7 +125,13 @@ $config =
array('appname' => 'laconica', # for syslog array('appname' => 'laconica', # for syslog
'priority' => 'debug'), # XXX: currently ignored 'priority' => 'debug'), # XXX: currently ignored
'queue' => 'queue' =>
array('enabled' => false), array('enabled' => false,
'subsystem' => 'db', # default to database, or 'stomp'
'stomp_server' => null,
'queue_basename' => 'laconica',
'stomp_username' => null,
'stomp_password' => null,
),
'license' => 'license' =>
array('url' => 'http://creativecommons.org/licenses/by/3.0/', array('url' => 'http://creativecommons.org/licenses/by/3.0/',
'title' => 'Creative Commons Attribution 3.0', 'title' => 'Creative Commons Attribution 3.0',

View File

@ -112,12 +112,21 @@ class QueueHandler extends Daemon
} }
function stomp_dispatch() { function stomp_dispatch() {
require("Stomp.php");
$con = new Stomp(common_config('queue','stomp_server')); // use an external message queue system via STOMP
if (!$con->connect()) { require_once("Stomp.php");
$server = common_config('queue','stomp_server');
$username = common_config('queue', 'stomp_username');
$password = common_config('queue', 'stomp_password');
$con = new Stomp($server);
if (!$con->connect($username, $password)) {
$this->log(LOG_ERR, 'Failed to connect to queue server'); $this->log(LOG_ERR, 'Failed to connect to queue server');
return false; return false;
} }
$queue_basename = common_config('queue','queue_basename'); $queue_basename = common_config('queue','queue_basename');
// subscribe to the relevant queue (format: basename-transport) // subscribe to the relevant queue (format: basename-transport)
$con->subscribe('/queue/'.$queue_basename.'-'.$this->transport()); $con->subscribe('/queue/'.$queue_basename.'-'.$this->transport());

View File

@ -826,22 +826,45 @@ function common_broadcast_notice($notice, $remote=false)
function common_enqueue_notice($notice) function common_enqueue_notice($notice)
{ {
$transports = array('omb', 'sms', 'public', 'twitter', 'facebook', 'ping');
if (common_config('xmpp', 'enabled'))
{
$transports[] = 'jabber';
}
if (common_config('queue','subsystem') == 'stomp') { if (common_config('queue','subsystem') == 'stomp') {
common_enqueue_notice_stomp($notice, $transports);
}
else {
common_enqueue_notice_db($notice, $transports);
}
return $result;
}
function common_enqueue_notice_stomp($notice, $transports)
{
// use an external message queue system via STOMP // use an external message queue system via STOMP
require_once("Stomp.php"); require_once("Stomp.php");
$con = new Stomp(common_config('queue','stomp_server'));
if (!$con->connect()) { $server = common_config('queue','stomp_server');
$username = common_config('queue', 'stomp_username');
$password = common_config('queue', 'stomp_password');
$con = new Stomp($server);
if (!$con->connect($username, $password)) {
common_log(LOG_ERR, 'Failed to connect to queue server'); common_log(LOG_ERR, 'Failed to connect to queue server');
return false; return false;
} }
$queue_basename = common_config('queue','queue_basename'); $queue_basename = common_config('queue','queue_basename');
foreach (array('jabber', 'omb', 'sms', 'public', 'twitter', 'facebook', 'ping') as $transport) {
if (!$con->send( foreach ($transports as $transport) {
'/queue/'.$queue_basename.'-'.$transport, // QUEUE $result = $con->send('/queue/'.$queue_basename.'-'.$transport, // QUEUE
$notice->id, // BODY of the message $notice->id, // BODY of the message
array ( // HEADERS of the msg array ('created' => $notice->created));
'created' => $notice->created if (!$result) {
))) {
common_log(LOG_ERR, 'Error sending to '.$transport.' queue'); common_log(LOG_ERR, 'Error sending to '.$transport.' queue');
return false; return false;
} }
@ -881,34 +904,13 @@ function common_enqueue_notice($notice)
common_log(LOG_DEBUG, 'sent to catch-all topic ' . $notice->id); common_log(LOG_DEBUG, 'sent to catch-all topic ' . $notice->id);
$result = true; $result = true;
} }
else {
// in any other case, 'internal'
foreach (array('jabber', 'omb', 'sms', 'public', 'twitter', 'facebook', 'ping') as $transport) {
$qi = new Queue_item();
$qi->notice_id = $notice->id;
$qi->transport = $transport;
$qi->created = $notice->created;
$result = $qi->insert();
if (!$result) {
$last_error = &PEAR::getStaticProperty('DB_DataObject','lastError');
common_log(LOG_ERR, 'DB error inserting queue item: ' . $last_error->message);
return false;
}
common_log(LOG_DEBUG, 'complete queueing notice ID = ' . $notice->id . ' for ' . $transport);
}
}
return $result;
}
function common_post_inbox_transports() function common_enqueue_notice_db($notice, $transports)
{ {
$transports = array('omb', 'sms'); // in any other case, 'internal'
foreach ($transports as $transport) {
if (common_config('xmpp', 'enabled')) { common_enqueue_notice_transport($notice, $transport);
$transports = array_merge($transports, array('jabber', 'public'));
} }
return $transports;
} }
function common_enqueue_notice_transport($notice, $transport) function common_enqueue_notice_transport($notice, $transport)