-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocess_sms_queue.php
53 lines (34 loc) · 1.2 KB
/
process_sms_queue.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
require_once 'bootstrap.php';
use Rabbitmq as Rabbitmq;
//Get the RabbitMQ instance
$objRabbitMQ = new Rabbitmq\Rabbitmq(RMQ_HOST, RMQ_PORT, RMQ_USERNAME, RMQ_PASSWORD);
//Create the Connection to the RabbitMQ
$objRabbitMQ->connect();
//Declare the Queue
$channel = $objRabbitMQ->declareQueue('sms_queue');
$messageCounter = 1;
echo "Ready to Process! Press CTRL+C to stop processing \n \n";
function processMessage($msg){
global $messageCounter;
echo "Processing Message Number = $messageCounter. Press CTRL+C to stop processing\n";
$messageCounter++;
if(isset($msg)) {
$dataArray = json_decode($msg->body, true);
if(is_array($dataArray)) {
writeLog($dataArray, LOG_SMS_FOR_NON_PAUSE);
$msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']);
}
else{
writeLog('Invalid JSON', LOG_PROCESS_INCOMING);
}
}
else{
writeLog('Invalid Message Parameter in Callback', LOG_PROCESS_INCOMING);
}
}
$channel->basic_qos(null, 1, null);
$channel->basic_consume('sms_queue', '', false, false, false, false, 'processMessage');
while(count($channel->callbacks)) {
$channel->wait();
}