%3CLINGO-SUB%20id%3D%22lingo-sub-1629898%22%20slang%3D%22en-US%22%3EService%20Bus%20-%20duplicate%20detection%20for%20partitioned%20messaging%20entity%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1629898%22%20slang%3D%22en-US%22%3E%3CP%3E%3CFONT%20size%3D%225%22%3E%3CSTRONG%3EPre-requirements%3A%3C%2FSTRONG%3E%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3EBefore%20we%20start%2C%20please%20read%20these%20document%20about%20%3CSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fservice-bus-messaging%2Fduplicate-detection%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3EDuplicate%20Detection%3C%2FA%3E%3C%2FSPAN%3E%2C%20%3CSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fservice-bus-messaging%2Fservice-bus-partitioning%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3EPartitioned%20queues%20and%20topics%3C%2FA%3E%3C%2FSPAN%3E%20and%20%3CSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fservice-bus-messaging%2Fmessage-sessions%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3EMessage%20Sessions%26nbsp%3B%20%3C%2FA%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFrom%20the%20above%20Pre-requirements%2C%20we%20learn%20the%20followings%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EEnabling%20%3CSTRONG%3EDuplicate%20detection%3C%2FSTRONG%3E%20helps%20to%20ensure%20that%20a%20duplicate%20message%2C%20which%20has%20the%20same%20message%20Id%20cannot%20be%20sent%20into%20a%20messaging%20entity%20during%20a%20specified%20time.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3E%3CSTRONG%3EService%20Bus%20Partitions%3C%2FSTRONG%3E%20enable%20queues%20and%20topics%20or%20message%20entities%20to%20be%20partitioned%20across%20multiple%20message%20brokers%20and%20messaging%20stores.%20Enable%20partitioning%20the%20overall%20throughput%20will%20separate%20to%20different%20partition.%20%3CSTRONG%3EPartition%20key%3C%2FSTRONG%3E%20can%20be%20used%20in%20some%20scenarios%2C%20such%20as%20sessions%20or%20transactions%2C%20require%20messages%20to%20be%20stored%20in%20a%20specific%20partition.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3E%3CSTRONG%3EMicrosoft%20Service%20Bus%20Session%3C%2FSTRONG%3E%20enable%20joint%20and%20ordered%20handling%20of%20unbounded%20sequences%20of%20messages.%26nbsp%3B%20There%20are%20two%20patterns%20of%20it%20%2C%20first%20out%20and%20request-response%20pattern.%20Any%20sender%20can%20create%20a%20session%20when%20submitting%20messages%20into%20a%20topic%20or%20queue%20by%20setting%20the%20%3CSTRONG%3ESessionId%3C%2FSTRONG%3E%20property%20to%20some%20application-defined%20identifier%20that%20is%20unique%20to%20the%20session.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ESo%2C%20from%20these%20above%20knowledges%2C%20we%20know%20that%20Azure%20Service%20Bus%20Queue%20and%20Topic%2FSubscription%20can%20enable%20for%20%3CSTRONG%3EDuplicate%20Detection%3C%2FSTRONG%3E%2C%20%3CSTRONG%3EPartitions%20%3C%2FSTRONG%3Eand%3CSTRONG%3E%20Sessions%3C%2FSTRONG%3E.%20%3CSTRONG%3EBut%20what%E2%80%99s%20the%20relationship%20between%20them%3F%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EFrom%20the%20meaning%20of%20Duplication%20detection%2C%20we%20know%20that%20there%20is%20a%20MessageId%20of%20each%20message.%20Definition%20of%20MessageId%20is%20shown%20below%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%3CEM%3E%E2%80%9CIf%20the%20queue%20or%20topic%20has%20the%26nbsp%3BRequiresDuplicateDetection%26nbsp%3Bproperty%20set%20to%26nbsp%3Btrue%26nbsp%3Band%20the%26nbsp%3BSessionId%26nbsp%3Bor%26nbsp%3BPartitionKey%26nbsp%3Bproperties%20are%20not%20set%2C%20then%20the%26nbsp%3BMessageId%26nbsp%3Bproperty%20value%20serves%20as%20the%20partition%20key%E2%80%9D%3C%2FEM%3E%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EThis%20means%20the%20duplicate%20detection%20only%20can%20work%20when%20SessionID%20or%20PartitionKey%20are%20not%20be%20set%3CSTRONG%3E.%20Is%20that%20a%20correct%20statement%3F%20Let%E2%80%99s%20do%20a%20test!%3C%2FSTRONG%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--1271197493%22%20id%3D%22toc-hId--1271197492%22%3E%3CFONT%20size%3D%225%22%3E%3CSTRONG%3ETest%20Entities%3A%3C%2FSTRONG%3E%3C%2FFONT%3E%3C%2FH2%3E%0A%3CP%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EQueues%3A%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EThere%20are%20three%20queue%20I%20used%2C%20testqueue%2C%20testqueue2%2C%20testqueue3.%20At%20first%20time%20all%20of%20them%20have%200%20messages.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-left%22%20image-alt%3D%22servicebusblog0.png%22%20style%3D%22width%3A%20393px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F216167iC6A4FDB3EC632F53%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22servicebusblog0.png%22%20alt%3D%22servicebusblog0.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3E%3CSTRONG%3E%3CU%3E%3CSPAN%3Etestqueue%3C%2FSPAN%3E%3C%2FU%3E%3C%2FSTRONG%3E%3CSPAN%3E%3A%26nbsp%3B%20Enable%20Batched%20Operation%2C%20Requires%20Duplicate%20Detection.%20And%20set%20duplicate%20detection%20for%2010%20mins.%3C%2FSPAN%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CSPAN%3E%26nbsp%3B%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22servicebusblog1.png%22%20style%3D%22width%3A%20649px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F216168i9F4A03E162A1B621%2Fimage-dimensions%2F649x486%3Fv%3D1.0%22%20width%3D%22649%22%20height%3D%22486%22%20title%3D%22servicebusblog1.png%22%20alt%3D%22servicebusblog1.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3E%3CSTRONG%3E%3CU%3E%3CSPAN%3Etestqueue2%3C%2FSPAN%3E%3C%2FU%3E%3C%2FSTRONG%3E%3CSPAN%3E%3A%20Enable%20Batched%20Operation%2C%20Requires%20Duplicate%20Detection%2C%20Requires%20Session%3C%2FSPAN%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CSPAN%3E%26nbsp%3B%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22servicebusblog2.png%22%20style%3D%22width%3A%20648px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F216170i61BCA5396FB05B12%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22servicebusblog2.png%22%20alt%3D%22servicebusblog2.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3E%3CSTRONG%3E%3CU%3E%3CSPAN%3Etestqueue3%3C%2FSPAN%3E%3C%2FU%3E%3C%2FSTRONG%3E%3CSPAN%3E%3A%20Enable%20Batched%20Operation%2C%20Requires%20Duplicate%20Detection%2C%20Requires%20Session%2C%20Enable%20Partition%3C%2FSPAN%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CSPAN%3E%26nbsp%3B%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22servicebusblog3.png%22%20style%3D%22width%3A%20645px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F216171iA710EDDAE8A3544E%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22servicebusblog3.png%22%20alt%3D%22servicebusblog3.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%3CSPAN%3EMy%20Program%3A%3C%2FSPAN%3E%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%3CSPAN%3EHere%20is%20the%20code.%20%3C%2FSPAN%3E%3C%2FSTRONG%3EThe%20different%20in%20this%20program%20used%20in%20each%20time%2C%20just%20the%20BrokeredMessage%20SessionID%20and%20PartitionKey%20that%20in%20red%20color.%3C%2FP%3E%0A%3CP%3EThe%20Session%20ID%20here%20set%20with%20a%20random%20value.%20From%20the%20above%20document%2C%20when%20enable%20both%20Partition%20key%20and%20Session%20ID%2C%20the%20value%20of%20them%20need%20to%20be%20same.%20Otherwise%20Service%20Bus%20returns%20an%20invalid%20operation%20exception.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20class%20Program%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20static%20string%20connectionString%20%3D%20%5BConnectionString%5D%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20static%20string%20queueName%20%3D%20%22testqueue3%22%3B%2F%2F%20testqueue%2Ctestqueue2%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3Bstatic%20void%20Main(string%5B%5D%20args)%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20MainAsync()%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7D%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20static%20void%20MainAsync()%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20QueueClient%20sendClient%20%3D%20QueueClient.CreateFromConnectionString(connectionString%2C%20queueName)%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2F%2Fcreate%20a%20sender%20on%20the%20queue%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20var%20session%20%3D%20Guid.NewGuid().ToString()%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20var%20partitionKey%20%3D%20session%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20sendClient.SendBatch(Enumerable.Range(0%2C%2010).Select(n%20%3D%26gt%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Console.WriteLine(%22test%20my%20message%20n%7B0%7D%22%2C%20session)%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20BrokeredMessage%20test%20%3D%20new%20BrokeredMessage(%22Hello%20World!%22)%20%7B%20%3CFONT%20color%3D%22%23FF0000%22%3E%3CSTRONG%3ESessionId%20%3D%20session%2C%20%2C%20PartitionKey%20%3D%20session%3C%2FSTRONG%3E%2C%3C%2FFONT%3E%20MessageId%20%3D%20%22deadbeef-dead-beef-dead-beef%22%20%2B%20n%20%7D%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20return%20test%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7D%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B))%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7D%3C%2FP%3E%0A%3CP%3E%7D%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3ETest%20Round%201%3A%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3ETo%20find%20the%20message%2C%20I%20sent%2010%20message%20each%20time%20first.%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3E%3CSTRONG%3E%3CSPAN%3Etestqueue%20(Enable%20Batched%20Operation%2C%20Requires%20Duplicate%20Detection)%3A%3C%2FSPAN%3E%3C%2FSTRONG%3E%20%26nbsp%3Bsend%2010%20messages%20first%2C%20then%20immediately%20%26nbsp%3Bsend%20another%20same%2010%20messages%2C%20it%20still%20displays%2010%20messages.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22servicebusblog8.0.png%22%20style%3D%22width%3A%20958px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F216172iFDA9E038BF125409%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22servicebusblog8.0.png%22%20alt%3D%22servicebusblog8.0.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3E%3CSTRONG%3E%3CSPAN%3Etestqueue2(Enable%20Batched%20Operation%2C%20Requires%20Duplicate%20Detection%2C%20Requires%20Session)%3C%2FSPAN%3E%3C%2FSTRONG%3E%3A%20send%2010%20messages%20first%2C%20and%20send%20another%20same%2010%20messages%2C%20here%20also%20display%2010%20messages.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22servicebusblog7.png%22%20style%3D%22width%3A%20970px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F216173i14CEA4DAF5AEFBAB%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22servicebusblog7.png%22%20alt%3D%22servicebusblog7.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3E%3CSTRONG%3E%3CSPAN%3Etestqueue3(Enable%20Batched%20Operation%2C%20Requires%20Duplicate%20Detection%2C%20Requires%20Session%2C%20Enable%20Partition)%3A%20%3C%2FSPAN%3E%3C%2FSTRONG%3E%3CSPAN%3EAdd%20new%20message%20twice%20the%20message%20count%20turn%20to%2020.%3C%2FSPAN%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CSPAN%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22servicebusblog8.png%22%20style%3D%22width%3A%20945px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F216174i225D5C5A7CE69EDC%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22servicebusblog8.png%22%20alt%3D%22servicebusblog8.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EYou%20can%20see%20in%20the%20list%20there%20are%20message%20with%20duplicate%20MessageId.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E%26nbsp%3B%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22servicebusblog9.png%22%20style%3D%22width%3A%20728px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F216175i97BAE0CDD9DBD7E1%2Fimage-dimensions%2F728x433%3Fv%3D1.0%22%20width%3D%22728%22%20height%3D%22433%22%20title%3D%22servicebusblog9.png%22%20alt%3D%22servicebusblog9.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EThen%20I%20checked%20for%20same%20MessageId%20%E2%80%9C%3CSTRONG%3Edeadbeef-dead-beef-dead-beef0%3C%2FSTRONG%3E%E2%80%9D%20%2C%20and%20I%20found%20they%20have%20%26nbsp%3Bdifferent%20Partition%20Keys.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22servicebusblog10.png%22%20style%3D%22width%3A%20548px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F216176i4B8D3040C97AA56C%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22servicebusblog10.png%22%20alt%3D%22servicebusblog10.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22servicebusblog10.1.png%22%20style%3D%22width%3A%20544px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F216177iFFBBF786022E0FE3%2Fimage-dimensions%2F544x451%3Fv%3D1.0%22%20width%3D%22544%22%20height%3D%22451%22%20title%3D%22servicebusblog10.1.png%22%20alt%3D%22servicebusblog10.1.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EHere%20are%20these%20three%20queues%20result%20in%20this%20test.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22servicebusblog12.png%22%20style%3D%22width%3A%20384px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F216178i5B44877A527EA0C9%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22servicebusblog12.png%22%20alt%3D%22servicebusblog12.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EThe%20above%20test%20about%20messages%20sent%20in%20duplicate%20detection%20duration.%20How%20about%20we%20wait%20for%2010%20mins%20to%20check%20after%20the%20duplicate%20detection%20time%3F%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3ETest%20Round%202%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EAfter%2010%20mins%2C%20I%20sent%201000%20messages%20again%20twice.%20The%20result%20shows%2C%20%3CSTRONG%3Etestqueue%3C%2FSTRONG%3E%20and%20%3CSTRONG%3Etestqueue2%3C%2FSTRONG%3E%20have%201000%20included%20the%2010%20messages%20sent%20before.%3C%2FSPAN%3E%20For%20%3CSTRONG%3E%3CSPAN%3Etestqueue3%3C%2FSPAN%3E%3C%2FSTRONG%3E%3CSPAN%3E%2C%20there%20are%202020%20messages.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22servicebusblog13.png%22%20style%3D%22width%3A%20377px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F216179iAA6A2C92C5FF392B%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22servicebusblog13.png%22%20alt%3D%22servicebusblog13.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20size%3D%225%22%3E%3CSTRONG%3ETest%20Result%20Summary%20%3C%2FSTRONG%3E%3C%2FFONT%3E%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3E%3CSPAN%3EFrom%20the%20first%20round%20test%20result%2C%20it%20indicates%20that%20messages%20with%20same%20MessageId%20can%20be%20detected%20as%20duplication%20in%20a%20non-partitioned%20entity%20within%20specified%20duplicate%20detection%20duration%20(10%20mins).%20%3C%2FSPAN%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3E%3CSPAN%3EHowever%20with%20partitioned%20entity%2C%20duplicate%20messages%20which%20has%20same%20MessageId%20may%20not%20be%20detected%20as%20duplication%20due%20to%20they%20can%20end%20up%20in%20a%20different%20partition.%20In%20conclusion%2C%20messages%20can%20only%20be%20detected%20as%20duplication%20within%20the%20specified%20duplicate%20detection%20duration%20when%20they%20are%20landed%20in%20the%20same%20partition%2C%20i.e.%20same%20partition%20key%3C%2FSPAN%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3E%3CSPAN%3EFor%20the%20second%20test%20with%201000%20message%20were%20sent%20twice%2C%20it%20indicates%20that%20the%20duplicate%20duration%20detect%20only%20works%20for%20the%20specified%20duration.%20After%20the%20duplicate%20detection%20period%2C%20the%20Messages%20with%20same%20MessageId%20can%20be%20sent%20to%20the%20same%20Service%20Bus%20messaging%20entity.%3C%2FSPAN%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CSTRONG%3E%26nbsp%3B%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-1629898%22%20slang%3D%22en-US%22%3E%3CP%3E%3CFONT%20size%3D%225%22%3E%3CSTRONG%3EPre-requirements%3A%3C%2FSTRONG%3E%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3EBefore%20we%20start%2C%20please%20read%20these%20document%20about%20%3CSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fservice-bus-messaging%2Fduplicate-detection%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%20target%3D%22_blank%22%3EDuplicate%20Detection%3C%2FA%3E%3C%2FSPAN%3E%2C%20%3CSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fservice-bus-messaging%2Fservice-bus-partitioning%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%20target%3D%22_blank%22%3EPartitioned%20queues%20and%20topics%3C%2FA%3E%3C%2FSPAN%3E%20and%20%3CSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fservice-bus-messaging%2Fmessage-sessions%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%20target%3D%22_blank%22%3EMessage%20Sessions%26nbsp%3B%20%3C%2FA%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFrom%20the%20above%20Pre-requirements%2C%20we%20learn%20the%20followings%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EEnabling%20%3CSTRONG%3EDuplicate%20detection%3C%2FSTRONG%3E%20helps%20to%20ensure%20that%20a%20duplicate%20message%2C%20which%20has%20the%20same%20message%20Id%20cannot%20be%20sent%20into%20a%20messaging%20entity%20during%20a%20specified%20time.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3E%3CSTRONG%3EService%20Bus%20Partitions%3C%2FSTRONG%3E%20enable%20queues%20and%20topics%20or%20message%20entities%20to%20be%20partitioned%20across%20multiple%20message%20brokers%20and%20messaging%20stores.%20Enable%20partitioning%20the%20overall%20throughput%20will%20separate%20to%20different%20partition.%20%3CSTRONG%3EPartition%20key%3C%2FSTRONG%3E%20can%20be%20used%20in%20some%20scenarios%2C%20such%20as%20sessions%20or%20transactions%2C%20require%20messages%20to%20be%20stored%20in%20a%20specific%20partition.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3E%3CSTRONG%3EMicrosoft%20Service%20Bus%20Session%3C%2FSTRONG%3E%20enable%20joint%20and%20ordered%20handling%20of%20unbounded%20sequences%20of%20messages.%26nbsp%3B%20There%20are%20two%20patterns%20of%20it%20%2C%20first%20out%20and%20request-response%20pattern.%20Any%20sender%20can%20create%20a%20session%20when%20submitting%20messages%20into%20a%20topic%20or%20queue%20by%20setting%20the%20%3CSTRONG%3ESessionId%3C%2FSTRONG%3E%20property%20to%20some%20application-defined%20identifier%20that%20is%20unique%20to%20the%20session.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ESo%2C%20from%20these%20above%20knowledges%2C%20we%20know%20that%20Azure%20Service%20Bus%20Queue%20and%20Topic%2FSubscription%20can%20enable%20for%20%3CSTRONG%3EDuplicate%20Detection%3C%2FSTRONG%3E%2C%20%3CSTRONG%3EPartitions%20%3C%2FSTRONG%3Eand%3CSTRONG%3E%20Sessions%3C%2FSTRONG%3E.%20%3CSTRONG%3EBut%20what%E2%80%99s%20the%20relationship%20between%20them%3F%3C%2FSTRONG%3E%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1629898%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%20Service%20Bus%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Microsoft

Pre-requirements:

Before we start, please read these document about Duplicate Detection, Partitioned queues and topics and Message Sessions 

 

From the above Pre-requirements, we learn the followings

  • Enabling Duplicate detection helps to ensure that a duplicate message, which has the same message Id cannot be sent into a messaging entity during a specified time.

 

  • Service Bus Partitions enable queues and topics or message entities to be partitioned across multiple message brokers and messaging stores. Enable partitioning the overall throughput will separate to different partition. Partition key can be used in some scenarios, such as sessions or transactions, require messages to be stored in a specific partition.

 

 

  • Microsoft Service Bus Session enable joint and ordered handling of unbounded sequences of messages.  There are two patterns of it , first out and request-response pattern. Any sender can create a session when submitting messages into a topic or queue by setting the SessionId property to some application-defined identifier that is unique to the session.

 

So, from these above knowledges, we know that Azure Service Bus Queue and Topic/Subscription can enable for Duplicate Detection, Partitions and Sessions. But what’s the relationship between them?

From the meaning of Duplication detection, we know that there is a MessageId of each message. Definition of MessageId is shown below

“If the queue or topic has the RequiresDuplicateDetection property set to true and the SessionId or PartitionKey properties are not set, then the MessageId property value serves as the partition key”

 

This means the duplicate detection only can work when SessionID or PartitionKey are not be set. Is that a correct statement? Let’s do a test!

 

Test Entities:

 

Queues:

There are three queue I used, testqueue, testqueue2, testqueue3. At first time all of them have 0 messages.

servicebusblog0.png

  • testqueue:  Enable Batched Operation, Requires Duplicate Detection. And set duplicate detection for 10 mins.

 servicebusblog1.png

  • testqueue2: Enable Batched Operation, Requires Duplicate Detection, Requires Session

 servicebusblog2.png

  • testqueue3: Enable Batched Operation, Requires Duplicate Detection, Requires Session, Enable Partition

 servicebusblog3.png

 

My Program:

Here is the code. The different in this program used in each time, just the BrokeredMessage SessionID and PartitionKey that in red color.

The Session ID here set with a random value. From the above document, when enable both Partition key and Session ID, the value of them need to be same. Otherwise Service Bus returns an invalid operation exception.

 

    class Program

    {

        static string connectionString = [ConnectionString];

        static string queueName = "testqueue3";// testqueue,testqueue2

        static void Main(string[] args)

        {

            MainAsync();

        }

        static void MainAsync()

        {

            QueueClient sendClient = QueueClient.CreateFromConnectionString(connectionString, queueName);

            //create a sender on the queue

 

            var session = Guid.NewGuid().ToString();

            var partitionKey = session;

            sendClient.SendBatch(Enumerable.Range(0, 10).Select(n =>

            {

 

                Console.WriteLine("test my message n{0}", session);

                BrokeredMessage test = new BrokeredMessage("Hello World!") { SessionId = session, , PartitionKey = session, MessageId = "deadbeef-dead-beef-dead-beef" + n };

 

                return test;

            }

            ));

        }

}

Test Round 1:

To find the message, I sent 10 message each time first.

  • testqueue (Enable Batched Operation, Requires Duplicate Detection):  send 10 messages first, then immediately  send another same 10 messages, it still displays 10 messages.

servicebusblog8.0.png

  • testqueue2(Enable Batched Operation, Requires Duplicate Detection, Requires Session): send 10 messages first, and send another same 10 messages, here also display 10 messages.

servicebusblog7.png

 

  • testqueue3(Enable Batched Operation, Requires Duplicate Detection, Requires Session, Enable Partition): Add new message twice the message count turn to 20.

servicebusblog8.png

You can see in the list there are message with duplicate MessageId.

 servicebusblog9.png

 

Then I checked for same MessageId “deadbeef-dead-beef-dead-beef0” , and I found they have  different Partition Keys.

servicebusblog10.png

 

servicebusblog10.1.png

 

Here are these three queues result in this test.

servicebusblog12.png

 

The above test about messages sent in duplicate detection duration. How about we wait for 10 mins to check after the duplicate detection time?

 

 

 

Test Round 2

 

After 10 mins, I sent 1000 messages again twice. The result shows, testqueue and testqueue2 have 1000 included the 10 messages sent before. For testqueue3, there are 2020 messages.

servicebusblog13.png

 

 

Test Result Summary

  • From the first round test result, it indicates that messages with same MessageId can be detected as duplication in a non-partitioned entity within specified duplicate detection duration (10 mins).

 

  • However with partitioned entity, duplicate messages which has same MessageId may not be detected as duplication due to they can end up in a different partition. In conclusion, messages can only be detected as duplication within the specified duplicate detection duration when they are landed in the same partition, i.e. same partition key

 

 

  • For the second test with 1000 message were sent twice, it indicates that the duplicate duration detect only works for the specified duration. After the duplicate detection period, the Messages with same MessageId can be sent to the same Service Bus messaging entity.