<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>David Barbarin &#187; service broker</title>
	<atom:link href="https://blog.developpez.com/mikedavem/ptag/service-broker/feed" rel="self" type="application/rss+xml" />
	<link>https://blog.developpez.com/mikedavem</link>
	<description>MVP DataPlatform - MCM SQL Server</description>
	<lastBuildDate>Thu, 09 Sep 2021 21:19:50 +0000</lastBuildDate>
	<language>fr-FR</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.1.42</generator>
	<item>
		<title>SQL Server service broker and curious duplicate messages case</title>
		<link>https://blog.developpez.com/mikedavem/p13185/sql-server-2008/sql-server-service-broker-and-curious-duplicate-messages</link>
		<comments>https://blog.developpez.com/mikedavem/p13185/sql-server-2008/sql-server-service-broker-and-curious-duplicate-messages#comments</comments>
		<pubDate>Sun, 22 Dec 2019 18:45:44 +0000</pubDate>
		<dc:creator><![CDATA[mikedavem]]></dc:creator>
				<category><![CDATA[SQL Server 2008]]></category>
		<category><![CDATA[SQL Server 2008 R2]]></category>
		<category><![CDATA[SQL Server 2012]]></category>
		<category><![CDATA[SQL Server 2014]]></category>
		<category><![CDATA[SQL Server 2016]]></category>
		<category><![CDATA[SQL Server 2017]]></category>
		<category><![CDATA[service broker]]></category>

		<guid isPermaLink="false">http://blog.developpez.com/mikedavem/?p=1419</guid>
		<description><![CDATA[One of my last write-up to finish the year 2019. A couple of days ago, I ran into an interesting issue concerning a service broker architecture. Let’s introduce quickly the context: this is a start-based architecture with one target and &#8230; <a href="https://blog.developpez.com/mikedavem/p13185/sql-server-2008/sql-server-service-broker-and-curious-duplicate-messages">Lire la suite <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>One of my last write-up to finish the year 2019. A couple of days ago, I ran into an interesting issue concerning a service broker architecture. Let’s introduce quickly the context: this is a start-based architecture with one target and more than 80 initiators as shown below:</p>
<p><span id="more-1419"></span></p>
<p><a href="http://blog.developpez.com/mikedavem/files/2019/12/152-0-SB-architecture.jpg"><img src="http://blog.developpez.com/mikedavem/files/2019/12/152-0-SB-architecture.jpg" alt="152 - 0 - SB architecture" width="494" height="574" class="alignnone size-full wp-image-1421" /></a></p>
<p>All messages are sent from the initiators to a single central target. Windows authentication for endpoint&rsquo;s connection and messages are encrypted before to be sent to the remote service by using certificates mapped to database users. </p>
<p><a href="http://blog.developpez.com/mikedavem/files/2019/12/152-1-SB-architecture.jpg"><img src="http://blog.developpez.com/mikedavem/files/2019/12/152-1-SB-architecture.jpg" alt="152 - 1 - SB architecture" width="838" height="486" class="alignnone size-full wp-image-1422" /></a></p>
<p>Installing such infrastructure is not trivial and during this year, we often had to deploy and reinitialize service broker configurations because we added new initiators, or some initiators were replaced by other ones. Therefore, on the DBA side we worked on an automatic way to interact with service broker configuration and it turns out that the natural way for us was to write a PowerShell module to address it. </p>
<p>A couple of days, for a sake of curiosity I implemented a service broker event based XE session and I noticed a bunch of broker_message_undeliverable messages with the reason: The message could not be delivered because it is a duplicate. See below:</p>
<p><a href="http://blog.developpez.com/mikedavem/files/2019/12/152-2-xe-result.jpg"><img src="http://blog.developpez.com/mikedavem/files/2019/12/152-2-xe-result.jpg" alt="152 - 2 - xe result" width="1126" height="574" class="alignnone size-full wp-image-1424" /></a></p>
<p>What does it mean exactly? Well, according to my Google-fu and very-explained <a href="https://rusanu.com/2005/12/20/troubleshooting-dialogs/" rel="noopener" target="_blank">blog</a> from Remus Rusanu, it seems that the messages are accepted by the target, but the acks don’t reach back to the sender and therefore the sender is retrying the message again and again. But in my case, the sender ended up managing sending back the acknowledgement. </p>
<p>First step was to identify a misconfigured route between the target and the corresponding initiator. From broker instance value corresponds to the service broker id of the initiator. But surprisingly I didn’t find any misconfigured item. But I remembered the campaign of server rollout that had been going on for a few months where some servers were renamed following a new named convention. Furthermore, in our deployment process, dealing with new or renamed servers is exactly the same and we just initialize a new initiator and install a new route on the target regardless the scenario. But we forget one important point: because all routes are based on server name renaming a server leads to potentially to duplicate routes in this case. I verified my assumption by counting the number of existing routes on the target site:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:650px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">SELECT COUNT(*) FROM sys.routes</div></div>
<p>The result was 148 and we expect to get 85 routes in the current architecture confirming we have duplicate items here. Next step consisted in identifying and fixing duplicate routes:</p>
<p><a href="http://blog.developpez.com/mikedavem/files/2019/12/152-30-duplicate-routes-query.jpg"><img src="http://blog.developpez.com/mikedavem/files/2019/12/152-30-duplicate-routes-query.jpg" alt="152 - 30 - duplicate routes query" width="540" height="366" class="alignnone size-full wp-image-1430" /></a></p>
<p>Here a sample of duplicate routes I founded. The renaming server kept its service broker id and I easily identified duplicates by grouping by the broker instance.</p>
<p><a href="http://blog.developpez.com/mikedavem/files/2019/12/152-3-duplicate-routes.jpg"><img src="http://blog.developpez.com/mikedavem/files/2019/12/152-3-duplicate-routes.jpg" alt="152 - 3 - duplicate routes" width="893" height="115" class="alignnone size-full wp-image-1425" /></a></p>
<p>After fixing the issue, messages related to duplicates disappear from the XE output.<br />
Hope this helps!</p>
<p>David Barbarin</p>
]]></content:encoded>
			<wfw:commentRss></wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
