期望: 使用带有EventHubTrigger-CSharp模板的函数应用程序在新事件进入时运行。
实施 使用https://azure.microsoft.com/en-us/documentation/articles/functions-bindings-event-hubs/
中的基本示例结果: 解释的方法:
public static void Run(string myEventHubMessage, TraceWriter log)
{
log.Info($"C# Event Hub trigger function processed a message: {myEventHubMessage}");
}
确实提供了第一个'在事件队列中而不是当前队列。
其他 - 我添加了一个consumerGroup(所以没有从$ Default读取) - 根据此博客:http://www.yourcloudbuddy.com/2016/04/azure-functions-and-event-hubs.html'目前无法将其配置为启动特定的偏移量。
问题: 如何在我的功能应用程序中收到集线器上的最新活动?
更多信息: 我需要将新信号从事件中心转发到外部mqtt api(到目前为止工作)。可能我需要另一种方法吗?
任何输入的Thanx,Ramin
答案 0 :(得分:2)
@Ramin,我试图重新创建一个类似于你的场景,但无法重现这个问题。以下是步骤:
设置事件中心触发功能(截至2016年10月27日使用最新版本0.7)
将一个简单的控制台应用程序发件人设置到我的事件中心,该事件中心发送10条带有时间戳和消息ID的消息。每封邮件发送<6分钟。这是我的控制台应用程序的输出,用于记录已发送的消息,
Sent message: Timestamp: 10/27/2016 2:27:06 PM, MessageId: 1 Sent message: Timestamp: 10/27/2016 2:33:07 PM, MessageId: 2 Sent message: Timestamp: 10/27/2016 2:39:07 PM, MessageId: 3 Sent message: Timestamp: 10/27/2016 2:45:07 PM, MessageId: 4 Sent message: Timestamp: 10/27/2016 2:51:08 PM, MessageId: 5 Sent message: Timestamp: 10/27/2016 2:57:08 PM, MessageId: 6 Sent message: Timestamp: 10/27/2016 3:03:08 PM, MessageId: 7 Sent message: Timestamp: 10/27/2016 3:09:08 PM, MessageId: 8 Sent message: Timestamp: 10/27/2016 3:15:08 PM, MessageId: 9 Sent message: Timestamp: 10/27/2016 3:21:08 PM, MessageId: 10 Stopped sending messages.
以下是我的功能
的日志条目2016-10-27T21:27:26.516 Function started (Id=d5ed0e23-2b0e-4e0b-a858-f1e497dcac8c)
2016-10-27T21:27:26.516 C# Event Hub trigger function processed a message: Timestamp: 10/27/2016 2:27:06 PM, MessageId: 1
2016-10-27T21:27:26.516 Function completed (Success, Id=d5ed0e23-2b0e-4e0b-a858-f1e497dcac8c)
2016-10-27T21:33:26.667 Function started (Id=9525a046-86fb-4499-9d4f-b0d0fd0d0829)
2016-10-27T21:33:26.667 C# Event Hub trigger function processed a message: Timestamp: 10/27/2016 2:33:07 PM, MessageId: 2
2016-10-27T21:33:26.667 Function completed (Success, Id=9525a046-86fb-4499-9d4f-b0d0fd0d0829)
2016-10-27T21:39:42.074 Function started (Id=e2d528c9-f1b9-41aa-9c38-669c57c8182a)
2016-10-27T21:39:42.074 C# Event Hub trigger function processed a message: Timestamp: 10/27/2016 2:39:07 PM, MessageId: 3
2016-10-27T21:39:42.074 Function completed (Success, Id=e2d528c9-f1b9-41aa-9c38-669c57c8182a)
2016-10-27T21:45:26.794 Function started (Id=ff5325af-5dab-48fb-95b1-8318fada3c8c)
2016-10-27T21:45:26.794 C# Event Hub trigger function processed a message: Timestamp: 10/27/2016 2:45:07 PM, MessageId: 4
2016-10-27T21:45:26.794 Function completed (Success, Id=ff5325af-5dab-48fb-95b1-8318fada3c8c)
2016-10-27T21:51:26.875 Function started (Id=01d3fbf9-b772-4076-8fbf-783dc16677a7)
2016-10-27T21:51:26.875 C# Event Hub trigger function processed a message: Timestamp: 10/27/2016 2:51:08 PM, MessageId: 5
2016-10-27T21:51:26.875 Function completed (Success, Id=01d3fbf9-b772-4076-8fbf-783dc16677a7)
2016-10-27T21:57:26.989 Function started (Id=443d96e6-af97-460a-9f70-9dbc2eaf2f37)
2016-10-27T21:57:26.989 C# Event Hub trigger function processed a message: Timestamp: 10/27/2016 2:57:08 PM, MessageId: 6
2016-10-27T21:57:26.989 Function completed (Success, Id=443d96e6-af97-460a-9f70-9dbc2eaf2f37)
2016-10-27T22:03:27.088 Function started (Id=9eefe03d-8e78-4119-a453-96655ea01824)
2016-10-27T22:03:27.088 C# Event Hub trigger function processed a message: Timestamp: 10/27/2016 3:03:08 PM, MessageId: 7
2016-10-27T22:03:27.088 Function completed (Success, Id=9eefe03d-8e78-4119-a453-96655ea01824)
2016-10-27T22:10:01.872 Function started (Id=34c9b277-059d-4839-9dce-aeb03afb2871)
2016-10-27T22:10:01.872 C# Event Hub trigger function processed a message: Timestamp: 10/27/2016 3:09:08 PM, MessageId: 8
2016-10-27T22:10:01.872 Function completed (Success, Id=34c9b277-059d-4839-9dce-aeb03afb2871)
2016-10-27T22:15:27.706 Function started (Id=50eda659-c68f-4e61-a942-32160668fd5c)
2016-10-27T22:15:27.706 C# Event Hub trigger function processed a message: Timestamp: 10/27/2016 3:15:08 PM, MessageId: 9
2016-10-27T22:15:27.706 Function completed (Success, Id=50eda659-c68f-4e61-a942-32160668fd5c)
2016-10-27T22:21:52.162 Function started (Id=fa8f8059-013f-42f9-8047-391d4e3fb4a3)
2016-10-27T22:21:52.162 C# Event Hub trigger function processed a message: Timestamp: 10/27/2016 3:21:08 PM, MessageId: 10
2016-10-27T22:21:52.162 Function completed (Success, Id=fa8f8059-013f-42f9-8047-391d4e3fb4a3)
如您所见,所有邮件都没有重复。你能否确认每次调用你的函数(你可以检查你的函数日志),它实际上是否成功运行完成了?
如果您看到以下消息,
Function completed (Success, Id=<some Guid>)
对于函数的每次调用,应该检查指向该执行的消息,并且您不应该在下次调用时再次处理消息。
但是,如果您没有看到该消息或看到错误消息,则函数运行失败,这将导致消息未被检查。当函数再次被触发时,如果您的函数从未成功处理该消息,它将从最后一个检查点(可能是第一个消息)中获取。
答案 1 :(得分:2)
现在有一种方法。
注意:要执行此操作,必须删除连接到功能应用程序的存储帐户中azure-webjobs-eventhub
中存储的使用者组数据。
我们现在可以使用Microsoft.Azure.Functions.Extensions
nuget包在Azure Functions中使用依赖项注入。
这为我们提供了一种方法,可通过执行以下操作来控制Azure Function App在何处开始处理事件中心:
using System;
using Microsoft.Azure.EventHubs;
using Microsoft.Azure.Functions.Extensions.DependencyInjection;
using Microsoft.Azure.WebJobs.EventHubs;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
[assembly: FunctionsStartup(typeof(EventHubOffsetTest.Startup))]
namespace EventHubOffsetTest
{
public class Startup : FunctionsStartup
{
public override void Configure(IFunctionsHostBuilder builder)
{
builder.Services.PostConfigure<EventHubOptions>(o => o.EventProcessorOptions.InitialOffsetProvider = GetInitialOffset);
}
private static EventPosition GetInitialOffset(string partitionId)
{
return EventPosition.FromEnd();
}
}
}
答案 2 :(得分:1)
EventHub侦听基于EventProcessorHost类(https://msdn.microsoft.com/en-us/library/azure/microsoft.servicebus.messaging.eventprocessorhost.aspx)并具有这些默认语义。 你是对的,你无法控制起始偏移量。它只是开始倾听和检查点。
我们还会在维基上跟踪其他信息:https://github.com/Azure/azure-webjobs-sdk/wiki/EventHub-support
提交功能请求