public function notify($type, TableInterface $table, RecordInterface $record) { $message = Json::encode($record->getData()); $headers = array('amun-table' => $table->getName(), 'amun-type' => $type, 'amun-user-id' => $this->user->id); $stomp = new Stomp($this->registry['stomp.broker'], $this->registry['stomp.user'], $this->registry['stomp.pw']); $stomp->send($this->registry['stomp.destination'], $message, $headers); unset($stomp); }
/** * @param RpcRequest $rpcRequest * * @return RpcResponse|null */ protected function sendRequest(RpcRequest $rpcRequest) { $destination = $this->destination; $message = $this->serializer->serialize($rpcRequest, $this->protocol, ['encoding' => $this->encoding]); $headers = ['content_type' => 'application/' . $this->encoding, 'rpc_type' => $this->protocol]; $this->client->send($destination, $message, $headers); return; }
/** * Experimental task to enable kill processing from queue. * @param array $options */ public function stomp_process_queue(array $options) { $this->cli->header("Starting Stomp Import"); $reg = Registry::getInstance(); $log = $reg->getLogger(); $stompcfg = $reg->stomp; if (is_null($stompcfg) || !is_array($stompcfg)) { $this->cli->error("stomp is not configured, see config.php for details"); $log->critical("stomp not configured, exiting"); return; } $stomp = new \Stomp($stompcfg['url'], $stompcfg['user'], $stompcfg['passwd']); // destination has the destination topic (for example /topic/kills) $destination = $reg->stomp['destination_read']; // we subscribe with additional parameters $stomp->subscribe($destination, array("id" => $reg->stomp['dsub_id'], "persistent" => "true", "ack" => "client", "prefetch-count" => 1)); while (true) { try { if (!$stomp->hasFrame()) { continue; } $frame = $stomp->readFrame(); if ($frame) { $log->debug("received frame with message-id: " . $frame->headers['message-id']); $killdata = json_decode($frame->body, true); $existing = Kill::getByKillId($killdata["killID"]); if (!is_null($existing)) { $log->debug($frame->headers['message-id'] . '::' . $killdata["killID"] . " kill by killID exists"); $stomp->ack($frame); continue; } try { $apiParser = new EveAPI(); $apiParser->parseKill($killdata); $log->debug($frame->headers['message-id'] . '::' . $killdata["killID"] . " saved"); $stomp->ack($frame); } catch (\Exception $e) { $log->error($frame->headers['message-id'] . "could not be saved, exception: " . $e->getMessage()); } } } catch (\StompException $e) { $log->error("there was some kind of error with stomp: " . $e->getMessage()); $log->info("going to sleep for 10, retrying then"); // we have a stomp exception here most likely that means that the server died. // so we are going to sleep for a bit and retry sleep(10); // replace stomp connection by new one // @todo: check if that might cause open connections not to close over time unset($stomp); $stomp = new \Stomp($stompcfg['url'], $stompcfg['user'], $stompcfg['passwd']); $stomp->subscribe($destination, array("id" => $reg->stomp['dsub_id'], "persistent" => "true", "ack" => "client", "prefetch-count" => 1)); $log->info("stomp process retrying"); } } }
private static function getConnection() { try { $conn = new Stomp("tcp://" . MQ_IP . ":" . MQ_PORT); $conn->connect(); return $conn; } catch (StompException $e) { MailUtil::sendSESFromHtml("<html>Active MQ Failed <p/></html>", "Hasan Keklik <*****@*****.**>", "Active MQ Failed"); error_log("Connection Error: " . $e->getTraceAsString()); } return null; }
public function loop() { $d = EventDispatcher::get(); if (!$this->stomp) { $this->connect(); } while (true) { if ($this->stomp->hasFrame()) { $msg = $this->stomp->readFrame(); $destination = $msg->headers['destination']; /** @var Topics\AbstractTopic $topic */ $topic = $this->eventTopics[$destination]; //$factory = "\\OpenRailData\\NetworkRail\\Services\\Stomp\\Events\\" . $topic->getFactory() . "\\Factory"; // Save events locally so we can ack the message. $events = []; foreach (json_decode($msg->body) as $raw) { $events[] = $raw; } $this->stomp->ack($msg); foreach ($events as $event) { $d->dispatch("raw" . $topic->getEventName(), new StompEvent($event)); } } } }
private function sendMessageToAM($destination, $message) { require_once 'Stomp.php'; require_once 'Stomp/Message/Map.php'; $con = new Stomp(Service::ACTIVE_MQ); $conn->sync = false; $con->connect(); $header = array(); $header['transformation'] = 'jms-map-json'; $mapMessage = new StompMessageMap($message, $header); $result = $con->send($destination, $mapMessage, array('persistent' => 'true')); $con->disconnect(); if (!$result) { $this->log("sendMessageToAM", "send message to activemq failure,\r\n destination: {$destination},\r\n mapMessage: " . print_r($mapMessage, true) . "\r\n <br>"); } return $result; }
/** * Send a meesage to ActiveMQ * * @param array $data message to send * @param string $queue name of the queue * @param string $scheme type of the connection: tcp, udp * @param string $host host of the ActiveMQ * @param int $port port of the ActiveMQ * @return true|false depends on the message is sent correctly */ public function send($data = null, $queue, $scheme, $host, $port) { if ($data) { try { $url = $scheme . "://" . $host . ":" . $port; $con = new Stomp($url); $message = '[' . json_encode($data) . ']'; $con->connect(); $con->send($queue, json_encode($data)); $con->disconnect(); return true; } catch (Exception $e) { return false; } } else { return false; } }
public function execute($parameters, $db) { global $stompServer, $stompUser, $stompPassword; // Ensure the class exists if (!class_exists("Stomp")) { die("ERROR! Stomp not installed! Check the README to learn how to install Stomp...\n"); } $stomp = new Stomp($stompServer, $stompUser, $stompPassword); $stompKey = "StompSend::lastFetch"; $lastFetch = date("Y-m-d H:i:s", time() - 12 * 3600); $lastFetch = Storage::retrieve($stompKey, $lastFetch); $stompCount = 0; $timer = new Timer(); while ($timer->stop() < 60000) { if (Util::isMaintenanceMode()) { return; } $result = $db->query("SELECT killID, insertTime, kill_json FROM zz_killmails WHERE insertTime > :lastFetch AND processed > 0 ORDER BY killID limit 1000", array(":lastFetch" => $lastFetch), 0); foreach ($result as $kill) { $lastFetch = max($lastFetch, $kill["insertTime"]); if (!empty($kill["kill_json"])) { if ($kill["killID"] > 0) { $stompCount++; $destinations = self::getDestinations($kill["kill_json"]); foreach ($destinations as $destination) { $stomp->send($destination, $kill["kill_json"]); } } $data = json_decode($kill["kill_json"], true); $json = json_encode(array("solarSystemID" => $data["solarSystemID"], "killID" => $data["killID"], "characterID" => $data["victim"]["characterID"], "corporationID" => $data["victim"]["corporationID"], "allianceID" => $data["victim"]["allianceID"], "shipTypeID" => $data["victim"]["shipTypeID"], "killTime" => $data["killTime"])); $stomp->send("/topic/starmap.systems.active", $json); } } Storage::store($stompKey, $lastFetch); sleep(5); } if ($stompCount > 0) { Log::log("Stomped {$stompCount} killmails"); } }
/** * @param InputInterface $input * @param OutputInterface $output * * @return int|null|void */ protected function execute(InputInterface $input, OutputInterface $output) { //Init rena $app = RenaApp::getInstance(); $startTime = time() + 3600; // Current time + 60 minutes $run = true; $stomp = new \Stomp($app->baseConfig->getConfig("server", "stomp"), $app->baseConfig->getConfig("username", "stomp"), $app->baseConfig->getConfig("password", "stomp")); $stomp->subscribe("/topic/kills", array("id" => "projectRena", "persistent" => "true", "ack" => "client", "prefetch-count" => 1)); do { $frame = $stomp->readFrame(); if (!empty($frame)) { $killdata = json_decode($frame->body, true); if (!empty($killdata)) { $app->StatsD->increment("stompReceived"); if (isset($killdata["_stringValue"])) { unset($killdata["_stringValue"]); } // Fix the killID $killdata["killID"] = (int) $killdata["killID"]; $json = json_encode($killdata, JSON_NUMERIC_CHECK); $hash = hash("sha256", ":" . $killdata["killTime"] . ":" . $killdata["solarSystemID"] . ":" . $killdata["moonID"] . "::" . $killdata["victim"]["characterID"] . ":" . $killdata["victim"]["shipTypeID"] . ":" . $killdata["victim"]["damageTaken"] . ":"); $inserted = $app->Db->execute("INSERT IGNORE INTO killmails (killID, hash, source, kill_json) VALUES (:killID, :hash, :source, :kill_json)", array(":killID" => $killdata["killID"], ":hash" => $hash, ":source" => "stomp", ":kill_json" => $json)); if ($inserted > 0) { // Push it over zmq to the websocket $context = new ZMQContext(); $socket = $context->getSocket(ZMQ::SOCKET_PUSH, "rena"); $socket->connect("tcp://localhost:5555"); $socket->send($json); } } $stomp->ack($frame->headers["message-id"]); } // Kill it after an hour if ($startTime <= time()) { $run = false; } } while ($run == true); }
/** * @param InputInterface $input * @param OutputInterface $output * * @return int|null|void */ protected function execute(InputInterface $input, OutputInterface $output) { //Init rena /** @var RenaApp $app */ $app = RenaApp::getInstance(); $startTime = time() + 3600; // Current time + 60 minutes $run = true; $stomp = new \Stomp($app->baseConfig->getConfig("server", "stomp"), $app->baseConfig->getConfig("username", "stomp"), $app->baseConfig->getConfig("password", "stomp")); $stomp->subscribe("/topic/kills", array("id" => $app->baseConfig->getConfig("queueName", "stomp", "projectRena"), "persistent" => "true", "ack" => "client", "prefetch-count" => 1)); do { $frame = $stomp->readFrame(); if (!empty($frame)) { $killdata = json_decode($frame->body, true); if (!empty($killdata)) { $app->StatsD->increment("stompReceived"); if (isset($killdata["_stringValue"])) { unset($killdata["_stringValue"]); } // Fix the killID $killdata["killID"] = (int) $killdata["killID"]; $json = json_encode($killdata, JSON_NUMERIC_CHECK); $hash = $app->CrestFunctions->generateCRESTHash($killdata); $inserted = $app->killmails->insertIntoKillmails($killdata["killID"], 0, $hash, "stomp", $json); if ($inserted > 0) { \Resque::enqueue("turbo", "\\ProjectRena\\Task\\Resque\\upgradeKillmail", array("killID" => $killdata["killID"])); } } $stomp->ack($frame->headers["message-id"]); } // Kill it after an hour if ($startTime <= time()) { $run = false; } } while ($run == true); }
function getDIStompConnection($renew = false) { global $wgStompServer; static $conn = null; if ($conn === null || !$conn->isConnected() || $renew) { if ($conn !== null && $conn->isConnected()) { $conn->disconnect(); //just to be safe. } // make a connection require_once "Stomp.php"; $conn = new Stomp($wgStompServer); // connect $conn->connect(); } return $conn; }
protected function postMessage($response) { $this->amq->send($this->replyQueue, $response, array('correlation-id' => $this->correlationId)); }
<?php require_once '../init.php'; global $stompListen; if ($stompListen != true) { exit; } $topics[] = '/topic/kills'; try { $stomp = new Stomp($stompServer, $stompUser, $stompPassword); } catch (Exception $ex) { Util::out("Stomp error: " . $ex->getMessage()); exit; } $stomp->setReadTimeout(1); foreach ($topics as $topic) { $stomp->subscribe($topic, array('id' => 'zkb-' . $baseAddr, 'persistent' => 'true', 'ack' => 'client', 'prefetch-count' => 1)); } $stompCount = 0; $timer = new Timer(); while ($timer->stop() <= 59000) { $frame = $stomp->readFrame(); if (!empty($frame)) { $killdata = json_decode($frame->body, true); $killID = (int) $killdata['killID']; if ($killID == 0) { continue; } $hash = $hash = Killmail::getCrestHash($killID, $killdata); $killdata['killID'] = (int) $killID; if (!$mdb->exists('crestmails', ['killID' => $killID, 'hash' => $hash])) {
/** * @param string $destination * @param StompFrame|string $msg * @param array $properties * @param null $sync * * @return bool * @throws Exception */ public function send($destination, $msg, $properties = array(), $sync = null) { if (!empty($this->clientType) && $this->clientType != self::CLIENT_TYPE_PUBLISHER) { throw new Exception("This client is a {$this->clientType}. A client can be only publisher or subscriber, not both."); } elseif (empty($this->clientType)) { $this->connect(); } $this->clientType = self::CLIENT_TYPE_PUBLISHER; return parent::send('/queue/' . $destination, $msg, $properties, $sync); }
* 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. */ /* To successfully run this example, you must first start the broker with stomp+ssl enabled. You can do that by executing: $ ${ACTIVEMQ_HOME}/bin/activemq xbean:activemq-connectivity.xml Then you can execute this example with: $ php connectivity.php */ // include a library require_once "Stomp.php"; // make a connection $con = new Stomp("failover://(tcp://localhost:61614,ssl://localhost:61612)?randomize=false"); // connect $con->connect(); // send a message to the queue $con->send("/queue/test", "test"); echo "Sent message with body 'test'\n"; // subscribe to the queue $con->subscribe("/queue/test"); // receive a message from the queue $msg = $con->readFrame(); // do what you want with the message if ($msg != null) { echo "Received message with body '{$msg->body}'\n"; // mark the message as received in the queue $con->ack($msg); } else {
echo "Message '{$msg->body}' received from topic\n"; $consumer->ack($msg); } else { echo "Failed to receive a message\n"; } sleep(1); // disconnect durable consumer $consumer->unsubscribe("/topic/test"); $consumer->disconnect(); echo "Disconnecting consumer\n"; // send a message while consumer is disconnected // note: only persistent messages will be redelivered to the durable consumer $producer->send("/topic/test", "test1", array('persistent' => 'true')); echo "Message 'test1' sent to topic\n"; // reconnect the durable consumer $consumer = new Stomp("tcp://localhost:61613"); $consumer->clientId = "test"; $consumer->connect(); $consumer->subscribe("/topic/test"); echo "Reconnecting consumer\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"; $consumer->ack($msg); } else { echo "Failed to receive a message\n"; } // disconnect $consumer->unsubscribe("/topic/test");
/** * Make socket connection to the server * We also set the stream to non-blocking mode, since we'll be * select'ing to wait for updates. In blocking mode it seems * to get confused sometimes. * * @throws StompException */ protected function _makeConnection() { parent::_makeConnection(); stream_set_blocking($this->_socket, 0); }
<?php /** * * Copyright (C) 2009 Progress Software, Inc. All rights reserved. * http://fusesource.com * * 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. */ // include a library require_once "Stomp.php"; // make a connection $con = new Stomp("tcp://localhost:61613"); // connect $con->connect(); // send a message to the queue $con->send("/topic/fedora.contentmodel.demo:testCModel", "test", array('pid' => 'demo:22', 'dsid' => 'fakedsid')); echo "Sent message with body 'test'\n"; // disconnect $con->disconnect();
* 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. */ /* To successfully run this example, you must first start the broker with stomp+ssl enabled. You can do that by executing: $ ${ACTIVEMQ_HOME}/bin/activemq xbean:activemq-connectivity.xml Then you can execute this example with: $ php connectivity.php */ // include a library // make a connection try { $con = new Stomp("tcp://192.168.56.101:61613"); // connect #// send a message to the queue $msg = '<?xml version="1.0" encoding="UTF-8"?> <entry xmlns="http://www.w3.org/2005/Atom" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:fedora-types="http://www.fedora.info/definitions/1/0/types/"> <id>urn:uuid:19aab165-c920-40a1-a349-443f60f84567</id> <updated>2010-08-08T15:57:08.659Z</updated> <author> <name>umroymr2</name> <uri>http://192.168.56.101:8080/fedora</uri> </author> <title type="text">modifyDatastreamByValue</title> <category term="uofm:highResImage" scheme="fedora-types:pid" label="xsd:string"></category> <category term="ISLANDORACM" scheme="fedora-types:dsID" label="xsd:string"></category> <category term="" scheme="fedora-types:altIDs" label="fedora-types:ArrayOfString"></category>
if (!$host) { $host = "localhost"; } $port = getenv("APOLLO_PORT"); if (!$port) { $port = 61613; } $destination = '/topic/event'; function now() { list($usec, $sec) = explode(' ', microtime()); return (double) $usec + (double) $sec; } try { $url = 'tcp://' . $host . ":" . $port; $stomp = new Stomp($url, $user, $password); $stomp->subscribe($destination); $start = now(); $count = 0; echo "Waiting for messages...\n"; while (true) { $frame = $stomp->readFrame(); if ($frame) { if ($frame->command == "MESSAGE") { if ($frame->body == "SHUTDOWN") { $diff = round(now() - $start, 2); echo "Received " . $count . " in " . $diff . " seconds\n"; break; } else { if ($count == 0) { $start = now();
* 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. */ // include a library require_once "Stomp.php"; // 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";
$password = "******"; } $host = getenv("ACTIVEMQ_HOST"); if (!$host) { $host = "localhost"; } $port = getenv("ACTIVEMQ_PORT"); if (!$port) { $port = 61613; } $destination = '/topic/event'; $messages = 10000; $size = 256; $DATA = "abcdefghijklmnopqrstuvwxyz"; $body = ""; for ($i = 0; $i < $size; $i++) { $body .= $DATA[$i % 26]; } try { $url = 'tcp://' . $host . ":" . $port; $stomp = new Stomp($url, $user, $password); for ($i = 0; $i < $messages; $i++) { $stomp->send($destination, $body); if ($i % 1000 == 0) { echo "Sent " . $i . " messages\n"; } } $stomp->send($destination, "SHUTDOWN"); } catch (StompException $e) { echo $e->getMessage(); }
public static function send($process_name, $process_no, $tenant_id, $parameters, $properties, $line_queue, $user_login_id) { if ($process_no == null || $process_no == '') { $process_no = Uuid::uuid1()->toString(); } $datetime = DateUtil::dateTimeNow(); \DB::beginTransaction(); try { \Log::info("Save to Process Message"); // insert ke t_process_message $msg = new \ProcessMessage(); $msg->process_name = $process_name; $msg->process_no = $process_no; $msg->tenant_id = $tenant_id; $msg->process_create_datetime = $datetime; $msg->process_queue_datetime = ""; $msg->process_finish_datetime = ""; $msg->process_status = "G"; $msg->ref_id = -99; $msg->tag_id = -99; $msg->flg_reprocess = "N"; $msg->prev_process_message_id = -99; $msg->line_queue = $line_queue; SchemaUtil::auditCreate($msg, $datetime, $user_login_id); $msg->save(); \Log::info("Save to Process Parameters"); // insert ke t_process_parameter // if(!empty($parameters) && is_array($parameters)){ // foreach($parameters as $key => $value){ // $param = new \ProcessParameter(); // $param->process_message_id = $msg->process_message_id; // $param->process_parameter_key = $key; // $param->process_parameter_value = $value; // SchemaUtil::auditCreate($param, $datetime, $user_login_id); // $param->save(); // } // } $param = new \ProcessParameter(); $param->process_message_id = $msg->process_message_id; $param->process_parameter_key = "data"; $param->process_parameter_value = json_encode($parameters); SchemaUtil::auditCreate($param, $datetime, $user_login_id); $param->save(); \DB::commit(); $send = true; // flag to send queue } catch (Exception $ex) { \DB::rollback(); \Log::error($ex->getMessage()); $send = false; // flag not to send queue } if ($send) { \Log::info("Send to Queue"); // Send to Queue using Stomp $stomp = new \Stomp(\Config::get('constants.QUEUE_URL')); $properties = array_merge($properties, ["processName" => $process_name, "processNo" => $process_no, "tenantId" => $tenant_id]); $stomp->send($line_queue, json_encode($parameters), $properties); \Log::info("Sent!"); unset($stomp); } }
* 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. */ /* To successfully run this example, you must first start the broker with security enabled. You can do that by executing: $ ${ACTIVEMQ_HOME}/bin/activemq xbean:activemq-security.xml Then you can execute this example with: $ php security.php */ // include a library require_once "Stomp.php"; // make a connection $con = new Stomp("tcp://localhost:61613"); // use sync operations $con->sync = true; // connect try { $con->connect("dejan", "test"); } catch (StompException $e) { echo "dejan cannot connect\n"; echo $e->getMessage() . "\n"; echo $e->getDetails() . "\n\n\n"; } $con->connect("guest", "password"); // send a message to the queue try { $con->send("/queue/test", "test"); echo "Guest sent message with body 'test'\n";
public function dealSkuStockMessage() { require_once 'Stomp.php'; require_once 'Stomp/Message/Map.php'; $consumer = new Stomp($this->conf['service']['activeMq']); $consumer->clientId = "inventory"; $consumer->connect(); $consumer->subscribe("/topic/SkuOutStock", array('transformation' => 'jms-map-json')); while (1) { $msg = $consumer->readFrame(); if ($msg != null) { //echo "Message '$msg->body' received from queue\n"; //print_r($msg->map); //$this->inventoryTakeOut($msg->map['inventory_model'], $msg->map['quantity'], $msg->map['shipment_id'], $msg->map['shipment_method']); $consumer->ack($msg); } sleep(1); } }
<?php require_once 'Stomp.php'; $stomp = new Stomp("tcp://localhost:61613"); $stomp->connect('system', 'manager'); $stomp->subscribe("/topic/STOCKS.JAVA"); $stomp->subscribe("/topic/STOCKS.IONA"); $i = 0; while ($i++ < 100) { $frame = $stomp->readFrame(); $xml = new SimpleXMLElement($frame->body); echo $xml->attributes()->name . "\t" . number_format($xml->price, 2) . "\t" . number_format($xml->offer, 2) . "\t" . ($xml->up == "true" ? "up" : "down") . "\n"; $stomp->ack($frame); } $stomp->disconnect();
public function dealSkuOutOfStockMessage() { require_once __DOCROOT__ . '/Stomp.php'; require_once __DOCROOT__ . '/Stomp/Message/Map.php'; $consumer = new Stomp($this->config['service']['activeMQ']); $consumer->clientId = "eBayListingSkuOutOfStock"; $consumer->connect(); $consumer->subscribe($this->config['topic']['skuOutOfStock'], array('transformation' => 'jms-map-json')); //for($i=0; $i<6; $i++){ $msg = $consumer->readFrame(); if ($msg != null) { //echo "Message '$msg->body' received from queue\n"; //print_r($msg->map); $consumer->ack($msg); $sku_array = explode(",", $msg->map['sku']); foreach ($sku_array as $sku) { $sql = "update template set status = 3 where SKU = '" . $sku . "' and status = 6"; echo $sql . "\n"; $result = mysql_query($sql, Cron::$database_connect); } } else { echo date("Y-m-d H:i:s") . " no message\n"; } //sleep(1); //} $consumer->disconnect(); }
<?php // include a library require_once "Stomp.php"; // make a connection $con = new Stomp("tcp://localhost:61613"); // connect $con->connect(); // 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++) { $con->send("/queue/transactions", $i, array("transaction" => "tx2")); echo "\t{$i}\n"; } echo "}\n"; // they will be available for consumers after commit $con->commit("tx2");
public function dealSkuStock() { require __DOCROOT__ . '/Stomp.php'; require __DOCROOT__ . '/Stomp/Message/Map.php'; $consumer = new Stomp($this->conf['service']['activeMq']); $consumer->clientId = "inventorySkuStock"; $consumer->connect(); $consumer->subscribe($this->conf['topic']['skuStock'], array('transformation' => 'jms-map-json')); $msg = $consumer->readFrame(); if ($msg != null) { $consumer->ack($msg); if ($msg->map['stock'] <= 0 && $msg->map['operate'] == "+") { $sql = "select status from sku_status_history where sku = '" . $msg->map['sku'] . "' order by id desc limit 0,1"; $result = mysql_query($sql, $this->conn); $row = mysql_fetch_assoc($result); $this->log("dealSkuStock", print_r($msg->map, true) . "<br>"); $this->updateCustomFieldValueBySku($msg->map['sku'], $this->conf['fieldArray']['skuStatus'], $this->conf['skuStatus'][str_replace(" ", "_", $row['status'])]); } } else { echo date("Y-m-d H:i:s") . " no message\n"; } $consumer->disconnect(); }
function send_bean(&$bean, $queue_name) { global $sugar_config; $stomp_url = "tcp://localhost:40001"; if (!empty($sugar_config['stomp_url'])) { $stomp_url = $sugar_config['stomp_url']; } // make a connection $con = new Stomp($stomp_url); // connect $con->connect(); // send a message to the queue $con->send($queue_name, $this->serialize_bean($bean)); // disconnect $con->disconnect(); }