Skip to content
This repository has been archived by the owner on Nov 27, 2023. It is now read-only.

Connect to Azure Service Bus using connection settings from Azure Management Portal #726

Open
jameschristou opened this issue Dec 29, 2014 · 13 comments
Assignees
Labels

Comments

@jameschristou
Copy link

jameschristou commented Dec 29, 2014

I'm trying to connect to an Azure Service Bus Topic from PHP using the SDK for PHP and have had no luck getting past the connection string. I am using the connection string from the Azure Management Portal and it looks something like this Endpoint=sb://my-sb-namespace.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=blahblah=.

Here is my code:

set_include_path(get_include_path() . PATH_SEPARATOR . $_SERVER['WEBROOT_PATH'] . '\vendor\pear-pear.php.net\HTTP_Request2');
set_include_path(get_include_path() . PATH_SEPARATOR . $_SERVER['WEBROOT_PATH'] . '\vendor\pear-pear.php.net\Net_URL2');
set_include_path(get_include_path() . PATH_SEPARATOR . $_SERVER['WEBROOT_PATH'] . '\vendor\pear-pear.php.net\PEAR');

require_once( $_SERVER['WEBROOT_PATH'] . '\vendor\microsoft\windowsazure\windowsazure\WindowsAzure.php' );

use WindowsAzure\Common\ServicesBuilder;
use WindowsAzure\Common\ServiceException;
use WindowsAzure\ServiceBus\Models\BrokeredMessage;

$connectionString = 'Endpoint=sb://my-sb-namespace.servicebus.windows.net/;SharedSecretIssuer=RootManageSharedAccessKey;SharedSecretValue=blahblah=';
$serviceBusRestProxy = ServicesBuilder::getInstance()->createServiceBusService($connectionString);

try {
    // Create message.
    $message = new BrokeredMessage();
    $message->setBody('Post ' . $post_ID . ' updated');

    // Send message.
    $serviceBusRestProxy->sendTopicMessage("mytopicname", $message);
}
catch(ServiceException $e){
    $errorMsg = 'ErrorCode: ' . $e->getCode() . ' ErrorMessage: ' . $e->getMessage();
    fwrite(STDOUT, $errorMsg);
}

When I run this script I get the following error:

PHP Fatal error:  Uncaught HTTP_Request2_ConnectionException: Unable to connect to ssl://my-sb-namespace-sb.accesscontrol.windows.net:443. Error: php_network_getaddresses: getaddrinfo failed: No such host is known.  in D:\home\site\wwwroot\vendor\pear-pear.php.net\HTTP_Request2\HTTP\Request2\Adapter\Socket.php on line 325
#0 D:\home\site\wwwroot\vendor\pear-pear.php.net\HTTP_Request2\HTTP\Request2\Adapter\Socket.php(325): HTTP_Request2_SocketWrapper->__construct('ssl://my-sb-name...', 10, Array)
#1 D:\home\site\wwwroot\vendor\pear-pear.php.net\HTTP_Request2\HTTP\Request2\Adapter\Socket.php(128): HTTP_Request2_Adapter_Socket->connect()
#2 D:\home\site\wwwroot\vendor\pear-pear.php.net\HTTP_Request2\HTTP\Request2.php(939): HTTP_Request2_Adapter_Socket->sendRequest(Object(HTTP_Request2))
#3 D:\home\site\wwwroot\vendor\microsoft\windowsazure\WindowsAzure\Common\Internal\Http\HttpClient.php(262): HTTP_Request2->send()
#4 D:\home\site\wwwroot\vendor\microsoft\windowsazure\WindowsAzure\Common\Internal\RestProxy.php(141): WindowsAzu in D:\home\site\wwwroot\vendor\pear-pear.php.net\HTTP_Request2\HTTP\Request2\SocketWrapper.php on line 108

Any ideas?

@jameschristou
Copy link
Author

Got a workaround using ACS connection setting rather than the default SAS setting which you get from Azure Management Portal. I needed to delete my existing service bus namespace and then recreate it using powershell. Then I could get the ACS setting from Azure Management Portal. See the comment from @Bottle here Azure/azure-sdk-for-java#437 for details.

However it would be nice however if we could use SAS from the SDK since that is now the default within the Azure Management Portal.

@PiDiBi
Copy link
Member

PiDiBi commented Nov 11, 2015

Hi, it would be nice to rewirte ServiceBuilder.php to use SAS, I'm not able to create ACS namespace using powershell from my macbook

http://blogs.msdn.com/b/servicebus/archive/2014/09/03/change-to-azure-service-bus-portal-default-authentication-mechanism-for-service-bus-namespaces-now-sas.aspx

@yaqiyang yaqiyang added this to the Ice Box milestone Mar 21, 2016
@sergey-shandar sergey-shandar modified the milestones: Future Release, Ice Box Oct 31, 2016
@andrerav
Copy link

This is quite the showstopper for using this library. Is there anything I can do to help out with getting this implemented quickly?

@sergey-shandar sergey-shandar self-assigned this Feb 10, 2017
@sergey-shandar
Copy link
Contributor

We are working on ARM implementation of Azure SDK for PHP. However, if someone provides a PR, I'm happy to review it and release a new version of the SDK.

@blocksninja
Copy link

Does this mean that the error I'm having:
cURL error 6: Could not resolve host: ***-sb.accesscontrol.windows.net
Is related to this?

@Shaked
Copy link

Shaked commented Oct 2, 2017

@timbrand did you solve this issue?

@blocksninja
Copy link

@Shaked Actually, I stopped the implementation and went back to RabbitMQ.

@Shaked
Copy link

Shaked commented Oct 8, 2017

@timbrand Thanks for the reply. In case you still need it, I have it working here: https://github.com/Shaked/azure-sdk-for-php. I didn't do a pull request as the contribution document is way too long and I have no time to follow all the guidelines.

@sergey-shandar
Copy link
Contributor

@Shaked please, send a PR. I will have a look. I can also help you with the contribution document.

@smpilo
Copy link

smpilo commented Oct 23, 2017

@Shaked Do you think you can address the PR issues in the short term? :) We have business partners who we'd love to roll to a new version and use SAS instead of monkeying around with ACS.

@Shaked
Copy link

Shaked commented Oct 23, 2017

@smpilo AFAIU @sergey-shandar is on it. I will try to fix the comments that I saw in the pull request but I have no time to do the entire process.

In the meanwhile, you can require the package from my repository if you would like

@sergey-shandar
Copy link
Contributor

@smpilo and @Shaked the PR is still failing because the fix doesn't support PHP 5.6 and PHP 7.0. Could you provide a fix?

@ziodave
Copy link

ziodave commented Mar 21, 2022

Downgrading to 0.4 worked for me, not the best of the solutions I know ...

composer.json:

{
  "require": {
    "microsoft/windowsazure": "~0.4"
  }
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

9 participants