<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Send a message to a queue or publish an item to a topic.</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="samconnection.rollback.html">SAMConnection::rollback</a></div> <div class="next" style="text-align: right; float: right;"><a href="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="samconnection.send" class="refentry"> <div class="refnamediv"> <h1 class="refname">SAMConnection::send</h1> <p class="verinfo">(PECL sam >= 0.1.0)</p><p class="refpurpose"><span class="refname">SAMConnection::send</span> — <span class="dc-title"> Send a message to a queue or publish an item to a topic. </span></p> </div> <div class="refsect1 description" id="refsect1-samconnection.send-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">string</span> <span class="methodname"><strong>SAMConnection::send</strong></span> ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$target</code></span> , <span class="methodparam"><span class="type"><a href="ref.sam.html" class="type SAMMessage">SAMMessage</a></span> <code class="parameter">$msg</code></span> [, <span class="methodparam"><span class="type">array</span> <code class="parameter">$properties</code></span> ] )</div> <p class="para rdfs-comment"> The "send" 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" id="refsect1-samconnection.send-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter">target</code></em></span> <dd> <p class="para"> If sending a message, the identity of the queue (<em>queue://queuename</em>) or if publishing to a topic the identity of the topic (<em>topic://topicname</em>) to which the message is to be delivered. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">msg</code></em></span> <dd> <p class="para"> The message to be sent or published. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">properties</code></em></span> <dd> <p class="para"> An optional associative array of properties describing other parameters to control the receive operation. <table class="doctable informaltable"> <thead> <tr> <th>Property name</th> <th>Possible values</th> </tr> </thead> <tbody class="tbody"> <tr> <td>SAM_DELIVERYMODE</td> <td> Indicates whether the messaging server should ensure 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 <strong><code>SAM_PERSISTENT</code></strong>, to indicate that message loss is not acceptable, or <strong><code>SAM_NON_PERSISTENT</code></strong>, 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 <strong><code>SAM_PERSISTENT</code></strong> is specified the send request will fail with an error indication showing the capability is not available. </td> </tr> <tr> <td>SAM_PRIORITY</td> <td> 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> <td>SAM_CORRELID</td> <td> 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> <td>SAM_TIMETOLIVE</td> <td> 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> <td>SAM_WMQ_TARGET_CLIENT</td> <td> 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 'jms' or 'mq'. The default is 'jms' which means that an RFH2 header is included. If the value 'mq' is specified then no RFH2 is included with the message. </td> </tr> </tbody> </table> </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-samconnection.send-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 <strong><code>FALSE</code></strong> if an error occurred. </p> <blockquote class="note"><p><strong class="note">Note</strong>: <p class="para"> A correlation id will only be returned for a successful send to a queue destination (<em>queue://xxxx</em>) in which case it will reflect the message identity 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 <strong><code>TRUE</code></strong> as no correlation id is available for return. </p> </p></blockquote> </div> <div class="refsect1 examples" id="refsect1-samconnection.send-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-4533"> <p><strong>Example #1 Send a message to a queue</strong></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">= new </span><span style="color: #0000BB">SAMMessage</span><span style="color: #007700">(</span><span style="color: #DD0000">'This is a simple text message'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$correlId </span><span style="color: #007700">= </span><span style="color: #0000BB">$conn</span><span style="color: #007700">-></span><span style="color: #0000BB">send</span><span style="color: #007700">(</span><span style="color: #DD0000">'queue://send/test'</span><span style="color: #007700">, </span><span style="color: #0000BB">$msg</span><span style="color: #007700">);<br />if (!</span><span style="color: #0000BB">$correlId</span><span style="color: #007700">) {<br /> </span><span style="color: #FF8000">// The send failed!<br /> </span><span style="color: #007700">echo </span><span style="color: #DD0000">"Send failed (</span><span style="color: #0000BB">$conn</span><span style="color: #007700">-></span><span style="color: #0000BB">errno</span><span style="color: #DD0000">) </span><span style="color: #0000BB">$conn</span><span style="color: #007700">-></span><span style="color: #0000BB">error</span><span style="color: #DD0000">"</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> </p> <p class="para"> <div class="example" id="example-4534"> <p><strong>Example #2 Publish a message to a topic</strong></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">= new </span><span style="color: #0000BB">SAMMessage</span><span style="color: #007700">(</span><span style="color: #DD0000">'This is a simple text item'</span><span style="color: #007700">);<br />if (!</span><span style="color: #0000BB">$conn</span><span style="color: #007700">-></span><span style="color: #0000BB">send</span><span style="color: #007700">(</span><span style="color: #DD0000">'topic://test'</span><span style="color: #007700">, </span><span style="color: #0000BB">$msg</span><span style="color: #007700">)) {<br /> </span><span style="color: #FF8000">// The Send failed!<br /> </span><span style="color: #007700">echo </span><span style="color: #DD0000">"Send failed (</span><span style="color: #0000BB">$conn</span><span style="color: #007700">-></span><span style="color: #0000BB">errno</span><span style="color: #DD0000">) </span><span style="color: #0000BB">$conn</span><span style="color: #007700">-></span><span style="color: #0000BB">error</span><span style="color: #DD0000">"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> <div class="example" id="example-4535"> <p><strong>Example #3 Send a request and receive a response</strong></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">= new </span><span style="color: #0000BB">SAMMessage</span><span style="color: #007700">(</span><span style="color: #DD0000">'This is a simple text message'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$msg</span><span style="color: #007700">-></span><span style="color: #0000BB">header</span><span style="color: #007700">-></span><span style="color: #0000BB">SAM_REPLY_TO </span><span style="color: #007700">= </span><span style="color: #DD0000">'queue://receive/test'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$correlid </span><span style="color: #007700">= </span><span style="color: #0000BB">$conn</span><span style="color: #007700">-></span><span style="color: #0000BB">send</span><span style="color: #007700">(</span><span style="color: #DD0000">'queue://send/test'</span><span style="color: #007700">, </span><span style="color: #0000BB">$msg</span><span style="color: #007700">);<br /><br />if (!</span><span style="color: #0000BB">$correlid</span><span style="color: #007700">) {<br /> </span><span style="color: #FF8000">// The Send failed!<br /> </span><span style="color: #007700">echo </span><span style="color: #DD0000">"Send failed (</span><span style="color: #0000BB">$conn</span><span style="color: #007700">-></span><span style="color: #0000BB">errno</span><span style="color: #DD0000">) </span><span style="color: #0000BB">$conn</span><span style="color: #007700">-></span><span style="color: #0000BB">error</span><span style="color: #DD0000">"</span><span style="color: #007700">;<br />} else {<br /> </span><span style="color: #0000BB">$resp </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">$correlid</span><span style="color: #007700">));<br />}<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> </p> </div> <div class="refsect1 seealso" id="refsect1-samconnection.send-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"><a href="samconnection.receive.html" class="xref">SAMConnection::receive</a></li> </ul> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="samconnection.rollback.html">SAMConnection::rollback</a></div> <div class="next" style="text-align: right; float: right;"><a href="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>