Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
71 lines (59 sloc) 1.47 KB
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<chapter xml:id="amqp.examples" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
&reftitle.examples;
<example>
<title>AMQP Example</title>
<programlisting role="php">
<![CDATA[
<?php
// Create a connection
$cnn = new AMQPConnection();
$cnn->connect();
// Create a channel
$ch = new AMQPChannel($cnn);
// Declare a new exchange
$ex = new AMQPExchange($ch);
$ex->declareExchange('exchange1', AMQP_EX_TYPE_FANOUT);
// Create a new queue
$q = new AMQPQueue($ch);
$q->declareQueue('queue1');
// Bind it on the exchange to routing.key
$ex->bind('queue1', 'routing.key');
// Publish a message to the exchange with a routing key
$ex->publish('message', 'routing.key');
function processMessage(AMQPEnvelope $env, AMQPQueue $queue) {
printf(
"Received Message on Queue '%s': '%s'\n",
$queue->getName(),
$env->getBody()
);
return true;
}
// Read from the queue
$q->consume('processMessage');
?>
]]>
</programlisting>
</example>
</chapter>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->