Files
archived-doc-pt-br/reference/stomp/examples.xml
Leonardo Lara Rodrigues 4baf074b52 sync file lines with en rev
2026-01-27 09:14:27 -03:00

163 lines
3.3 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- EN-Revision: d0ec3a70d19f82d65d0d201bd7b8573f431cdda6 Maintainer: leonardolara Status: ready --><!-- CREDITS: leonardolara -->
<chapter xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="stomp.examples">
&reftitle.examples;
<!-- section xml:id="stomp.examples-overview" -->
<example>
<title>&style.oop;</title>
<programlisting role="php">
<![CDATA[
<?php
$queue = '/queue/foo';
$msg = 'bar';
/* conexão */
try {
$stomp = new Stomp('tcp://localhost:61613');
} catch(StompException $e) {
die('Conexão falhou: ' . $e->getMessage());
}
/* envia uma mensagem à fila 'foo' */
$stomp->send($queue, $msg);
/* inscreve para mensagens da fila 'foo' */
$stomp->subscribe($queue);
/* lê um quadro */
$frame = $stomp->readFrame();
if ($frame->body === $msg) {
var_dump($frame);
/* confirma que o quadro foi recebido */
$stomp->ack($frame);
}
/* fecha a conexão */
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>
<example>
<title>&style.procedural;</title>
<programlisting role="php">
<![CDATA[
<?php
$queue = '/queue/foo';
$msg = 'bar';
/* conexão */
$link = stomp_connect('ssl://localhost:61612');
/* verifica a conexão */
if (!$link) {
die('Conexão falhou: ' . stomp_connect_error());
}
/* começa uma transação */
stomp_begin($link, 't1');
/* envia uma mensagem à fila 'foo' */
stomp_send($link, $queue, $msg, array('transaction' => 't1'));
/* confirma uma transação */
stomp_commit($link, 't1');
/* inscreve para mensagens da fila 'foo' */
stomp_subscribe($link, $queue);
/* lê um quadro */
$frame = stomp_read_frame($link);
if ($frame['body'] === $msg) {
var_dump($frame);
/* confirma que o quadro foi recebido */
stomp_ack($link, $frame['headers']['message-id']);
}
/* fecha a conexão */
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>
<!-- /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
-->