php-doc-en/reference/stomp/examples.xml
2012-01-11 06:50:17 +00:00

169 lines
3.2 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<chapter xml:id="stomp.examples" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
&reftitle.examples;
<!-- section xml:id="stomp.examples-overview" -->
<para>
<example>
<title>&style.oop;</title>
<programlisting role="php">
<![CDATA[
<?php
$queue = '/queue/foo';
$msg = 'bar';
/* connection */
try {
$stomp = new Stomp('tcp://localhost:61613');
} catch(StompException $e) {
die('Connection failed: ' . $e->getMessage());
}
/* send a message to the queue 'foo' */
$stomp->send($queue, $msg);
/* subscribe to messages from the queue 'foo' */
$stomp->subscribe($queue);
/* read a frame */
$frame = $stomp->readFrame();
if ($frame->body === $msg) {
var_dump($frame);
/* acknowledge that the frame was received */
$stomp->ack($frame);
}
/* close connection */
unset($stomp);
?>
]]>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
object(StompFrame)#2 (3) {
["command"]=>
string(7) "MESSAGE"
["headers"]=>
array(5) {
["message-id"]=>
string(41) "ID:php.net-55293-1257226743606-4:2:-1:1:1"
["destination"]=>
string(10) "/queue/foo"
["timestamp"]=>
string(13) "1257226805828"
["expires"]=>
string(1) "0"
["priority"]=>
string(1) "0"
}
["body"]=>
string(3) "bar"
}
]]>
</screen>
</example>
</para>
<para>
<example>
<title>&style.procedural;</title>
<programlisting role="php">
<![CDATA[
<?php
$queue = '/queue/foo';
$msg = 'bar';
/* connection */
$link = stomp_connect('ssl://localhost:61612');
/* check connection */
if (!$link) {
die('Connection failed: ' . stomp_connect_error());
}
/* begin a transaction */
stomp_begin($link, 't1');
/* send a message to the queue 'foo' */
stomp_send($link, $queue, $msg, array('transaction' => 't1'));
/* commit a transaction */
stomp_commit($link, 't1');
/* subscribe to messages from the queue 'foo' */
stomp_subscribe($link, $queue);
/* read a frame */
$frame = stomp_read_frame($link);
if ($frame['body'] === $msg) {
var_dump($frame);
/* acknowledge that the frame was received */
stomp_ack($link, $frame['headers']['message-id']);
}
/* close connection */
stomp_close($link);
?>
]]>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
array(3) {
["command"]=>
string(7) "MESSAGE"
["body"]=>
string(3) "bar"
["headers"]=>
array(6) {
["transaction"]=>
string(2) "t1"
["message-id"]=>
string(41) "ID:php.net-55293-1257226743606-4:3:-1:1:1"
["destination"]=>
string(10) "/queue/foo"
["timestamp"]=>
string(13) "1257227037059"
["expires"]=>
string(1) "0"
["priority"]=>
string(1) "0"
}
}
]]>
</screen>
</example>
</para>
<!-- /section -->
</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
-->