Skip to content

Commit c86e476

Browse files
committed
Merge pull request rabbitmq#81 from seyfer/master
fix new task and worker files for second php-amqp tutorial
2 parents 504457a + f15261f commit c86e476

7 files changed

+8
-11
lines changed

php-amqp/emit_log_direct.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
$channel = new AMQPChannel($connection);
1313

1414

15-
$routing_key = $severity = $argv[1];
16-
if(empty($severity)) $severity = 'info';
15+
$routing_key = $severity = isset($argv[1]) && !empty($argv[1]) ? $argv[1] : 'info';
1716

1817
$message = implode(' ',array_slice($argv, 2));
1918
if(empty($message)) $message = 'Hello World!';

php-amqp/emit_log_topic.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
$channel = new AMQPChannel($connection);
1313

1414

15-
$routing_key = (isset($argv[1]))? $argv[1] : 'anonymous.info';
15+
$routing_key = isset($argv[1]) && !empty($argv[1]) ? $argv[1] : 'anonymous.info';
1616

1717
$message = implode(' ',array_slice($argv, 2));
1818
if(empty($message)) $message = "Hello World!";
@@ -28,6 +28,6 @@
2828

2929
$exchange->publish($message, $routing_key);
3030
echo " [x] Sent {$routing_key}:{$message}", PHP_EOL;
31-
} catch(Exception $ex) {
31+
} catch(Exception $ex) {
3232
print_r($ex);
3333
}

php-amqp/new_task.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,6 @@
3535
$exchange = new AMQPExchange($channel);
3636
$exchange->publish($message, $routing_key);
3737

38-
echo " [x] Sent {$data}", PHP_EOL;
38+
echo " [x] Sent {$message}", PHP_EOL;
3939

4040
$connection->disconnect();

php-amqp/receive_logs.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
print_r($ex);
4141
} catch(AMQPExchangeException $ex) {
4242
print_r($ex);
43-
} catch(AMQPChanncelException $ex) {
43+
} catch(AMQPChannelException $ex) {
4444
print_r($ex);
4545
} catch(AMQPConnectionException $ex) {
4646
print_r($ex);

php-amqp/worker.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
$callback_func = function(AMQPEnvelope $message, AMQPQueue $q) use (&$max_jobs) {
1717
echo " [x] Received: ", $message->getBody(), PHP_EOL;
18-
sleep(1);
18+
sleep(sleep(substr_count($message->getBody(), '.')));
1919
echo " [X] Done", PHP_EOL;
2020
$q->ack($message->getDeliveryTag());
2121
};

php/emit_log_direct.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99

1010
$channel->exchange_declare('direct_logs', 'direct', false, false, false);
1111

12-
$severity = $argv[1];
13-
if(empty($severity)) $severity = "info";
12+
$severity = isset($argv[1]) && !empty($argv[1]) ? $argv[1] : 'info';
1413

1514
$data = implode(' ', array_slice($argv, 2));
1615
if(empty($data)) $data = "Hello World!";

php/emit_log_topic.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010

1111
$channel->exchange_declare('topic_logs', 'topic', false, false, false);
1212

13-
$routing_key = $argv[1];
14-
if(empty($routing_key)) $routing_key = "anonymous.info";
13+
$routing_key = isset($argv[1]) && !empty($argv[1]) ? $argv[1] : 'anonymous.info';
1514
$data = implode(' ', array_slice($argv, 2));
1615
if(empty($data)) $data = "Hello World!";
1716

0 commit comments

Comments
 (0)