/**
  * @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;
 }
Example #2
0
 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);
 }
 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");
     }
 }
Example #4
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;
 }
Example #5
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;
     }
 }
Example #6
0
require_once "Stomp.php";
// 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");
sleep(1);
// send a message to the topic
$producer->send("/topic/test", "test", array('persistent' => 'true'));
echo "Message 'test' 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";
    $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";
Example #7
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();
Example #8
0
<?php

$broker = 'tcp://localhost:61613';
$queue = '/queue/foo';
$msg = 'bar';
try {
    $stomp = new Stomp($broker);
    $stomp->send($queue, $msg);
    $stomp->subscribe($queue);
    $frame = $stomp->readFrame();
    if ($frame->body === $msg) {
        echo "Worked\n";
        $stomp->ack($frame, array('receipt' => 'message-12345'));
    } else {
        echo "Failed\n";
    }
    $stomp->disconnect();
} catch (StompException $e) {
    echo $e->getMessage();
}
Example #9
0
    $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();
}
Example #10
0
 protected function postMessage($response)
 {
     $this->amq->send($this->replyQueue, $response, array('correlation-id' => $this->correlationId));
 }
Example #11
0
 /**
  * Send a stomp collaboration event message to all or a single user
  * Always call before sendResponse because the response will be
  * complete and stomp will throw exceptions.
  *
  * @param String $topicId
  *           could be a userId for a forumId
  */
 public static function sendEvent($eventDomain, $topicId, $eventId, $eventDescription, $eventParameters)
 {
     $impulseHeader = array("persistent" => 'false');
     $content = array("sourceUserId" => self::getUserId(), "type" => $eventId, "description" => $eventDescription, "params" => $eventParameters);
     $msg = json_encode($content, JSON_NUMERIC_CHECK);
     if (self::$stompMode) {
         try {
             $stomp = new Stomp('tcp://localhost:61613', 'admin', 'password');
             $stomp->send(self::$topic . $eventDomain . '.' . $topicId, $msg, $impulseHeader);
             unset($stomp);
         } catch (StompException $e) {
             self::logError($e, __METHOD__);
         }
     } else {
         $pdo = new EventServicePDO();
         $pdo->pushEvent(self::getUserId(), $eventDomain . '.' . $topicId, $msg);
     }
 }
Example #12
0
<?php

// Library
require_once "library/Stomp.php";
// Broker URI
$BROKER_URI = "tcp://kaazing.kevinhoyt.com:61613";
$TOPIC = "/topic/heart";
// Connection
$conn = new Stomp($BROKER_URI);
// Connect
$conn->connect();
// Send a message
$conn->send($TOPIC, $argv[1]);
// Debug
// echo "Sent message.\n";
// Disconnect
$conn->disconnect();
Example #13
0
     $sku_str = "";
     foreach ($id_array as $id) {
         $sql = "select inventory_model_code from inventory_model where inventory_model_id = " . $id;
         $result = mysql_query($sql);
         $row = mysql_fetch_assoc($result);
         $sku_str .= $row['inventory_model_code'] . ",";
     }
     $sku_str = substr($sku_str, 0, -1);
     $con = new Stomp($config['service']['activeMq']);
     $con->connect();
     // send a message to the queue
     $body = array("skus" => $sku_str, "status" => $_POST['status']);
     $header = array();
     $header['transformation'] = 'jms-map-json';
     $mapMessage = new StompMessageMap($body, $header);
     $con->send("/queue/SkuStatus", $mapMessage, array('persistent' => 'true'));
     $con->disconnect();
 }
 if (strpos($_POST['ids'], ",") != false) {
     $id_array = explode(",", $_POST['ids']);
     foreach ($id_array as $id) {
         $sql = "update custom_field_selection set custom_field_value_id = " . $status_array_2[$_POST['status']] . " where entity_qtype_id = 2 and custom_field_value_id in (" . $status_string . ") and entity_id = " . $id;
         $result = mysql_query($sql);
         echo $sql . "\n";
     }
 } else {
     $id = $_POST['ids'];
     $sql = "update custom_field_selection set custom_field_value_id = " . $status_array_2[$_POST['status']] . " where entity_qtype_id = 2 and custom_field_value_id in (" . $status_string . ") and entity_id = " . $id;
     $result = mysql_query($sql);
     echo $sql . "\n";
 }
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
// include a library
require_once "Stomp.php";
require_once "Stomp/Message/Map.php";
// make a connection
$con = new Stomp("tcp://localhost:61613");
// connect
$con->connect();
// send a message to the queue
$body = array("city" => "Belgrade", "name" => "Dejan");
$header = array();
$header['transformation'] = 'jms-map-json';
$mapMessage = new StompMessageMap($body, $header);
$con->send("/queue/test", $mapMessage);
echo "Sending array: ";
print_r($body);
$con->subscribe("/queue/test", array('transformation' => 'jms-map-json'));
$msg = $con->readFrame();
// extract
if ($msg != null) {
    echo "Received array: ";
    print_r($msg->map);
    // mark the message as received in the queue
    $con->ack($msg);
} else {
    echo "Failed to receive a message\n";
}
// disconnect
$con->disconnect();
Example #15
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'));
 }
 */
/*
 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 "Failed to receive a message\n";
}
// disconnect
$con->disconnect();
Example #17
0
 /**
  * @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);
 }
Example #18
0
  <category term="ISLANDORACM" scheme="fedora-types:dsID" label="xsd:string"></category>
  <category term="" scheme="fedora-types:altIDs" label="fedora-types:ArrayOfString"></category>
  <category term="High Resolution Image" scheme="fedora-types:dsLabel" label="xsd:string"></category>
  <category term="" scheme="fedora-types:formatURI" label="xsd:string"></category>
  <category term="[OMITTED]" scheme="fedora-types:dsContent" label="xsd:base64Binary"></category>
  <category term="DISABLED" scheme="fedora-types:checksumType" label="xsd:string"></category>
  <category term="none" scheme="fedora-types:checksum" label="xsd:string"></category>
  <category term="Modified by Islandora API." scheme="fedora-types:logMessage" label="xsd:string"></category>
  <category term="false" scheme="fedora-types:force" label="xsd:boolean"></category>
  <summary type="text">uofm:highResImage</summary>
  <content type="text">2010-08-08T15:57:08.657Z</content>
  <category term="3.3" scheme="info:fedora/fedora-system:def/view#version"></category>
  <category term="info:fedora/fedora-system:ATOM-APIM-1.0" scheme="http://www.fedora.info/definitions/1/0/types/formatURI"></category>
</entry>';

$con->send("/queue/fedora.apim.update", $msg);

#echo "Sent message with body 'test'\n";
// subscribe to the queue
#$con->subscribe("/topic/fedora.apim.update");
// 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 "Failed to receive a message\n";
/**
 * Hook to send transaction information to ActiveMQ server
 * TODO: Seriously. Parameterize sendStomp. I hated this when there were only 
 * two of them, and now I've made another one.
 * THE ONLY THING this does differently, is use a different queue, and set the 
 * correlation-id if one is set in the transaction array. 
 * @global string $wgStompServer ActiveMQ server name. 
 * @global string $wgLimboStompQueueName Name of the destination queue for 
 * 'limbo' transactions. 
 * @param array $transaction Key-value array of staged and ready donation data. 
 * @return bool Just returns true all the time. Presumably an indication that 
 * nothing exploded big enough to kill the whole thing.
 */
function sendLimboSTOMP($transaction)
{
    global $wgStompServer, $wgLimboStompQueueName, $wgCCLimboStompQueueName;
    if ($transaction['payment_method'] === 'cc') {
        $queueName = isset($wgCCLimboStompQueueName) ? $wgCCLimboStompQueueName : 'cc-limbo';
    } else {
        $queueName = isset($wgLimboStompQueueName) ? $wgLimboStompQueueName : 'limbo';
    }
    // include a library
    require_once "Stomp.php";
    $properties = array('persistent' => 'true', 'correlation-id' => $transaction['correlation-id'], 'payment_method' => $transaction['payment_method']);
    if (array_key_exists('antimessage', $transaction)) {
        $message = '';
        $properties['antimessage'] = 'true';
    } else {
        $message = json_encode(createQueueMessage($transaction));
    }
    // make a connection
    $con = new Stomp($wgStompServer);
    // connect
    $con->connect();
    // send a message to the queue
    $result = $con->send("/queue/{$queueName}", $message, $properties);
    if (!$result) {
        wfDebugLog('activemq_stomp', 'Send to Q failed for this message: ' . $message);
    }
    $con->disconnect();
    return true;
}
Example #20
0
 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);
     }
 }
<?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");
Example #22
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() . " -"));
	       }
       }
Example #23
-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();
 }