PHP code example of iron-io / iron_mq
1. Go to this page and download the library: Download iron-io/iron_mq library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
iron-io / iron_mq example snippets
$ironmq = new \IronMQ\IronMQ();
$ironmq = new \IronMQ\IronMQ();
$ironmq = new \IronMQ\IronMQ(array(
"token" => 'XXXXXXXXX',
"project_id" => 'XXXXXXXXX'
));
$ironmq = new \IronMQ\IronMQ('config.json');
$keystone = array(
"server" => "http://your.keystone.host/v2.0/",
"tenant" => "some-gorup",
"username" => "name",
"password" => "password"
);
$ironmq = new \IronMQ\IronMQ(array(
"project_id" => '57a7b7b35e8e331d45000001',
"keystone" => $keystone
));
$ironmq->postMessage($queue_name, "Hello world");
$ironmq->postMessage($queue_name, "Test Message", array(
"timeout" => 120, # Timeout, in seconds. After timeout, item will be placed back on queue. Defaults to 60.
"delay" => 5, # The item will not be available on the queue until this many seconds have passed. Defaults to 0.
"expires_in" => 2*24*3600 # How long, in seconds, to keep the item on the queue before it is deleted.
));
$ironmq->postMessages($queue_name, array("Message 1", "Message 2"), array(
"timeout" => 120
));
$ironmq->reserveMessage($queue_name);
$ironmq->reserveMessages($queue_name, 3);
$message = $ironmq->reserveMessage($queue_name);
$reservation_id = $message->reservation_id;
$ironmq->deleteMessage($queue_name, $message_id, $reservation_id);
$ironmq->deleteMessage($queue_name, $message_id);
$ironmq->deleteMessages($queue_name, array("xxxxxxxxx", "xxxxxxxxx"));
$messages = $ironmq->reserveMessages($queue_name, 3);
$ironmq->deleteMessage($queue_name, $messages);
$ironmq = new \IronMQ\IronMQ(array(
"token" => 'XXXXXXXXX',
"project_id" => 'XXXXXXXXX'
));
$queues = $ironmq->getQueues();
$queues = $ironmq->getQueues('b', 3);
$qinfo = $ironmq->getQueue($queue_name);
$response = $ironmq->deleteQueue($queue_name);
$ironmq->postMessage($queue_name, "Test Message", array(
'delay' => 2,
'expires_in' => 2*24*3600 # 2 days
));
$ironmq->postMessages($queue_name, array("Lorem", "Ipsum"), array(
"delay" => 2,
"expires_in" => 2*24*3600 # 2 days
));
$message = $ironmq->reserveMessage($queue_name, $timeout);
$message = $ironmq->reserveMessages($queue_name, $count, $timeout, $wait);
$ironmq->touchMessage($queue_name, $message_id, $reservation_id, $timeout);
$ironmq->releaseMessage($queue_name, $message_id, $reservation_id, $delay);
$ironmq->deleteMessage($queue_name, $message_id, $reservation_id);
$message = $ironmq->peekMessage($queue_name);
$messages = $ironmq->peekMessages($queue_name, $count);
$ironmq->clearQueue($queue_name);
$params = array(
"message_timeout" => 120,
"message_expiration" => 24 * 3600,
"push" => array(
"subscribers" => array(
array("url" => "http://your.first.cool.endpoint.com/push", "name" => "first"),
array("url" => "http://your.second.cool.endpoint.com/push", "name" => "second")
),
"retries" => 4,
"retries_delay" => 30,
"error_queue" => "error_queue_name"
)
);
$ironmq->createQueue($queue_name, $params);
$ironmq->addSubscriber($queue_name, array(
"url" => "http://cool.remote.endpoint.com/push",
"name" => "subscriber_name",
"headers" => array(
"Content-Type" => "application/json"
)
)
);
$ironmq->addSubscribers($queue_name, array(
array(
"url" => "http://first.remote.endpoint.com/push",
"name" => "first"),
array(
"url" => "http://second.remote.endpoint.com/push",
"name" => "second")
)
);
$ironmq->replaceSubscriber($queue_name, array(
"url" => "http://cool.remote.endpoint.com/push",
"name" => "subscriber_name"
)
);
$ironmq->addSubscribers($queue_name, array(
array(
"url" => "http://first.remote.endpoint.com/push",
"name" => "first"),
array(
"url" => "http://second.remote.endpoint.com/push",
"name" => "second")
)
);
$ironmq->removeSubscriber($queue_name, array(
"name" => "subscriber_name"
)
);
$ironmq->removeSubscribers($queue_name, array(
array("name" => "first"),
array("name" => "second")
)
);
$response = $ironmq->postMessage('push me!');
$message_id = $response["ids"][0];
$statuses = $ironmq->getMessagePushStatuses($queue_name, $message_id);
$ironmq->deletePushMessage($queue_name, $message_id, $reservation_id, $subscriber_name);