function.samconnection-send.html

来自「php的帮助文档,涉及到PHP的案例和基本语法,以及实际应用内容」· HTML 代码 · 共 248 行

HTML
248
字号
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head>  <title>Send a message to a queue or publish an item to a topic.</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-rollback.html">SAMConnection->rollback</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.samconnection-setDebug.html">SAMConnection::setDebug</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-send" class="refentry"> <div class="refnamediv">  <h1 class="refname">SAMConnection-&gt;send</h1>  <p class="verinfo">(No version information available, might be only in CVS)</p><p class="refpurpose"><span class="refname">SAMConnection-&gt;send</span> &mdash; <span class="dc-title">   Send a message to a queue or publish an item to a topic.  </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">string</span> <span class="methodname"><b><b>send</b></b></span>     ( <span class="methodparam"><span class="type">string</span> <tt class="parameter">$target</tt></span>    , <span class="methodparam"><span class="type"><span class="type SAMMessage">SAMMessage</span></span> <tt class="parameter">$msg</tt></span>    [, <span class="methodparam"><span class="type">array</span> <tt class="parameter">$properties</tt></span>   ] )</div>  </div>  <p class="para">   The &quot;send&quot; method is used to send a message to a specific queue or to   publish to a specific topic. The method returns a correlation id that can   be used as a selector to identify reply or response messages when these   are requested.  </p> </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">       If sending a message, the identity of the queue (queue://queuename)       or if publishing to a topic the identity of the topic       (topic://topicname) to which the message is to be delivered.      </p>     </dd>    </dt>    <dt>     <span class="term"><i><tt class="parameter">msg</tt></i></span>     <dd>      <p class="para">        The message to be sent or published.      </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_DELIVERYMODE</td>           <td colspan="1" rowspan="1" align="left">            Indicates whether the messaging server should enusre delivery or            whether it is acceptable for messages to be lost in the case of            system failures. The value of this property may be set to either            <b><tt>SAM_PERSISTENT</tt></b>, to indicate that message            loss is not acceptable, or             <b><tt>SAM_NON_PERSISTENT</tt></b>, if message loss is            acceptable. The resulting behaviour of the send will vary            depending on the capabilities of the messaging server the PHP            script is currently connected to. If the server does not support            persistent messages and <b><tt>SAM_PERSISTENT</tt></b> is            specified the send request will fail with an error indication            showing the capability is not available.           </td>          </tr>          <tr valign="middle">           <td colspan="1" rowspan="1" align="left">SAM_PRIORITY</td>           <td colspan="1" rowspan="1" align="left">            A numeric value between 0 and 9 indicating the desired message            delivery priority. A priority value of 0 indicates the lowest            priority while 9 indicates highest priority. If no priority is            specified a default will be assigned which is dependent on the            messaging server being used.           </td>          </tr>          <tr valign="middle">           <td colspan="1" rowspan="1" align="left">SAM_CORRELID</td>           <td colspan="1" rowspan="1" align="left">            A string to be assigned as a correlation id for this message. If            no value is given the messaging server may assign a value            automatically.           </td>          </tr>          <tr valign="middle">           <td colspan="1" rowspan="1" align="left">SAM_TIMETOLIVE</td>           <td colspan="1" rowspan="1" align="left">            A time in milliseconds indicating how long the messaging server            should retain the message on a queue before discarding it. The            default value is 0 indicating the message should be retained            indefinitely.           </td>          </tr>          <tr valign="middle">           <td colspan="1" rowspan="1" align="left">SAM_WMQ_TARGET_CLIENT</td>           <td colspan="1" rowspan="1" align="left">            This property is only valid when using WebSphere MQ and indicates            whether or not an RFH2 header should be included with the            message. This option may be set to either &#039;jms&#039; or &#039;mq&#039;. The            default is &#039;jms&#039; which means that an RFH2 header is included.            If the value &#039;mq&#039; is specified then no RFH2 is included with the            message.            </td>          </tr>         </tbody>        </colgroup>       </table>      </p>     </dd>    </dt>   </dl>  </p> </div> <div class="refsect1 returnvalues">  <h3 class="title">Return Values</h3>  <p class="para">   A correlation id string that can be used in a subsequent receive call as a   selector to obtain any reply or response that has been requested or <b><tt>FALSE</tt></b>   if an error occurred.  </p>  <blockquote><p><b class="note">Note</b>:        A correlation id will only be returned for a successful send to a queue    destination (queue://xxxx) in which case it will reflect the message    identitiy of the message on the queue. In the case of a send being used    to publish data to a topic the return value will be <b><tt>TRUE</tt></b> as no    correlation id is availabe for return.   <br />  </p></blockquote> </div> <div class="refsect1 examples">  <h3 class="title">Examples</h3>  <p class="para">   <div class="example">    <p><b>Example #1 Send a message to a queue</b></p>    <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$msg&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">SAMMessage</span><span style="color: #007700">(</span><span style="color: #DD0000">'This&nbsp;is&nbsp;a&nbsp;simple&nbsp;text&nbsp;message'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$correlId&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$conn</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">send</span><span style="color: #007700">(</span><span style="color: #DD0000">'queue://send/test'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$msg</span><span style="color: #007700">);<br />if&nbsp;(!</span><span style="color: #0000BB">$correlId</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;The&nbsp;send&nbsp;failed!<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">echo&nbsp;</span><span style="color: #DD0000">"Send&nbsp;failed&nbsp;($conn-&gt;errno)&nbsp;$conn-&gt;error"</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>    </div>   </div>  </p>  <p class="para">   <div class="example">    <p><b>Example #2 Publish a message to a topic</b></p>    <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$msg&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">SAMMessage</span><span style="color: #007700">(</span><span style="color: #DD0000">'This&nbsp;is&nbsp;a&nbsp;simple&nbsp;text&nbsp;item'</span><span style="color: #007700">);<br />if&nbsp;(!</span><span style="color: #0000BB">$conn</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">send</span><span style="color: #007700">(</span><span style="color: #DD0000">'topic://test'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$msg</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;The&nbsp;Send&nbsp;failed!<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">echo&nbsp;</span><span style="color: #DD0000">"Send&nbsp;failed&nbsp;($conn-&gt;errno)&nbsp;$conn-&gt;error"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>    </div>   </div>   <div class="example">    <p><b>Example #3 Send a request and receive a response</b></p>    <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$msg&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">SAMMessage</span><span style="color: #007700">(</span><span style="color: #DD0000">'This&nbsp;is&nbsp;a&nbsp;simple&nbsp;text&nbsp;message'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$msg</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">header</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">SAM_REPLY_TO&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'queue://receive/test'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$correlid&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$conn</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">send</span><span style="color: #007700">(</span><span style="color: #DD0000">'queue://send/test'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$msg</span><span style="color: #007700">);<br /><br />if&nbsp;(!</span><span style="color: #0000BB">$correlid</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;The&nbsp;Send&nbsp;failed!<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">echo&nbsp;</span><span style="color: #DD0000">"Send&nbsp;failed&nbsp;($conn-&gt;errno)&nbsp;$conn-&gt;error"</span><span style="color: #007700">;<br />}&nbsp;else&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$resp&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$conn</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">receive</span><span style="color: #007700">(</span><span style="color: #DD0000">'queue://receive/test'</span><span style="color: #007700">,&nbsp;array(</span><span style="color: #0000BB">SAM_CORRELID&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">$correlid</span><span style="color: #007700">));<br />}<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>    </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-receive.html" class="xref">SAMConnection->receive</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-rollback.html">SAMConnection->rollback</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.samconnection-setDebug.html">SAMConnection::setDebug</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 + =
减小字号Ctrl + -
显示快捷键?