Azure / azure-functions-host

The host/runtime that powers Azure Functions
https://functions.azure.com
MIT License
1.91k stars 436 forks source link

ServiceBus binding does not support binary data type for non C# languages #3125

Open soninaren opened 6 years ago

soninaren commented 6 years ago

When you send binary data via a service bus message it shows up as "String": "System.Byte[]" instead of the actual data.

There is some relevant data in this PR https://github.com/Azure/azure-functions-python-worker/pull/158

Sample protobuff message


 {
        "Origin": "Host",
        "MessageType": "InvocationRequest",
        "WorkerId": "dc1036ce-8a25-4fa9-9311-189562f33dd5",
        "Message": {
          "RequestId": "",
          "InvocationRequest": {
            "InvocationId": "676e0dbd-b2d6-4909-838a-22f8a72d4cc7",
            "FunctionId": "13972e81-2479-4bc7-ad0e-589830026c12",
            "InputData": [
              {
                "Name": "msg",
                "Data": {
                  "String": "System.Byte[]",
                  "Json": "",
                  "Bytes": [],
                  "Stream": [],
                  "Int": 0,
                  "Double": 0.0,
                  "DataCase": "String"
                }
              }
            ],
            "TriggerMetadata": {
              "DeliveryCount": {
                "String": "",
                "Json": "1",
                "Bytes": [],
                "Stream": [],
                "Int": 0,
                "Double": 0.0,
                "DataCase": "Json"
              },
              "DeadLetterSource": {
                "String": "",
                "Json": "",
                "Bytes": [],
                "Stream": [],
                "Int": 0,
                "Double": 0.0,
                "DataCase": "None"
              },
              "ExpiresAtUtc": {
                "String": "",
                "Json": "\"2018-07-12T14:36:59.104Z\"",
                "Bytes": [],
                "Stream": [],
                "Int": 0,
                "Double": 0.0,
                "DataCase": "Json"
              },
              "EnqueuedTimeUtc": {
                "String": "",
                "Json": "\"2018-06-28T14:36:59.104Z\"",
                "Bytes": [],
                "Stream": [],
                "Int": 0,
                "Double": 0.0,
                "DataCase": "Json"
              },
              "MessageId": {
                "String": "cf6fa1fe04ac4cd19b6b625bd284e51c",
                "Json": "",
                "Bytes": [],
                "Stream": [],
                "Int": 0,
                "Double": 0.0,
                "DataCase": "String"
              },
              "ContentType": {
                "String": "text/plain",
                "Json": "",
                "Bytes": [],
                "Stream": [],
                "Int": 0,
                "Double": 0.0,
                "DataCase": "String"
              },
              "ReplyTo": {
                "String": "",
                "Json": "",
                "Bytes": [],
                "Stream": [],
                "Int": 0,
                "Double": 0.0,
                "DataCase": "None"
              },
              "SequenceNumber": {
                "String": "",
                "Json": "31806672368304129",
                "Bytes": [],
                "Stream": [],
                "Int": 0,
                "Double": 0.0,
                "DataCase": "Json"
              },
              "To": {
                "String": "",
                "Json": "",
                "Bytes": [],
                "Stream": [],
                "Int": 0,
                "Double": 0.0,
                "DataCase": "None"
              },
              "Label": {
                "String": "",
                "Json": "",
                "Bytes": [],
                "Stream": [],
                "Int": 0,
                "Double": 0.0,
                "DataCase": "None"
              },
              "CorrelationId": {
                "String": "",
                "Json": "",
                "Bytes": [],
                "Stream": [],
                "Int": 0,
                "Double": 0.0,
                "DataCase": "None"
              },
              "UserProperties": {
                "String": "",
                "Json": "{\"$AzureWebJobsParentId\":\"06ea352e-e884-4ce1-8fc1-48fc84edc6e8\",\"x-opt-enqueue-sequence-number\":0}",
                "Bytes": [],
                "Stream": [],
                "Int": 0,
                "Double": 0.0,
                "DataCase": "Json"
              },
              "sys": {
                "String": "",
                "Json": "{\"MethodName\":\"servicebus_trigger\",\"UtcNow\":\"2018-06-28T14:36:59.2639206Z\",\"RandGuid\":\"1476de8c-1ae2-4005-a4e2-4eae017ecd46\"}",
                "Bytes": [],
                "Stream": [],
                "Int": 0,
                "Double": 0.0,
                "DataCase": "Json"
              }
            }
          },
          "ContentCase": "InvocationRequest"
        },
        "Name": "InvocationRequest",
        "Source": "Rpc"
      }
uch-energinet commented 2 years ago

Has this ever been solved. I'm having issues sending bytes data to a Service Bus using the Python library. A simple function example here, where I am triggering on a service bus message, and also outputting one.

def azure_func(msg: func.ServiceBusMessage) -> bytes:
    return b"hello world"

On the receiving message bus, it shows up as a string with the content "System.byte[]" and not the actual bytes data

pragnagopa commented 2 years ago

Tagging @fabiocav / @liliankasem for triage

pragnagopa commented 2 years ago

@vrdmr / @gavin-aguiar / @YunchuWang - can you confirm if python language worker supports TypedData : https://github.com/Azure/azure-functions-language-worker-protobuf/blob/6635670b136d565f2a196ce1a64fee1ea5c9c1c9/src/proto/FunctionRpc.proto#L400 ?

MughundhanRaveendran-MSFT commented 2 years ago

@vrdmr / @gavin-aguiar / @YunchuWang , Any updates on this thread? Similar issue is seen here : https://docs.microsoft.com/en-us/answers/questions/855946/index.html

fabiocav commented 2 years ago

It would be good to understand the data type being used when this occurs.

@uch-energinet would you be able to share your function.json definition for this?

uch-energinet commented 2 years ago

Yes, of course. You can see the entire code sample in this repository, which I made for this specific issue: https://github.com/uch-energinet/github-issue-3125 (the file you are asking for is under HttpTrigger1/function.json)

azaharyan commented 2 years ago

I have the same issue here. I have two bindings to an azure function - out and in. The in binary correctly receives binary data, but when I try to write binary to a Service Bus topic it shows as "System.Byte[]". I have set to both bindings "dataType: binary" in function.json. Is it even possible to send binary message via a binding to a Service Bus topic?

nickroci commented 2 months ago

This still seems to be an issue with binary data being corrupted into python servicebus trigger. It seems to incorrectly decoding/recoding the bytes as utf8 and replacing errors...