📄 function.samconnection-receive.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <title>Receive a message from a queue or subscription.</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.samconnection-peekall.html">SAMConnection->peekAll</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.samconnection-remove.html">SAMConnection->remove</a></div> <div class="up"><a href="ref.sam.html">SAM Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div id="function.samconnection-receive" class="refentry"> <div class="refnamediv"> <h1 class="refname">SAMConnection->receive</h1> <p class="verinfo">(No version information available, might be only in CVS)</p><p class="refpurpose"><span class="refname">SAMConnection->receive</span> — <span class="dc-title"> Receive a message from a queue or subscription. </span></p> </div> <div class="refsect1 description"> <h3 class="title">Description</h3> <div class="classsynopsis"> <div class="ooclass"><b class="classname">SAMConnection</b></div> <div class="methodsynopsis dc-description"> <span class="type">SAMMessage</span> <span class="methodname"><b><b>receive</b></b></span> ( <span class="methodparam"><span class="type">string</span> <tt class="parameter">$target</tt></span> [, <span class="methodparam"><span class="type">array</span> <tt class="parameter">$properties</tt></span> ] )</div> </div> </div> <div class="refsect1 parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><i><tt class="parameter">target</tt></i></span> <dd> <p class="para"> The identity of the queue, topic or subscription from which to receive the message. </p> </dd> </dt> <dt> <span class="term"><i><tt class="parameter">properties</tt></i></span> <dd> <p class="para"> An optional associative array of properties describing other parameters to control the receive operation. <table class="informaltable"> <colgroup> <thead valign="middle"> <tr valign="middle"> <th colspan="1">Property name</th> <th colspan="1">Possible values</th> </tr> </thead> <tbody valign="middle" class="tbody"> <tr valign="middle"> <td colspan="1" rowspan="1" align="left">SAM_CORRELID</td> <td colspan="1" rowspan="1" align="left"> Used to request selection of the message to receive based upon the correlation id string of the message. </td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left">SAM_MESSAGEID</td> <td colspan="1" rowspan="1" align="left"> Used to request selection of the message to receive based upon the message id string of the message. </td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left">SAM_WAIT</td> <td colspan="1" rowspan="1" align="left"> Timeout value in milliseconds to control how long the request should block waiting to receive a message before returning with a failure if no message is available on the queue or topic. The default value is 0 meaning wait indefinitely and should be used with caution as the request may wait until the overall PHP script processing time limit has expired if no message becomes available. </td> </tr> </tbody> </colgroup> </table> </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> This method returns a SAMMessage object or <b><tt>FALSE</tt></b> if an error occurs. </p> </div> <div class="refsect1 examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example"> <p><b>Example #1 Receiving a message from a queue</b></p> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br />$msg </span><span style="color: #007700">= </span><span style="color: #0000BB">$conn</span><span style="color: #007700">-></span><span style="color: #0000BB">receive</span><span style="color: #007700">(</span><span style="color: #DD0000">'queue://receive/test'</span><span style="color: #007700">);<br /><br />if (!</span><span style="color: #0000BB">$msg</span><span style="color: #007700">) {<br /> </span><span style="color: #FF8000">// The receive failed!<br /> </span><span style="color: #007700">echo </span><span style="color: #DD0000">"Receive failed ($conn->errno) $conn->error"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?></span></span></code></div> </div> </div> </p> <p class="para"> <div class="example"> <p><b>Example #2 Receiving a message from a queue with options</b></p> <div class="example-contents"><p> In this example the SAM_CORRELID option is used to specify a correlation id string to be used to identify the message to receive. A wait timeout of 10 seconds is also specified. </p></div> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br /><br />$msg </span><span style="color: #007700">= </span><span style="color: #0000BB">$conn</span><span style="color: #007700">-></span><span style="color: #0000BB">receive</span><span style="color: #007700">(</span><span style="color: #DD0000">'queue://receive/test'</span><span style="color: #007700">, array(</span><span style="color: #0000BB">SAM_CORRELID </span><span style="color: #007700">=> </span><span style="color: #0000BB">$token</span><span style="color: #007700">, </span><span style="color: #0000BB">SAM_WAIT </span><span style="color: #007700">=> </span><span style="color: #0000BB">10000</span><span style="color: #007700">));<br /><br /></span><span style="color: #0000BB">?></span></span></code></div> </div> </div> </p> <p class="para"> <div class="example"> <p><b>Example #3 Receiving a message from a subscription</b></p> <div class="example-contents"><p> In this example we show how to receive a message from a subscription id. </p></div> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br />$msg </span><span style="color: #007700">= </span><span style="color: #0000BB">$conn</span><span style="color: #007700">-></span><span style="color: #0000BB">receive</span><span style="color: #007700">(</span><span style="color: #0000BB">$subscriptionName</span><span style="color: #007700">);<br /><br />if (!</span><span style="color: #0000BB">$msg</span><span style="color: #007700">) {<br /> </span><span style="color: #FF8000">// The receive failed!<br /> </span><span style="color: #007700">echo </span><span style="color: #DD0000">"Receive failed ($conn->errno) $conn->error"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?></span></span></code></div> </div> <div class="example-contents"><p> Please note that $subscriptionName is a subscription id returned from an earlier subscribe call. </p></div> </div> </p> </div> <div class="refsect1 seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"><a href="function.samconnection-send.html" class="xref">SAMConnection->send</a></li> </ul> </p> </div></div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.samconnection-peekall.html">SAMConnection->peekAll</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.samconnection-remove.html">SAMConnection->remove</a></div> <div class="up"><a href="ref.sam.html">SAM Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -