Publish to Azure Service Bus over http behind proxy

被刻印的时光 ゝ 提交于 2019-12-20 02:09:20

问题


I used Azure ServiceBus API to publish onto Service Bus. The sb protocol does not work behind the firewall. Hence I set ServiceBusEnvironment.SystemConnectivity.Mode to ConnectivityMode.Http. This was working as long as I was directly connected to the internet. This wouldnt work in my office, even after configuring the http proxy. Is there an issue with the ServiceBus API? Appreciate your help on this.

Below is the piece of code that I used....

    public static void Initialize()
    {
        // Using Http to be friendly with outbound firewalls
        ServiceBusEnvironment.SystemConnectivity.Mode =
            ConnectivityMode.Http;

        //InitializeQueue();
    }


    // The name of your queue
    public const string QueueName = "ordersqueue";

    public static NamespaceManager CreateNamespaceManager()
    {
        // Create the namespace manager which gives you access to
        // management operations
        var uri = ServiceBusEnvironment.CreateServiceUri(
            "sb", Namespace, String.Empty);
        var tP = TokenProvider.CreateSharedSecretTokenProvider(
            IssuerName, IssuerKey);
        return new NamespaceManager(uri, tP);
    }

    private static void InitializeQueue()
    {
        // Create the namespace manager which gives you access to 
        // management operations
        var namespaceManager = CreateNamespaceManager();

        // Create the queue if it does not exist already
        if (!namespaceManager.QueueExists(QueueName))
        {
            namespaceManager.CreateQueue(QueueName);
        }

        // Get a client to the queue
        var messagingFactory = MessagingFactory.Create(
            namespaceManager.Address,
            namespaceManager.Settings.TokenProvider);
        OrdersQueueClient = messagingFactory.CreateQueueClient(
            QueueName);
    }

Below is the stack trace I get................................ ...............................................................

Microsoft.ServiceBus.Messaging.MessagingCommunicationException was unhandled
  Message=Unable to connect to ServiceBus using HTTP connectivity mode
  Source=Microsoft.ServiceBus
  IsTransient=true
  StackTrace:
       at Microsoft.ServiceBus.Messaging.Sbmp.SbmpMessageSender.EndSendCommand(IAsyncResult result)
       at Microsoft.ServiceBus.Messaging.Sbmp.SbmpMessageSender.OnEndSend(IAsyncResult result)
       at Microsoft.ServiceBus.Messaging.Sbmp.SbmpMessageSender.OnSend(TrackingContext trackingContext, IEnumerable`1 messages, TimeSpan timeout)
       at Microsoft.ServiceBus.Messaging.MessageSender.Send(TrackingContext trackingContext, IEnumerable`1 messages, TimeSpan timeout)
       at Microsoft.ServiceBus.Messaging.MessageSender.Send(BrokeredMessage message)
       at Microsoft.ServiceBus.Messaging.QueueClient.Send(BrokeredMessage message)
       at AzureServiceBusPublisher.QueueConnector.send(String arg) in C:\Users\prasanh\Documents\Visual Studio 2010\Projects\AzureServiceBusPublisher\AzureServiceBusPublisher\QueueConnector.cs:line 72
       at AzureServiceBusPublisher.Program.sendMessagesToQueue() in C:\Users\prasanh\Documents\Visual Studio 2010\Projects\AzureServiceBusPublisher\AzureServiceBusPublisher\Program.cs:line 23
       at AzureServiceBusPublisher.Program.Main(String[] args) in C:\Users\prasanh\Documents\Visual Studio 2010\Projects\AzureServiceBusPublisher\AzureServiceBusPublisher\Program.cs:line 13
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: System.ServiceModel.CommunicationException
       Message=Unable to connect to ServiceBus using HTTP connectivity mode
       Source=Microsoft.ServiceBus
       StackTrace:
         Server stack trace: 
            at Microsoft.ServiceBus.WebStream..ctor(Uri factoryEndpointUri, String webSocketRole)
            at Microsoft.ServiceBus.WebSocketConnection..ctor(Uri factoryEndpointUri, String webSocketRole, Int32 asyncReadBufferSize)
            at Microsoft.ServiceBus.WebSocketOnewayConnectionInitiator.Connect(Uri uri, TimeSpan timeout)
            at Microsoft.ServiceBus.WebSocketOnewayConnectionInitiator.BeginConnect(Uri uri, TimeSpan timeout, AsyncCallback callback, Object state)
            at Microsoft.ServiceBus.Channels.BufferedConnectionInitiator.BeginConnect(Uri uri, TimeSpan timeout, AsyncCallback callback, Object state)
            at Microsoft.ServiceBus.Channels.ConnectionPoolHelper.EstablishConnectionAsyncResult.OpenUsingNewConnection()
            at Microsoft.ServiceBus.Channels.ConnectionPoolHelper.EstablishConnectionAsyncResult.Begin()
            at Microsoft.ServiceBus.Channels.ConnectionPoolHelper.EstablishConnectionAsyncResult..ctor(ConnectionPoolHelper parent, TimeSpan timeout, AsyncCallback callback, Object state)
            at Microsoft.ServiceBus.Channels.ConnectionPoolHelper.BeginEstablishConnection(TimeSpan timeout, AsyncCallback callback, Object state)
            at Microsoft.ServiceBus.Channels.ClientFramingDuplexSessionChannel.OpenAsyncResult..ctor(ClientFramingDuplexSessionChannel duplexChannel, TimeSpan timeout, AsyncCallback callback, Object state)
            at Microsoft.ServiceBus.Channels.ClientFramingDuplexSessionChannel.OnBeginOpen(TimeSpan timeout, AsyncCallback callback, Object state)
            at Microsoft.ServiceBus.Channels.CommunicationObject.OpenAsyncResult..ctor(CommunicationObject communicationObject, TimeSpan timeout, AsyncCallback callback, Object state)
            at Microsoft.ServiceBus.Channels.CommunicationObject.BeginOpen(TimeSpan timeout, AsyncCallback callback, Object state)
            at Microsoft.ServiceBus.Channels.LayeredChannel`1.OnBeginOpen(TimeSpan timeout, AsyncCallback callback, Object state)
            at Microsoft.ServiceBus.Channels.CommunicationObject.OpenAsyncResult..ctor(CommunicationObject communicationObject, TimeSpan timeout, AsyncCallback callback, Object state)
            at Microsoft.ServiceBus.Channels.CommunicationObject.BeginOpen(TimeSpan timeout, AsyncCallback callback, Object state)
            at Microsoft.ServiceBus.Messaging.Sbmp.DuplexRequestBindingElement.DuplexRequestSessionChannel.OnBeginOpen(TimeSpan timeout, AsyncCallback callback, Object state)
            at System.ServiceModel.Channels.CommunicationObject.OpenAsyncResult.InvokeOpen()
            at System.ServiceModel.Channels.CommunicationObject.OpenAsyncResult..ctor(CommunicationObject communicationObject, TimeSpan timeout, AsyncCallback callback, Object state)
            at System.ServiceModel.Channels.CommunicationObject.BeginOpen(TimeSpan timeout, AsyncCallback callback, Object state)
            at Microsoft.ServiceBus.Messaging.Channels.SharedChannel`1.GetInstanceAsyncResult.<GetAsyncSteps>b__3(GetInstanceAsyncResult thisPtr, TimeSpan t, AsyncCallback c, Object s)
            at Microsoft.ServiceBus.Messaging.IteratorAsyncResult`1.EnumerateSteps(CurrentThreadType state)
            at Microsoft.ServiceBus.Messaging.IteratorAsyncResult`1.Start()
         Exception rethrown at [0]: 
            at Microsoft.ServiceBus.Common.AsyncResult.End[TAsyncResult](IAsyncResult result)
            at Microsoft.ServiceBus.Messaging.IteratorAsyncResult`1.End(IAsyncResult asyncResult)
            at Microsoft.ServiceBus.Messaging.Channels.SharedChannel`1.OnEndCreateInstance(IAsyncResult asyncResult)
            at Microsoft.ServiceBus.Messaging.SingletonManager`1.EndGetInstance(IAsyncResult asyncResult)
            at Microsoft.ServiceBus.Messaging.Channels.ReconnectBindingElement.ReconnectChannelFactory`1.RequestSessionChannel.RequestAsyncResult.<GetAsyncSteps>b__f(RequestAsyncResult thisPtr, IAsyncResult r)
            at Microsoft.ServiceBus.Messaging.IteratorAsyncResult`1.EnumerateSteps(CurrentThreadType state)
         Exception rethrown at [1]: 
            at Microsoft.ServiceBus.Common.AsyncResult.End[TAsyncResult](IAsyncResult result)
            at Microsoft.ServiceBus.Messaging.IteratorAsyncResult`1.End(IAsyncResult asyncResult)
            at Microsoft.ServiceBus.Messaging.Channels.ReconnectBindingElement.ReconnectChannelFactory`1.RequestSessionChannel.EndRequest(IAsyncResult result)
            at Microsoft.ServiceBus.Messaging.Sbmp.SbmpTransactionalAsyncResult`1.<GetAsyncSteps>b__44(TIteratorAsyncResult thisPtr, IAsyncResult a)
            at Microsoft.ServiceBus.Messaging.IteratorAsyncResult`1.EnumerateSteps(CurrentThreadType state)
         Exception rethrown at [2]: 
            at Microsoft.ServiceBus.Common.AsyncResult.End[TAsyncResult](IAsyncResult result)
            at Microsoft.ServiceBus.Messaging.IteratorAsyncResult`1.End(IAsyncResult asyncResult)
            at Microsoft.ServiceBus.Messaging.Sbmp.SbmpMessageSender.EndSendCommand(IAsyncResult result)
       InnerException: System.ServiceModel.CommunicationException
            Message=Unable to connect downstream
            Source=Microsoft.ServiceBus
            StackTrace:
                 at Microsoft.ServiceBus.WebStream.CreateDownStreamRequest(Uri endpointLocation)
                 at Microsoft.ServiceBus.WebStream.StartSession(Uri readEndpoint, Uri writeEndpoint)
                 at Microsoft.ServiceBus.WebStream..ctor(Uri factoryEndpointUri, String webSocketRole)
            InnerException: System.Net.WebException
                 Message=The remote server returned an error: (403) Forbidden.
                 Source=System
                 StackTrace:
                      at System.Net.HttpWebRequest.GetResponse()
                      at Microsoft.ServiceBus.WebStream.CreateDownStreamRequest(Uri endpointLocation)
                 InnerException: 

回答1:


What is the detailed exception you get?

In my experience, too many proxies do not support HTTP 1.1 by their default configuration. HTTP 1.1 is necessary for Service Bus to work properly.

Other than this I suggest you to check this guide to troubleshoot connectivity to Service Bus




回答2:


Microsoft has released new service bus API this week. See the links below http://msdn.microsoft.com/en-us/library/windowsazure/hh667331.aspx#New_SB I have tested this issue in service bus 1.8. Still the same error. can anyone please guide me whether microsoft has fixed this issue ?




回答3:


I'm an SDE on the Windows Azure Service Bus team. Please attempt the guide posted.

Also be aware that as of SDK 1.7, Service Bus Messaging only works with HTTP 1.1 proxies that support POST chunking. We are working on a long-term solution to this and the upcoming SDK 1.8 allows Service Bus Relay to work on these proxies and also over HTTP 1.0 proxies by using HTTPS rather than POST chunking.

We are also aware that certain Cisco proxies (and perhaps others) require name addresses for any IP address connection that is attempted. We are working on a long term solution to this.



来源:https://stackoverflow.com/questions/12281570/publish-to-azure-service-bus-over-http-behind-proxy

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!