如何天青的EventData.PartitionKey决定写信给哪个分区? [英] How does Azure's EventData.PartitionKey decide which partition to write to?

查看:289
本文介绍了如何天青的EventData.PartitionKey决定写信给哪个分区?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现一个事件枢纽Azure上。我已成功地建立生产者这消息发布到事件枢纽,以及其内容他们掀起了消费者。我的活动中心被划分为16个分区。在消费者方面,我遍历每个这些如下:

I am trying to implement an Event Hub in Azure. I have managed to create a Producer which publishes messages to the Event Hub, as well as a Consumer which reads them off. My Event Hub is divided up into 16 partitions. On the consumer side, I loop through each of these as follows:

var eventHub = NamespaceManager.CreateFromConnectionString(builder.ToString()).GetEventHub("de-analytics-events");

foreach (var partitionId in eventHub.PartitionIds)
{
     subscriberGroup.RegisterProcessor<EventProcessor>(new Lease
     {
         PartitionId = partitionId
     }, new EventProcessorCheckpointManager());

     Console.WriteLine("Processing: " + partitionId);
}

寻找在调试这些值表明,在16个分区的情况下的 eventHub.PartitionIds 范围从0到15。

不过,制片方,我都被允许指定是我的 EventData.PartitionKey ,这是一个字符串,但它并不直接对应于弦上在消费者方面。例如。如果我指定一个PartitionKey =7,也不一定写分区7。

However, on the producer side, all I was allowed to specify was my EventData.PartitionKey, which is a string, but which does not directly correspond to the strings on the consumer side. E.g. if I specified a PartitionKey = "7", it did not necessarily write to partition "7".

阅读了某排序散列参与表演,但我并不特别想猜测随机在16字符串散列数字0-15。所以,我想知道我怎么能确定哪个分区发布到?

Reading up shows that some sort of hashing is involved, but I don't particularly want to guess randomly at 16 strings that hash to the numbers 0-15. So I'm wondering how I can define which partition is published to?

有关补充参考,<一个href=\"http://alexandrebrisebois.word$p$pss.com/2014/07/18/getting-acquainted-with-azure-service-bus-event-hubs/\"相对=nofollow>这是我跟着让我简单的情况下工作的教程。

For added reference, this is the tutorial I followed to get my simplest case working.

推荐答案

你是正确的,散列用于转换分区键给定分区。这个问题我有话,只要散列算法均匀一致地分布事件,你为什么要真正关心哪个分区的消息被分配到?

You're correct, a hash is used to translate the partition key to a given partition. The question I have then, is as long as the hash algorithm distributes events evenly and consistently, why should you really care which partition the message is assigned to?

是的,你可能会说,你想知道的,所以你知道谁接收器会。但现实的情况是,像这样的紧耦合使得该解决方案固有的脆弱。你投注了让服务做它需要做的,以保持业务的健康,并意识到,一旦你得到使用给定分区键的消息,你很可能总是使用该密钥的消息。

Yes, you could argue that you want to know so you know who the receiver will be. But the reality is that tight coupling like this makes the solution inherently fragile. You're betting off letting the service do what it needs to do to keep traffic healthy and realize that once you get a message using a given partition key, you're very likely to always get messages using that key.

更大的挑战是要确保您使用的分区关键策略是指将有助于确保整个分区相当,甚至事件的分布(又名不给予1设备都是一样的分区键)。

The bigger challenge is to ensure that the partition key strategy you use is one that will help ensure a fairly even distribution of events across the partitions (aka don't give 10,000 devices all the same partition key).

这篇关于如何天青的EventData.PartitionKey决定写信给哪个分区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆