Пример #1
0
 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;
 }
Пример #2
0
 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;
 }
Пример #3
0
 /**
  * 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;
     }
 }
<?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");
<?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();
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;
}
Пример #7
0
} 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");
$consumer->disconnect();
$producer->disconnect();
Пример #8
0
 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();
 }
Пример #9
0
 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();
 }
/*
 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";
} catch (StompException $e) {
    echo "guest cannot send\n";
    echo $e->getMessage() . "\n";
    echo $e->getDetails() . "\n\n\n";
}
Пример #11
0
 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);
     }
 }
Пример #12
0
 private function enqueueComment()
 {
     $this->payload = array('message_type' => $this->new_record->message_type, 'message' => $this->new_record->message, 'id_segment' => $this->new_record->id_segment, 'full_name' => $this->new_record->full_name, 'email' => $this->new_record->email, 'source_page' => $this->new_record->source_page, 'formatted_date' => $this->new_record->getFormattedDate(), 'thread_id' => $this->new_record->thread_id, 'timestamp' => (int) $this->new_record->timestamp);
     $message = json_encode(array('_type' => 'comment', 'data' => array('id_job' => $this->__postInput['id_job'], 'passwords' => $this->getProjectPasswords(), 'id_client' => $this->__postInput['id_client'], 'payload' => $this->payload)));
     $stomp = new Stomp(INIT::$QUEUE_BROKER_ADDRESS);
     $stomp->connect();
     $stomp->send(INIT::$SSE_COMMENTS_QUEUE_NAME, $message, array('persistent' => 'true'));
 }
Пример #13
0
       public function update($old, $new){
               try {
                       if ($new !== null) { // Update or Create
                               $method = "request";
                               $tmpFilename = $new->getIcs($userId, $method, false);
                       } elseif ($old !== null) { // Delete
                               $method = "cancel";
                               $tmpFilename = $old->getIcs($userId, $method, false);
                       } else {
                               throw new OBM_ObserverException(__('$old and $new cannot be null at the same time in OBM_EventStompObserver'));
                       }
                                               
                       $contentOfTmpFilename = fread(fopen($tmpFilename, "r"), filesize($tmpFilename));
		       $stomp = new Stomp("tcp://".$GLOBALS['stomp_host'].":".$GLOBALS['stomp_port']); 
                       $stomp->connect();
                       $stomp->send("jms.topic.eventChanges", $contentOfTmpFilename, array('persistent'=>'true'));

                       $stomp->disconnect();
               } catch (StompException $e) {
                       throw new OBM_ObserverException(__("An Exception was thrown during OBM_EventStompObserver->update " . $e->getMessage() . " -"));
	       }
       }
Пример #14
-1
 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();
 }