【问题标题】:Azure Service Bus in Xamarin FormsXamarin Forms 中的 Azure 服务总线
【发布时间】:2020-05-25 22:07:43
【问题描述】:

我正在尝试使用 Xamarin 表单订阅 Azure 服务总线队列。 (老实说,我根本不确定是否可以这样做。)

我可以使用简单的控制台应用程序从队列中接收消息,而不会出现任何问题。但是,当我将相同的代码移动到 Xamarin 时,它会在两种不同的情况下失败。

很少,它工作正常,我收到消息(虽然在 1-2 分钟后),但是当它尝试在这一行完成消息时给出Microsoft.Azure.ServiceBus.ServiceBusTimeoutException: 'The operation did not complete within the allocated time 00:00:59.9923240 for object dispose.' 错误await queueClient.CompleteAsync(message.SystemProperties.LockToken);

其他时候,它甚至没有收到任何消息就失败了,并给出了这个错误The operation did not complete within the allocated time 00:00:56.2875140 for object session5.

这是我的代码:

    public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
    {
        static IQueueClient queueClient;

        protected override void OnCreate(Bundle savedInstanceState)
        {
            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource = Resource.Layout.Toolbar;

            base.OnCreate(savedInstanceState);

            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
            LoadApplication(new App());

            var serviceBusConnectionString = "myConnectionString";
            var queueName = "myqueueName";

            var messageHandlerOptions = new MessageHandlerOptions(ExceptionReceivedHandler);
            messageHandlerOptions.AutoComplete = false;
            messageHandlerOptions.MaxConcurrentCalls = 1;

            queueClient = new QueueClient(serviceBusConnectionString, queueName);
            queueClient.RegisterMessageHandler(ProcessMessageAsync, messageHandlerOptions);
        }

        private static async Task ProcessMessageAsync(Message message, CancellationToken token)
        {
            var result = Encoding.UTF8.GetString(message.Body);
            await queueClient.CompleteAsync(message.SystemProperties.LockToken);
        }
}

问题:

  1. 是否可以正确订阅 Azure 服务总线队列 完全使用 Xamarin 吗?
  2. 我在这里遗漏了什么吗?
  3. 我还有其他方法可以将 JSON 对象从服务总线发送到手机吗?

【问题讨论】:

  • 有趣的是,我遇到了同样的问题,但发送到队列而不是接收。我说很有趣,因为它已经工作了大约 2 年,突然到 5 月左右它停止了工作,我现在遇到了和你一样的超时异常。我想知道是否有任何变化

标签: c# xamarin.forms azureservicebus azure-servicebus-queues


【解决方案1】:

在我的评论中,我确实发现在 Xamarin 应用程序中实现类似的订阅模式时,Signal R 工作得更好,并且实现起来非常容易和轻量级。这是主观的,但我确实发现连接的协商方法比直接连接到 Azure 服务总线端点更简洁

【讨论】:

    猜你喜欢
    • 2018-10-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-09
    • 2016-11-24
    • 2016-08-16
    • 1970-01-01
    相关资源
    最近更新 更多