Can't connect to RabbitMQ on Amazon MQ - php

I created an Amazon MQ broker:
Select broker engine: RabbitMQ 3.8.6
Single-instance broker
Network and security: Public access
VPC and subnets: Use the default VPC and subnet(s)
I have tried two libraries: from RabbitMQ manual and Enqueue\AmqpExt
Either of them cannot connect to Amazon (with docker container all works fine. But I want to try AMAZON MQ.
I used code below:
use Enqueue\AmqpExt\AmqpConnectionFactory;
use PhpAmqpLib\Connection\AMQPSSLConnection;
$connectionFactory = new AmqpConnectionFactory([
'host' => 'b-da219bXXXXXXXXXXXX86a.mq.us-east-1.amazonaws.com',
'port' => 5671,
'vhost' => '/',
'user' => 'xxxx',
'pass' => 'xxxx', // I can login with this to rabbit admin panel
'persisted' => false,
'ssl_on' => false,
'ssl_verify' => false,
]);
$c = $connectionFactory->createContext();
$queue = $c->createQueue('emails');
$c->declareQueue($queue);
Result:
Library error: connection closed unexpectedly - Potential login failure.
With 'ssl_on' => true the same error.
I don't know can it be happen because I didn't provide ssl cert to amazon.
If so, how to fix it?

I've had success with php-amqplib, and I am actually not using the newest version (I am on v2.12.3). I can connect using this:
$connection = new AMQPSSLConnection($host, $port, $user, $pass, $vhost, ['verify_peer_name' => false], [], 'ssl');
I found that I had to set 'verify_peer_name' => false, or else I just got a unable to connect to ssl://localhost:5671 (Unknown error) error, but I was also port-forwarding through localhost.

Amazon MQ broker (RabbitMQ specifically) is using SSL by default (you can notice that connection string starts with amqps, not amqp
In your case, you should set to true ssl_on and ssl_verify options

Answered by #Eugene K in a sub-comment:
You need to add the DSN to the SSLOptions array, and you need to use a AMQPSSLConnection instead of an AMQPStreamConnection
$this->connection = new AMQPSSLConnection(
'myhost.mq.eu-west-1.amazonaws.com',
'5671',
'username',
'xxx',
'/',
[
'dsn' => 'amqps:'
]
);

I see you installed amqp-ext and using it's ConnectionFactory
use Enqueue\AmqpExt\AmqpConnectionFactory; but
If you are using php-enqueue and want to connect to AWS AMQ RabbitMQ you should install and use enqueue/amqp-lib instead of enqueue/amqp-ext
and connection details
use Enqueue\AmqpLib\AmqpConnectionFactory;
new AmqpConnectionFactory([
'host' => env('RABBITMQ_HOST'),
'port' => env('RABBITMQ_PORT', 5672),
'vhost' => env('RABBITMQ_DEFAULT_VHOST'),
'user' => env('RABBITMQ_USERNAME'),
'pass' => env('RABBITMQ_PASSWORD'),
'persisted' => false,
'ssl_on' => true,
'ssl_verify' => true,
]);

Related

problem accessing soap web service's production environment

I hope this question won't be marked as duplicate as I read many related questions and answers on the site: although I tried most of the suggestions out there I still couldn't resolve my problem.
My codebase : (I left comments on purpose to give an idea of what I have been trying so far, based on my browsing)
try {
$opts = array(
//~mrossw 'http' => array(
//~mrossw 'user_agent' => 'PHPSoapClient'
//~mrossw ),
//~mrossw 'socket' => array('bindto' => '158.69.189.149')
'socket' => array('bindto' => '127.0.0.1')
//~mrossw ,
//~mrossw 'ssl' => [
//~mrossw 'verify_peer' => true,
//~mrossw 'verify_peer_name' => true,
//~mrossw 'allow_self_signed' => true
//~mrossw ]
);
$context = stream_context_create($opts);
$client = new SoapClient("https://ws_provider_hostname:xxxx/foo/bar/blah/Operaciones/OpFooBarBlahReqABCS?wsdl",
//~mrossw $client = new SoapClient($doc_root.'OpCotizadorVehiculoExtReqABCS.xml',
array(
'location' => "https://ws_provider_hostname:xxxx/foo/bar/blah/Operaciones/OpFooBarBlahReqABCS?wsdl",
'uri' => "https://ws_provider_hostname:xxxx/foo/bar/blah/Operaciones",
// Stuff for development.
'trace' => 1,
'exceptions' => true,
'keep_alive' => true,
'connection_timeout' => 120,
'stream_context' => $context,
'cache_wsdl' => WSDL_CACHE_NONE,
'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP | SOAP_COMPRESSION_DEFLATE,
//~mrossw 'local_cert' => $certRequest_param['sslcertfile'],
//~mrossw 'login'=>'username',
//~mrossw 'password' => 'password'
)
);
} catch (Exception $e) {
echo \"<h2>Exception Error!</h2>\";
echo $e->getMessage();
// print_r($e);
}
The WS provider has an dev environment on port xxxx and a prod env on port yyyy. Hostname and path request are the same.
SoapClient instanciation and operation call work perfect in dev env.
When i change the port to fetch against prod env I get the following error:
SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://ws_provider_hostname:xxxx/foo/bar/blah/Operaciones/OpFooBarBlahReqABCS?wsdl' : failed to load external entity "https://ws_provider_hostname:xxxx/foo/bar/blah/Operaciones/OpFooBarBlahReqABCS?wsdl"
Provider says my public web server's IP is correctly set as allowed in their firewall. It looks right because when I tried to run the code from a different server with different IP and it fails with the same error in both dev and prod env.
When I run that code from a server inside a private network, it works in both
environment ! I don't know much about security, but this sounds to me like a security breach. I mention it here though, in case it can give a clue. I guess this is because this server has a private ip and the provider's firewall don't filter it.
When I go to https://ws_provider_hostname:xxxx/foo/bar/blah/Operaciones/OpFooBarBlahReqABCS?wsdl in my PC browser i get the correct wsdl's xml.
Do you have an idea of what can prevent the code to work form my public web server ?
Or maybe what else can I check ?
For example I couldn't find a way to check the ws server's http response code from outside my browser.
I could neither get a curl request form bash to return the wsdl xml, but that should be another question maybe.
Also let me know if i can provide any other relevant test or data.

PHP Solr connection issue

I have PHP-Solr extension version 1.0.3-alpha installed on my server. I'm initializing the connection using:
$options = array(
'hostname' => 'hostname',
'login' => '',
'password' => '',
'port' => '',
'path' => 'solr/core1');
$client = new SolrClient($options);
It returns the following object:
class SolrClient#17 (1) { private $_hashtable_index => int(13444) }
But whenever I try to run a query like:
$qryArray = 'key_id:123456';
$client->deleteByQuery($qryArray);
It throws an exception as follows:
Solr HTTP Error 7: 'Couldn't connect to server
Can anyone help me to find what would causing this issue?
I have tried var_dump($client->getDebug());, but it returns NULL.

Dokku deployed Silex can't find PdoServiceProvider

I have a project done with Silex, and I was using herrera-io/silex-pdo as the PDO provider, but I faced random crashes with socket errors (I connect to the DB via socket), since that lib is abandoned, I changed to csanquer/pdo-service-provider, and it works just fine on my localhost server, but when I deploy to remote, I get the following error:
PHP Fatal error: Class 'Csanquer\Silex\PdoServiceProvider\Provider\PdoServiceProvider' not found in /app/web/index.php on line 52
Here is the code around the line 52:
use Csanquer\Silex\PdoServiceProvider\Provider\PdoServiceProvider;
$app->register(
// you can customize services and options prefix with the provider first argument (default = 'pdo')
new PdoServiceProvider('pdo'), // Line 52
array(
'pdo.server' => array(
// PDO driver to use among : mysql, pgsql , oracle, mssql, sqlite, dblib
'driver' => 'mysql',
'host' => 'unix_socket=/app/mysqld.sock',
'dbname' => 'db_beta',
'port' => 3306,
'user' => 'user',
'password' => 'pass',
),
// optional PDO attributes used in PDO constructor 4th argument driver_options
// some PDO attributes can be used only as PDO driver_options
// see http://www.php.net/manual/fr/pdo.construct.php
'pdo.options' => array(
\PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'UTF8'"
),
// optional PDO attributes set with PDO::setAttribute
// see http://www.php.net/manual/fr/pdo.setattribute.php
'pdo.attributes' => array(
\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
),
)
);
Thanks in advance for any help, or any clue of what may be going wrong!
Turns out the problem was with the use instructions. To fix, simply change:
use Csanquer\Silex\PdoServiceProvider\Provider\PdoServiceProvider;
To:
use Csanquer\Silex\PdoServiceProvider\Provider\PDOServiceProvider;
And:
new PdoServiceProvider('pdo') To: new PDOServiceProvider('pdo')
Now it works!

ZF2 Zend\Paginator\Adapter\DbSelect on DB2 i Series

Im creating a Zend APIgility application REST service and having a problem with my fetchAll Mapper function.
I'm connecting to an IBM DB2 database running on an i Series server (AS/400) via DB2 Connect on a Windows Application Server.
My Connection is is made in my local.php as such:
return array(
'db' => array(
'driver' => 'IbmDb2',
'database' => $database,
'username' => $user,
'password' => $password,
'hostname' => $host,
'port' => $port,
'driver_options' => array(
'i5_naming' => DB2_I5_NAMING_ON,
'i5_lib' => 'LIBWEB',
),
),
);
The fetchAll() function in my Mapper class is:
public function fetchAll()
{
$select = new Select('WBRESOURCE');
$paginatorAdapter = new DbSelect($select, $this->adapter);
$collection = new ResourcesCollection($paginatorAdapter);
return $collection;
}
When I hit the DbSelect, ZF2 throws the following DB2 Connect error:
"[IBM][CLI Driver][AS] SQL0204N \"*LIBL.WBRESOURCE\" is an undefined name. SQLSTATE=42704"
Im not sure why its using *LIBL (user defined library list), since I defined the library (SCHEMA) to use as LIBWEB in my connection option.
Thanks in advance!
Rob
Try changing this section:
'driver_options' => array(
'i5_naming' => DB2_I5_NAMING_ON,
'i5_lib' => 'LIBWEB',
Change to":
'driver_options' => array(
'i5_naming' => DB2_I5_NAMING_OFF, <=== change
'i5_lib' => 'LIBWEB',
By using DB2_I5_NAMING_OFF, you should get SQL naming mode. The use of DB2 i5 naming mode will result in things like reliance on a job's library list.
See PHP: db2-connect for some info on the parameter.

unable to connect to Google Cloud Connection Server

I'm trying to open a XMPP connection between my server and the Google Cloud Connection Server (CCS), but it doesn´t work. I´m programming with PHP and using the JAXL library. Here is my code:
<?php
include_once 'jaxl.php';
$client = new JAXL(array(
'jid'=>'<my_sender_ID>#gcm.googleapis.com',
'pass'=>'my_API_key',
'auth_type'=>'PLAIN',
'host' => 'gcm.googleapis.com',
'port' => '5235',
'force_tls' => true
));
$client->start();
echo "done";
?>
And then I get this error:
unable to connect tcp://gcm.googleapis.com:5235 with error no: 110, error str: Connection timed out
what am I doing wrong?
You should connect to gcm.googleapis.com by ssl, not http or tcp.
I fixed this by modifying jaxl.php from:
public function get_socket_path() {
return ($this->cfg['port'] == 5223 ? "ssl" : "tcp")."://".$this->cfg['host'].":".$this->cfg['port'];
}
to:
public function get_socket_path() {
return ($this->cfg['port'] == 5223 || $this->cfg['ssl'] == true ? "ssl" : "tcp")."://".$this->cfg['host'].":".$this->cfg['port'];
}
After that you can initialize the client with:
$client = new JAXL(array(
'jid' => '<your-API-key>#gcm.googleapis.com',
'pass' => '<your-API-key>',
'host' => 'gcm.googleapis.com',
'port' => 5235,
'force_tls' => true,
'auth_type' => 'PLAIN',
'strict' => FALSE,
'ssl' => TRUE
));
Also, when you initialize the client, use
'log_level' => JAXL_DEBUG
That will allow you to see everything that's sending or being received. In my case, I figured out that my project has not yet been whitelisted - I forgot to register it on https://services.google.com/fb/forms/gcm/
jaxl_socket_client:189 - 2013-10-04 08:11:58 - <failure xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><temporary-auth-failure/><text xmlns="urn:ietf:params:xml:ns:xmpp-stanzas">Project 1012343798740 not whitelisted.</text></failure>
Perhaps you should change the host to http://gcm.googleapis.com. Your error says "unable to connect tcp://gcm.googleapis.com:5235".
GCM Cloud Connection Server (CCS) is an XMPP endpoint, running on http://gcm.googleapis.com port 5235.

Categories