Reading message from Service bus - azure-logic-apps

I have a logic app with started when there is a message in serviceBus queue. The message is being published to the service bus from the DevOps pipeline using "PublishToAzureServiceBus" as a JSON message or from the pipeline webhook.
But getting an issue while converting a message from service bus to original JSON format, not able to get valid JSON object. It's getting append with some Serialization object.
I have tried with base64 decode, and JSON converts but have not been able to get success.
Below is the content of the message it looks like.
Any pointer on how can solve this?
Sample message sent
{
"id": "76a187f3-c154-4e60-b8bc-c0b754e54191",
"eventType": "build.complete",
"publisherId": "tfs",
"message": {
"text": "Build 20220605.8 succeeded"
},
"detailedMessage": {
"text": "Build 20220605.8 succeeded"
},
"resource": {
"uri": "vstfs:///Build/Build/288",
"id": 288,
"buildNumber": "20220605.8",
"url": "https://dev.azure.com/*******/_apis/build/Builds/288",
"startTime": "2022-06-05T14:47:01.1846966Z",
"finishTime": "2022-06-05T14:47:16.7602096Z",
"reason": "manual",
"status": "succeeded",
"drop": {},
"log": {},
"sourceGetVersion": "LG:refs/heads/main:********",
"lastChangedBy": {
"displayName": "Microsoft.VisualStudio.Services.TFS",
"id": "00000000-0000-0000-0000-000000000000",
"uniqueName": "***************"
},
"retainIndefinitely": false,
"definition": {
"definitionType": "xaml",
"id": 20,
"name": "getReleaseFile",
"url": "https://dev.azure.com/************/_apis/build/Definitions/20"
},
"requests": [
{
"id": 288,
"url": "https://dev.azure.com/B*****/**********/_apis/build/Requests/288",
"requestedFor": {
"displayName": "B*****.sag",
"id": "*******",
"uniqueName": "B**********"
}
}
]
},
"resourceVersion": "1.0",
"resourceContainers": {
"collection": {
"id": "*******",
"baseUrl": "https://dev.azure.com/B*****/"
},
"account": {
"id": "******",
"baseUrl": "https://dev.azure.com/B*****/"
},
"project": {
"id": "**********",
"baseUrl": "https://dev.azure.com/B*****/"
}
},
"createdDate": "2022-06-05T14:47:28.6089499Z"
}
Message received
#string3http://schemas.microsoft.com/2003/10/Serialization/�q{"id":"****","eventType":"build.complete","publisherId":"tfs","message":{"text":"Build 20220605.8 succeeded"},"detailedMessage":{"text":"Build 20220605.8 succeeded"},"resource":{"uri":"vstfs:///Build/Build/288","id":288,"buildNumber":"20220605.8","url":"https://dev.azure.com/*****/********/_apis/build/Builds/288","startTime":"2022-06-05T14:47:01.1846966Z","finishTime":"2022-06-05T14:47:16.7602096Z","reason":"manual","status":"succeeded","drop":{},"log":{},"sourceGetVersion":"LG:refs/heads/main:f0b1a1d2bd047454066cf21dc4d4c710bca4e1d7","lastChangedBy":{"displayName":"Microsoft.VisualStudio.Services.TFS","id":"00000000-0000-0000-0000-000000000000","uniqueName":"******"},"retainIndefinitely":false,"definition":{"definitionType":"xaml","id":20,"name":"getReleaseFile","url":"https://dev.azure.com/******/_apis/build/Definitions/20"},"requests":[{"id":288,"url":"https://dev.azure.com/*****/******/_apis/build/Requests/288","requestedFor":{"displayName":"baharul.sag","id":"******","uniqueName":"baharul.*****"}}]},"resourceVersion":"1.0","resourceContainers":{"collection":{"id":"3*****","baseUrl":"https://dev.azure.com/*****/"},"account":{"id":"******","baseUrl":"https://dev.azure.com/*****/"},"project":{"id":"*******","baseUrl":"https://dev.azure.com/*****/"}},"createdDate":"2022-06-05T14:47:28.6089499Z"}
When reading message from service bus in peek mode can see as below where <#string3http://schemas.microsoft.com/2003/10/Serialization/��> is appended to json string
Publish using PublishToAzureServiceBus from Azure pipeline.
Publish from Azure DevOps project webhook

I believe what is happening is that you have two different types of serialisation in the body of the brokered message created by the PublishToAzureServiceBus task. This is because the brokered message only supports binary content.
So the json is initially serialised as a binary string using the data contract serialiser.
How to solve this? Do the following before passing to your json deserialiser - unfortunately the logic app isn't doing this:
byte[] messageContent = brokeredMessage.GetBody<byte[]>();
string messageContentStr = Encoding.UTF8.GetString(messageContent);
I probably wouldn't use a logic app to do the reading of the message because to insert c# like I suggest you're gonna need to call an azure function or similar. I'd create an azure function to read your messages as above.

Related

Can't create a schema extension

I am trying to create a schema extension in Microsoft Graph API.
But it has failed with error message "Property type is invalid for target types".
POST https://graph.microsoft.com/v1.0/schemaExtensions
Content-type: application/json
{
"id":"extendedData",
"description": "Graph Learn training courses extensions",
"targetTypes": [
"Event"
],
"properties": [
{
"name": "courseId",
"type": "Integer"
},
{
"name": "materialId",
"type": "Integer"
},
{
"name": "courseType",
"type": "String"
}
]
}
Response
{
"error": {
"code": "BadRequest",
"message": "Property type is invalid for target types.",
"innerError": {
"date": ...,
"request-id": ...,
"client-request-id": ...
}
}
}
Why can't I create a schema extension and what error means?
Integer type in properties is not supported for Event targetTypes based on Supported property data types.
You could change them to String.
Please note that you may will encounter a new error: Attempt to update complex extension definition on application: dexxxxx5-d9f9-48b1-a8ad-b7xxxxx25064 belonging to different context.
If you get this error, it means you still need to put an owner property in the JSON payload. (If you don't get this error, it's unnecessary to put owner property)
Register an Azure AD app and put the application id as the owner.
POST https://graph.microsoft.com/v1.0/schemaExtensions
Content-type: application/json
{
"id":"extendedData",
"description": "Graph Learn training courses extensions",
"targetTypes": [
"Event"
],
"owner": "{application id of an Azure AD app}",
"properties": [
{
"name": "courseId",
"type": "String"
},
{
"name": "materialId",
"type": "String"
},
{
"name": "courseType",
"type": "String"
}
]
}

Alexa Smart Home "Failed to Retrieve State"

I am playing with a sample Alexa Smart Home skill - I am not talking to any real hardware or back-end, just trying to get message flow working. I have set up a simple switch/plug/light that can just support turning On/Off - and I have account linked working and the skill enabled. When I try looking at it via the Alexa app on phone or web (with debug enabled) it always says the device isn't responding, or it's "Failed to Retrieve State". I can definitely see the messages in Cloud Watch as follows.
Any idea why I'd be chronically getting such a response??
Request:
"directive": {
"endpoint": {
"cookie": {},
"endpointId": "endpoint-003",
"scope": {
"token": "<<<SUPRESSING>>",
"type": "BearerToken"
}
},
"header": {
"correlationToken": "<<SHORTENED>>",
"messageId": "50397414-bb9d-412f-8a2c-15669978ab64",
"name": "ReportState",
"namespace": "Alexa",
"payloadVersion": "3"
},
"payload": {}
}
}
Response:
{
"context": {
"properties": [
{
"name": "connectivity",
"namespace": "Alexa.EndpointHealth",
"timeOfSample": "2020-06-29T16:49:59.00Z",
"uncertaintyInMilliseconds": 0,
"value": "OK"
},
{
"name": "powerState",
"namespace": "Alexa.PowerController",
"timeOfSample": "2020-06-29T16:49:59.00Z",
"uncertaintyInMilliseconds": 0,
"value": "ON"
}
]
},
"event": {
"endpoint": {
"endpointId": "endpoint-003",
"scope": {
"token": "Alexa-access-token",
"type": "BearerToken"
}
},
"header": {
"correlationToken": "<<SHORTENED>>",
"messageId": "7a8b9a71-adda-41b8-acba-4d3855374845",
"name": "Response",
"namespace": "Alexa",
"payloadVersion": "3"
},
"payload": {}
}
}
Problem was: The "name" in my header response should have been "ReportState". "Response" is only used for things that set/change values.
My general advice is to always verify that THREE things are good:
Initial "Discovery"
"Response" messages
General "ReportState" queries.
By this - I mean that:
Anything you advertised as should be reported in "discovery" better be reported in other ("ReportState") messages. If you advertise a "PowerController" - if your ReportStates don't contain status for that, you'll either not see the status, or it'll keep retrying forever (continuing to look for it) - or you might get some sort of an error.
If you CHANGED your discovery stuff - make sure that you really removed, re-discovered, and that the states (above) for the new additions/removals are okay
Always make sure that "EndpointHealth" is being reported.

How to customize rest() route's description and id?

I configured Camel REST with Spring Boot and enabled actuator/camelroutes as in this example: https://github.com/apache/camel/blob/master/examples/camel-example-spring-boot/src/main/resources/application.properties
Now i am able to get my route descriptions... the problem is they are showing as route1,route2 etc, and provide no description which makes it difficult to distinguish which route belongs to which REST endpoint, e.g.
{
"id": "route2",
"uptime": "3.172 seconds",
"uptimeMillis": 3172,
"properties": {
"parent": "49889154",
"rest": "true",
"description": null,
"id": "route2"
},
"status": "Started"
}
Question is how do I provide custom description and id to rest() routes?
My route is simple:
rest("/hello")
.description("/hello GET endpoint")
.consumes("application/json").produces("text/html")
.get("/").description("Hello World example").outType(String.class)
.to("direct:hello")
and i tried adding .description after .rest("/bla") but it has no effect in the actuator/camelroutes
Ideally, i would like to get something like below:
{
"id": "route1",
"description": "direct hello route returning simple string",
"uptime": "3.173 seconds",
"uptimeMillis": 3173,
"properties": {
"parent": "76af51d6",
"rest": "false",
"description": "direct hello route returning simple string",
"id": "route1"
},
"status": "Started"
},
You need to set id and description to route context, not to rest context.
For example this definition:
rest("/hello")
.consumes("application/json").produces("text/html")
.get("/").outType(String.class)
.route().id("sayHi").description("This endpoint says Hi")
.to("direct:hello");
from("direct:hello")
.routeId("hello")
.setBody(constant("Hi"));
Generates this actuator output:
[
{
"id": "hello",
"uptime": "13.158 seconds",
"uptimeMillis": 13158,
"status": "Started"
},
{
"id": "sayHi",
"description": "This endpoint says Hi",
"uptime": "13.145 seconds",
"uptimeMillis": 13145,
"status": "Started"
}
]

IBM CLOUD function action took too long to respond in IBM watson chat dialog

Hi, I am creating a chatbot. I developed a IBM cloud function(action) in IBM.
This is the action code..
{
"context": {
"my_creds": {
"user": "ssssssssssssssssss",
"password": "sssssssssssssssssssssss"
}
},
"output": {
"generic": [
{
"values": [
{
"text": ""
}
],
"response_type": "text",
"selection_policy": "sequential"
}
]
},
"actions": [
{
"name": "ssssssssssss/user-detail",
"type": "server",
"parameters": {
"name": "<?input.text?>",
"lastname": "<?input.text?>"
},
"credentials": "$my_creds",
"result_variable": "$my_result"
}
]
}
Now my action user detail is giving response when i am invoking the code.
But when i am checking the output with my chatbot I am getting execution of cloud functions action took too long.
There is currently a 5 second limitation on processing time for a cloud function being called from a dialog node. If your process will need longer than this, you'll need to do it client side through your application layer.

Azure Logic App - On New Email - Attachments have null bytes

Why aren't the attachments being read correctly?
Trying to use the quick-start template for saving attachments in emails to a SharePoint folder.
Workflow:
On new email (success)
For each container (Attachments is passed in)
Create file (fails)
On new email > Outputs > Attachments
On new mail appears to succeed, but the content of the attachments is set to null ("ContentBytes": null):
[
{
"Id": "AAMkADlhMDBiODNiLWFmOTEtNGZjOS1hMjYxLTY1OTU3MDk4YzZjNABGAAAAAACijX5OkcblRIVMFzOsYgiSBwBFaJ_hCA08Tb5SmdY6ZqCxAAAAADB8AABFaJ_hCA08Tb5SmdY6ZqCxAACD6w2UAAABEgAQAOCw7xb1bG9LstW5SRafEOE=",
"ContentType": "image/jpeg",
"Size": 16962,
"#odata.type": "#Microsoft.OutlookServices.FileAttachment",
"Name": "image001.jpg",
"ContentBytes": null
},
{
"Id": "AAMkADlhMDBiODNiLWFmOTEtNGZjOS1hMjYxLTY1OTU3MDk4YzZjNABGAAAAAACijX5OkcblRIVMFzOsYgiSBwBFaJ_hCA08Tb5SmdY6ZqCxAAAAADB8AABFaJ_hCA08Tb5SmdY6ZqCxAACD6w2UAAABEgAQAG7KUOVpzCRJslBYmXAysB4=",
"ContentType": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"Size": 194702,
"#odata.type": "#Microsoft.OutlookServices.FileAttachment",
"Name": "Test.docx",
"ContentBytes": null
},
{
"Id": "AAMkADlhMDBiODNiLWFmOTEtNGZjOS1hMjYxLTY1OTU3MDk4YzZjNABGAAAAAACijX5OkcblRIVMFzOsYgiSBwBFaJ_hCA08Tb5SmdY6ZqCxAAAAADB8AABFaJ_hCA08Tb5SmdY6ZqCxAACD6w2UAAABEgAQAL3JExHdzLJDs0YH1XpZXgU=",
"ContentType": "image/jpeg",
"Size": 73353,
"#odata.type": "#Microsoft.OutlookServices.FileAttachment",
"Name": "image005.jpg",
"ContentBytes": null
},
{
"Id": "AAMkADlhMDBiODNiLWFmOTEtNGZjOS1hMjYxLTY1OTU3MDk4YzZjNABGAAAAAACijX5OkcblRIVMFzOsYgiSBwBFaJ_hCA08Tb5SmdY6ZqCxAAAAADB8AABFaJ_hCA08Tb5SmdY6ZqCxAACD6w2UAAABEgAQABUsTq9cXiVCoowGEFnbtHw=",
"ContentType": "image/jpeg",
"Size": 3684,
"#odata.type": "#Microsoft.OutlookServices.FileAttachment",
"Name": "image003.jpg",
"ContentBytes": null
}
]
For-each container > Create file
Fails with the following:
InvalidTemplate. Unable to process template language expressions in
action 'Create_file' inputs at line '1' and column '11': 'The template
language function 'base64ToBinary' expects its parameter to be a
string. The provided value is of type 'Null'. Please see
https://aka.ms/logicexpressions#base64ToBinary for usage details.'.
There's an "include attachments " option on the trigger to opt in to include bytes. Make sure that is turned on and it should work.

Resources