Azure / Azure-Functions

1.12k stars 199 forks source link

Can't receive data from Iot hub using azure functions #800

Open guylot opened 6 years ago

guylot commented 6 years ago

Hello,

I'm trying to create azure function which receive messages from Iot hub and I get error "Method not found" when I'm trying to create the receiver for Iot hub. When I'm running the same project using console application instead of azure function project It's working.

I'm running on visual studio 2017 15.7.1, azure functions and web jobs version 15.0.40424.0.

To simulate the problem this is the code simplified to generate the error (there are some connections and variables you need to apply):

Create azure function project V1 from visual studio

(Im having microsoft.NET.Sdk.Function (1.0.13) and WindowsAzure.ServiceBus(4.1.9) nuggets)

        [FunctionName("Function1")]
        public static void Run([TimerTrigger("0 */1 * * * *")]TimerInfo myTimer, TraceWriter log)
        {
            log.Info($"C# Timer trigger function executed at: {DateTime.Now}");

            ServiceBusConnectionStringBuilder connectionStringBuilder =
                new ServiceBusConnectionStringBuilder(IothubConnectionString) { TransportType = TransportType.Amqp };

            MessagingFactory messagingFactory = MessagingFactory.CreateFromConnectionString(connectionStringBuilder.ToString());
            eventHubClient = messagingFactory.CreateEventHubClient(IotHubD2CEndpoint);
            d2CPartitions = eventHubClient.GetRuntimeInformation().PartitionIds;

            List<Task> taskList = new List<Task>();

            foreach (string partition in d2CPartitions)
            {
                var eventHubReceiver = eventHubClient.GetConsumerGroup(ConsumerGroup).
                    CreateReceiver(partition, DateTime.Now.AddDays(-5));
            }
        }

The function will not run and the line causing the error is the CreateReceiver method.

Creating console application with same code will run successfully.

How can I make it work and receive messages from Iot hub?

Thanks.

marxxxx commented 6 years ago

why don't you use event hub trigger?

guylot commented 6 years ago

I want to read events from specific time until specific time, every function run to read only the messages from 2 days ago. I don't want to read new arrive messages

ColbyTresness commented 5 years ago

Sorry for the lack of response. I think the answer is that anything not possible in the EventHub trigger isn't possible in the IoTHub trigger, since they're essentially the same. So I'll leave this open to track improvements to the IoT Hub trigger.