function json_rpc_stomp_init($server = '', $connopt = null, $subopt = null) { global $json_rpc_opt, $json_rpc_error, $json_rpc_errormsg, $json_rpc_stompconn, $json_rpc_tempqueue; $opt = array('ack' => 'client', 'activemq.prefetchSize' => 1, 'activemq.dispatchAsync' => 'true'); if ($json_rpc_stompconn) { $json_rpc_stompconn->disconnect(); } if (is_array($subopt)) { $opt = array_merge($opt, $supopt); } $json_rpc_opt = $opt; if (empty($server)) { $server = $json_rpc_stompserver; } $json_rpc_stompconn = new StompConnection($server); // connect if (!$json_rpc_stompconn->connect($connopt['login'], $connopt['passcode'])) { $json_rpc_error = JSON_RPC_ERR_CONNECT_TRANSPORT; $json_rpc_errormsg = $json_rpc_stompconn->error . "\n" . $json_rpc_stompconn->exception; return false; } //Automatic generate tempqueue name; $json_rpc_tempqueue = uniqid('client'); if (!$json_rpc_stompconn->subscribe("/temp-queue/{$json_rpc_tempqueue}", $opt)) { $json_rpc_error = JSON_RPC_ERR_INIT_TRANSPORT; $json_rpc_errormsg = $json_rpc_stompconn->error . "\n" . $json_rpc_stompconn->exception; return false; } register_shutdown_function('json_rpc_stomp_destroy'); return true; }
<?php /** * * Copyright 2005-2006 The Apache Software Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * 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. */ require_once 'Stomp.php'; $c = new StompConnection("localhost"); $result = $c->connect("hiram", "test"); print_r($result); $c->subscribe("/queue/FOO"); $c->send("/queue/FOO", "Hello World!"); // Wait for the message to come in.. $result = $c->readFrame(); print_r($result); $c->disconnect();
require_once "JSON.php"; #PHP version 5.1 or less. #$json = '{"version": "1.1", "method": "subtract", "params": [23, 42], "id": 2}'; #$json = '{"version": "1.1", "method": "subtract", "params": [99, 34], "id": 2}'; #$json = '{"version": "1.1", "method": "add", "params": [99, 34], "id": 3}'; #$json = '{"version": "1.1", "method": "subtract", "params": {"minuend": 42, "subtrahend": 23}, "id": 4}'; //error_reporting(E_ERROR | E_WARNING | E_PARSE); error_reporting(E_ALL); // include a library require_once "Stomp.php"; // make a connection $con = new StompConnection("tcp://localhost:61613"); // connect $con->connect(); $con->subscribe("/temp-queue/clientreply", array('ack' => 'auto')); $start = time(); $i = 33; //for ($i = 0;$i<100;$i++) { print "Sending request:"; print $con->send("/queue/jsonrpc", '{"version": "1.1", "method": "add", "params": [' . $i . ', 2009], "id": ' . ($i + 100) . '}', array('reply-to' => '/temp-queue/clientreply')) . "\n"; //sleep(3); $msg = $con->readFrame(true, 10); if (is_object($msg)) { print "Reply:\n"; print $msg->body . "\n"; } else { print "Time out or Error\n"; } //} /*print "Reply:\n";