public function testAbortTransaction() { $this->assertTrue($this->Stomp->connect()); $this->assertTrue($this->Stomp->begin('my-id')); $this->assertTrue($this->Stomp->send('/queue/test', 'test t-id', array('transaction' => 'my-id'))); $this->assertTrue($this->Stomp->abort('my-id')); $this->assertTrue($this->Stomp->subscribe('/queue/test')); $this->Stomp->getConnection()->setReadTimeout(array(1, 0)); $frame = $this->Stomp->readFrame(); $this->assertFalse($frame); }
protected function consume() { $consumer2 = new Stomp($this->broker); $consumer2->sync = false; $consumer2->clientId = 'test'; $consumer2->getConnection()->setReadTimeout(0, 500000); $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(); }
public function testGetConnectionReturnsUsedConnection() { $connection = new Connection('tcp://myhost'); $stomp = new Stomp($connection); $this->assertSame($connection, $stomp->getConnection(), 'getConnection must return passed connection instance.'); }
* * 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->getConnection()->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";
protected function consume() { $consumer2 = new Stomp($this->broker); $consumer2->sync = true; $consumer2->clientId = 'test'; $consumer2->getConnection()->setReadTimeout(0, 500000); $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(); }