public static function createConnectionUsingPHPAMQPLib(AMQPServerConfigurationInterface $config, $sslCAPath = null, $sslHost = null)
    {
        if($config->getSSL() === true) {
            $sslOptions = [
                'verify_peer' => true,
            ];

            if ($sslCAPath !== null) {
                $sslOptions['capath'] = $sslCAPath;
            }

            if ($sslHost !== null) {
                $sslOptions['CN_match'] = $sslHost;
            } elseif(!filter_var($config->getHost(), FILTER_VALIDATE_IP)) {
                $sslOptions['CN_match'] = $config->getHost();
            }

            $amqp = new AMQPSSLConnection(
                $config->getHost(),
                $config->getPort(),
                $config->getUsername(),
                $config->getPassword(),
                $config->getVHost(),
                $sslOptions,
                [
                    'connection_timeout' => $config->getConnectionTimeout(),
                ]
            );
        } else {
            $amqp = new AMQPSocketConnection(
                $config->getHost(),
                $config->getPort(),
                $config->getUsername(),
                $config->getPassword(),
                $config->getVHost(),
                false,
                'AMQPLAIN',
                null,
                'en_US',
                $config->getConnectionTimeout(),
                true
            );
        }

        register_shutdown_function(function() use ($amqp){
            if ($amqp->isConnected()) {
                try {
                    $amqp->close();
                } catch (Exception $ex) {
                }
            }
        });

        return $amqp;
    }