处理Azure存储队列列表,没有ADF ForEach中的任何QueueMessage。

huangapple go评论48阅读模式
英文:

Dealing with Azure Storage Queue list without any QueuMessage in ADF ForEach

问题

I am using WebActivity to get QueueMessage from Azure Blob Storage and pass the output to ForEach to use each QueueMessage in subsequent pipeline process. The pipeline is on schedule run and this is the Dynamic Expression I use in ForEach Items:

@json(xml(activity('get_queue_message').output.Response)).QueueMessagesList.QueueMessage

It works fine when there are MessageText in the queue. But once the queue is cleared and the webactivity returns empty QueueMessageList as per below, the ForEach will start to fail:

{
	"Response": "<?xml version=\"1.0\" encoding=\"utf-8\"?><QueueMessagesList />",
	"ADFWebActivityResponseHeaders": {
		"Transfer-Encoding": "chunked",
		"x-ms-request-id": "requestid",
		"x-ms-version": "2020-04-08",
		"Cache-Control": "no-cache",
		"Date": "Tue, 13 Jun 2023 07:53:30 GMT",
		"Server": "Windows-Azure-Queue/1.0;Microsoft-HTTPAPI/2.0",
		"Content-Type": "application/xml"
	},
	"effectiveIntegrationRuntime": "AutoResolveIntegrationRuntime (Southeast Asia)",
	"executionDuration": 0,
	"durationInQueue": {
		"integrationRuntimeQueue": 0
	},
	"billingReference": {
		"activityType": "ExternalActivity",
		"billableDuration": [
			{
				"meterType": "AzureIR",
				"duration": 0.016666666666666666,
				"unit": "Hours"
			}
		]
	}
}

ForEach Failure as follows:

The expression 'length(json(xml(activity('get_queue_message').output.Response)).QueueMessagesList.QueueMessage)' cannot be evaluated because property 'QueueMessage' cannot be selected.

What is the correct way to check for the QueueMessageList before running ForEach. If the queue is empty, I would like to stop the ForEach without triggering any error.

Thank you.

英文:

I am using WebActivity to get QueueMessage from Azure Blob Storage and pass the output to ForEeach to use each QueueMessage in subsequent pipeline process.The pipeline is on schedule run and this is the Dynamic Expression I use in ForEach Items:

@json(xml(activity(&#39;get_queue_message&#39;).output.Response)).QueueMessagesList.QueueMessage

It works fine when there are MessageText in the queue. But once the queue is cleared and the webactivity returns empty QueueMessageList as per below, the ForEach will start to fail

{
 &quot;Response&quot;: &quot;&lt;?xml version=\&quot;1.0\&quot; encoding=\&quot;utf-8\&quot;?&gt;&lt;QueueMessagesList /&gt;&quot;,
 &quot;ADFWebActivityResponseHeaders&quot;: {
 	&quot;Transfer-Encoding&quot;: &quot;chunked&quot;,
 	&quot;x-ms-request-id&quot;: &quot;requestid&quot;,
 	&quot;x-ms-version&quot;: &quot;2020-04-08&quot;,
 	&quot;Cache-Control&quot;: &quot;no-cache&quot;,
 	&quot;Date&quot;: &quot;Tue, 13 Jun 2023 07:53:30 GMT&quot;,
 	&quot;Server&quot;: &quot;Windows-Azure-Queue/1.0;Microsoft-HTTPAPI/2.0&quot;,
 	&quot;Content-Type&quot;: &quot;application/xml&quot;
 },
 &quot;effectiveIntegrationRuntime&quot;: &quot;AutoResolveIntegrationRuntime (Southeast Asia)&quot;,
 &quot;executionDuration&quot;: 0,
 &quot;durationInQueue&quot;: {
 	&quot;integrationRuntimeQueue&quot;: 0
 },
 &quot;billingReference&quot;: {
 	&quot;activityType&quot;: &quot;ExternalActivity&quot;,
 	&quot;billableDuration&quot;: [
 		{
 			&quot;meterType&quot;: &quot;AzureIR&quot;,
 			&quot;duration&quot;: 0.016666666666666666,
 			&quot;unit&quot;: &quot;Hours&quot;
 		}
 	]
 }
}

ForEach Failure as follows:

> The expression 'length(json(xml(activity('get_queue_message').output.Response)).QueueMessagesList.QueueMessage)' cannot be evaluated because property 'QueueMessage' cannot be selected.

What is the correct way to check for the QueueMessageList before running ForEach. If the queue is empty, i would like to stop the ForEach without triggering any error.

Thank you.

答案1

得分: 1

To check if the QueueMessagesList is empty before running the ForEach activity, you can use the if function to conditionally execute the ForEach activity only if the QueueMessagesList is not empty. Since the ForEach activity cannot be used directly inside an If Condition activity, you can design a two level pipeline by using the combination of If Condition and Execute Pipeline activities to achieve the requirement. In the outer pipeline, take the web activity and if activity. Inside the if activity, take the execute pipeline activity.

Outer Pipeline:

  • Take the Web activity and then the if condition activity. Give the expression as,
@contains(json(xml(activity(&#39;get_queue_message&#39;).output.Response)).QueueMessagesList,&#39;QueueMessage&#39;)

This expression will return true if the QueueMessagesList property contains one or more QueueMessage elements, and false if the QueueMessagesList property is empty, meaning it does not contain any QueueMessage elements.

  • You can also give the expression as
@not(empty(json(xml(activity(&#39;get_queue_message&#39;).output.Response)).QueueMessagesList))

This expression returns true if there are messages in the QueueMessagesList property, and false if there are no messages.

  • In the true section of the If activity, you can add an execute pipeline activity, and in the false branch, leave it empty (no activities inside it).

Inner Pipeline:

  • In the execute pipeline activity, you can invoke the pipeline that contains the web activity and the for-each activity.

This way, you can execute the ForEach activity only if the QueueMessagesList is not empty.

英文:

To check if the QueueMessagesList is empty before running the ForEach activity, you can use the if function to conditionally execute the ForEach activity only if the QueueMessagesList is not empty. Since the ForEach activity cannot be used directly inside an If Condition activity, you can design a two level pipeline by using the combination of If Condition and Execute Pipeline activities to achieve the requirement. In outer pipeline take the web activity and if activity. Inside if activity take the execute pipeline activity.

Outer Pipeline:
处理Azure存储队列列表,没有ADF ForEach中的任何QueueMessage。

  • Take the Web activity and then if condition activity. Give the expression as,
@contains(json(xml(activity(&#39;get_queue_message&#39;).output.Response)).QueueMessagesList,&#39;QueueMessage&#39;)

This expression will return true if the QueueMessagesList property contains one or more QueueMessage elements, and false if the QueueMessagesList property is empty. that is, it does not contain any QueueMessage elements.

  • You can also give the expression as
@not(empty(json(xml(activity(&#39;get_queue_message&#39;).output.Response)).QueueMessagesList))

This expression returns true if there are messages in the QueueMessagesList property, and false if there are no messages.

  • In true section of If activity you can add execute pipeline activity and in false branch, leave it as empty (no activities inside it).

Inner Pipeline:

  • In the execute pipeline activity, you can invoke the pipeline that contains web activity and for-each activity.

处理Azure存储队列列表,没有ADF ForEach中的任何QueueMessage。

This way, you can execute the ForEach activity only if the QueueMessagesList is not empty.

huangapple
  • 本文由 发表于 2023年6月13日 16:01:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/76462834.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定