1
votes

My Azure function doesn't trigger when called by my Android app.

Test:

The following test successfully triggers the Azure function via a ServiceBusTrigger:

[<Fact>]
let ``Publish message assigned to servicebus topic``() =

    // Setup
    let connectionstring = ConfigurationManager.ConnectionStrings.["servicebus_testEnv"].ConnectionString

    // Test
    async {

        let client  = TopicClient(connectionstring, "Topic.courier-subscribed")
        let data    = "test_data"
        let message = Message(Encoding.UTF8.GetBytes(data))

        do! client.SendAsync(message) |> Async.AwaitTask
        do! client.CloseAsync()       |> Async.AwaitTask
    }

Issue:

However, when I plug the code into my Xamarin Android application, the Azure function never gets triggered.

Instead, I only observe the following error:

System.TimeoutException: 'The operation did not complete within the allocated time 00:00:49.9480520 for object session5.'

Xamarin.Android:

Here's the code in my Xamarin Android app:

let subscribe : Subscribe =
    fun request ->

        async {

            let body = {
                Courier   = request.Courier
                Location  = request.Location
                Timestamp = DateTime.Now
            }

            try
                let connectionstring = QueueTopic.Instance.ConnectionString
                let client  = TopicClient(connectionstring, "Topic.courier-subscribed")
                let json    = JsonConvert.SerializeObject(body)
                let message = Message(Encoding.UTF8.GetBytes(json))

                do! client.SendAsync(message) |> Async.AwaitTask
                do! client.CloseAsync()       |> Async.AwaitTask

                return Ok body
         }

Azure Function (ServiceBusTrigger):

public static class SubscribedFn
{
    [FunctionName(nameof(SubscribedFn))]
    public static async Task Run([ServiceBusTrigger("Topic.courier-subscribed", "Subscription.all-messages", Connection= "ServiceBusConnectionKey")]
                                  string json, ILogger log)
    {
        ... // NEVER INVOKED
    }

NOTE:

  1. I have verified the connection string to be identical with my automated test.

  2. The automated test triggers the Azure function via ServiceBusTrigger every time.

  3. I have verified that I'm sending JSON as the payload in both clients

1
Any news on this? Did my answer help you? - Alex AIT
Your answer helped me. I now get several exceptions even on my mobile client regarding task being cancelled. However, regardless of the exceptions thrown, the Azure function is now being triggered from my app. Thanks. - Scott Nimrod

1 Answers

2
votes

You probably have some network issue on your device. ServiceBus uses the AMQP protocol by default. You need ports 5671 and 5672 open on outgoing connections for most cases.

For your Xamarin application, I would suggest appending ;TransportType=AmqpWebSockets to your connection string and see if that helps.

Endpoint=sb://xxxx.servicebus.windows.net/;SharedAccessKeyName=xxxx;SharedAccessKey=xxxxx;TransportType=AmqpWebSockets