如何从azure队列消息(服务总线)获取数据

时间:2016-02-08 14:53:43

标签: azure

我需要从我的控制台应用程序从服务总线获取数据,而不是我的数据我有System.UnauthorizedAccessException错误401 我有2个静态只读字符串,我不知道如何使用 您可能需要以下一种或两种服务,具体取决于您需要的详细程度 -

- (void)initPlayer {

    [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient withOptions:0 error:nil];

    // some init logic
    // e.g:
    //
    // _playerItem = [AVPlayerItem playerItemWithAsset:[AVAsset assetWithURL:_URL]];
    // _player = [AVPlayer playerWithPlayerItem:_playerItem];
    // _playerLayer = [AVPlayerLayer playerLayerWithPlayer:_player];
    //
    // etc.

}

- (void)setMuted:(BOOL)muted {
    if (!muted) {
        [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategorySoloAmbient withOptions:0 error:nil];
    }

    self.player.muted = muted;
}

我刚进入app.config并使用正确的命名空间和密码

    //sample usage string briefingDetailsByIdURI = string.Format(Constants.BRIEFING_DETAILS_ID_URI, brfId);

    public static readonly string ID_URI = "https://trtrtrtr.servicebus.windows.net/trtrtr/trttrttr/{0}";



    //sample usage - string URI = string.Format(Constants.sdgsdgg, sgsgsg, sgsgsg);

    public static readonly string DETAIL_ID_URI = "https://trtrtrtr.servicebus.windows.net/trtrtr/trrtrttr/{0}/{1}";

之后我进入了我的控制台program.cs

Console.Title =“Receiver2”;

<appSettings>
<!-- Service Bus specific app setings for messaging connections -->
<add key="Microsoft.ServiceBus.ConnectionString"        value="Endpoint=sb://<namespace>.servicebus.windows.net/;
 SharedAccessKeyName=Root      stManageSharedAccessKey;SharedAccessKey=<paasword> />

1 个答案:

答案 0 :(得分:0)

这是我用来连接队列的方法

QueueClient _client;
        var connectionString = CloudConfigurationManager.GetSetting("Microsoft.ServiceBus.ConnectionString");
        var namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString);
        if (!namespaceManager.QueueExists(QueueName))
        {
            namespaceManager.CreateQueue(QueueName);
        }

        _client = QueueClient.CreateFromConnectionString(connectionString, QueueName);

而不是运行while循环。您可以像这样使用OnMessage():

_client.OnMessage(message =>
                {
                    try
                    {
                        //do logic
                    }
                    catch (Exception e)
                    {
                        message.Abandon();
                        throw new Exception(e.Message);
                    }
                });

确保Azure ServiceConfiguration中的连接字符串设置正确:

<?xml version="1.0" encoding="utf-8"?>
<ServiceConfiguration serviceName="App" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration" osFamily="4" osVersion="*" schemaVersion="2015-04.2.6">
  <Role name="App">
    <Instances count="1" />
    <ConfigurationSettings>
      <Setting name="Microsoft.ServiceBus.ConnectionString" value="THE CONNECTION STRING" />
    </ConfigurationSettings>
  </Role>
</ServiceConfiguration>