Created
February 27, 2019 05:31
-
-
Save deltastateonline/efc9ddfb811cba3f11614e149c90b5e9 to your computer and use it in GitHub Desktop.
Connecting to Stomp on AmazonMq Using stomp-php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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