Пример #1
0
 /**
  * Tests Stomp->connect(), send() and subscribe() in order.
  */
 public function testSyncSub()
 {
     $this->assertTrue($this->Stomp->connect());
     $this->assertTrue($this->Stomp->subscribe('/queue/test'));
     $this->assertTrue($this->Stomp->send('/queue/test', 'test 1'));
     $this->assertTrue($this->Stomp->send('/queue/test', 'test 2'));
     $this->Stomp->setReadTimeout(5);
     $frame = $this->Stomp->readFrame();
     $this->assertEquals('test 1', $frame->body, 'test 1 not received!');
     $this->Stomp->ack($frame);
     $frame = $this->Stomp->readFrame();
     $this->assertEquals('test 2', $frame->body, 'test 2 not received!');
     $this->Stomp->ack($frame);
 }
Пример #2
0
 protected function consume()
 {
     $consumer2 = new Stomp($this->broker);
     $consumer2->sync = false;
     $consumer2->clientId = 'test';
     $consumer2->setReadTimeout(1);
     $consumer2->connect('system', 'manager');
     $consumer2->subscribe($this->topic, null, null, true);
     $frame = $consumer2->readFrame();
     $this->assertEquals($frame->body, 'test message');
     if ($frame != null) {
         $consumer2->ack($frame);
     }
     // yes, that's active mq! you must unsub two times...
     // http://mail-archives.apache.org/mod_mbox/activemq-dev/201205.mbox/raw/
     //        %3C634996273.21688.1336051731428.JavaMail.tomcat@hel.zones.apache.org%3E/
     $consumer2->unsubscribe($this->topic);
     // that took me some time...
     $consumer2->unsubscribe($this->topic, null, null, true);
     $consumer2->disconnect();
 }
Пример #3
0
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
// include a library
use Stomp\Stomp;
// make a connection
$con = new Stomp('tcp://localhost:61613');
// connect
$con->connect();
$con->setReadTimeout(1);
// subscribe to the queue
$con->subscribe('/queue/transactions', array('ack' => 'client', 'activemq.prefetchSize' => 1));
// try to send some messages
$con->begin('tx1');
for ($i = 1; $i < 3; $i++) {
    $con->send('/queue/transactions', $i, array('transaction' => 'tx1'));
}
// if we abort transaction, messages will not be sent
$con->abort('tx1');
// now send some messages for real
$con->begin('tx2');
echo "Sent messages {\n";
for ($i = 1; $i < 5; $i++) {
    echo "\t{$i}\n";
    $con->send('/queue/transactions', $i, array('transaction' => 'tx2'));
Пример #4
0
 protected function consume()
 {
     $consumer2 = new Stomp($this->broker);
     $consumer2->sync = true;
     $consumer2->clientId = 'test';
     $consumer2->setReadTimeout(1);
     $consumer2->connect($this->login, $this->password);
     $consumer2->subscribe($this->topic, array('persistent' => 'true'));
     $frame = $consumer2->readFrame();
     $this->assertEquals($frame->body, 'test message');
     if ($frame != null) {
         $consumer2->ack($frame);
     }
     $consumer2->disconnect();
 }
Пример #5
0
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
// include a library
use Stomp\Stomp;
// create a producer
$producer = new Stomp('tcp://localhost:61613');
// create a consumer
$consumer = new Stomp('tcp://localhost:61613');
$consumer->setReadTimeout(1);
// set clientId on a consumer to make it durable
$consumer->clientId = 'test';
// connect
$producer->connect();
$consumer->connect();
// subscribe to the topic
$consumer->subscribe('/topic/test', null, true, true);
// send a message to the topic
$producer->send('/topic/test', 'test-1');
echo "Message 'test-1' sent to topic\n";
// receive a message from the topic
$msg = $consumer->readFrame();
// do what you want with the message
if ($msg != null) {
    echo "Message '{$msg->body}' received from topic\n";