Skip to content

Instantly share code, notes, and snippets.

@deltastateonline
Created February 27, 2019 05:31
Show Gist options
  • Save deltastateonline/efc9ddfb811cba3f11614e149c90b5e9 to your computer and use it in GitHub Desktop.
Save deltastateonline/efc9ddfb811cba3f11614e149c90b5e9 to your computer and use it in GitHub Desktop.
Connecting to Stomp on AmazonMq Using stomp-php
<?php
use Stomp\Client;
use Stomp\StatefulStomp;
use Stomp\Exception\StompException;
class Adjustit_activemqconnection {
var $connection = NULL;
function __construct()
{
$this->CI = & get_instance();
$this->CI->load->config("activemq");
$this->activemqConfigs = $this->CI->config->item('activemq');
}
public function getConnection(){
if(empty($this->connection)){
write_logs("LOG:: New Activemq Connection...");
$connectionString = sprintf('tls://%s:%d', $this->activemqConfigs["host"], $this->activemqConfigs["port"]);
$connection = new \Stomp\Network\Connection($connectionString, 1, [
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false
]
]);
$con = new Client($connection);
$con->setClientId("adj.producer.".time());
$con->setLogin( $this->activemqConfigs["username"], $this->activemqConfigs["password"]);
$this->connection = new StatefulStomp($con);
try{
$con->connect();
} catch (StompException $e) {
write_logs("ERROR:: Unable to connect to activemq server ".$this->activemqConfigs["host"] );
write_logs("ERROR:: Message: ".$e->getMessage() );
}
}
return $this->connection;
}
function __destruct() {
if($this->connection){
// $this->connection->close();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment