简体   繁体   English

如何将二进制消息从 Azure 函数发送到 Azure 服务总线

[英]How to send a binary message from Azure Function to Azure Service Bus

I used the following code to send some sample binary messages to a service bus from an Azure function, but on the service bus I always receive a message with the content "System.Byte[]" and the content type "text/plain" .我使用以下代码将一些示例二进制消息从 Azure 函数发送到服务总线,但在服务总线上,我总是收到内容为"System.Byte[]"和内容类型为"text/plain"的消息。 I also tried to read the messages from the service bus with a Java app and I get the same result.我还尝试使用 Java 应用程序从服务总线读取消息,我得到了相同的结果。 When reading the messages with the Java app I expect to receive the specified array new byte[] { 1, 3, 4, 5, 6, 7, 8, 9} , not the byte array that represents the String "System.Byte[]" .使用 Java 应用程序读取消息时,我希望收到指定的数组new byte[] { 1, 3, 4, 5, 6, 7, 8, 9} ,而不是代表字符串"System.Byte[]" I assume that the azure function sends the binary array as a String instead of byte array.我假设 azure 函数将二进制数组作为字符串而不是字节数组发送。

package azure.functions;

import com.microsoft.azure.functions.ExecutionContext;
import com.microsoft.azure.functions.annotation.FunctionName;
import com.microsoft.azure.functions.annotation.TimerTrigger;
import com.microsoft.azure.functions.annotation.ServiceBusQueueOutput;

public class ServiceBusPeriodicSampleProducer {
    @FunctionName("ServiceBusPeriodicSampleProducer")
    @ServiceBusQueueOutput(
        name = "serviceBusBinaryMessage", 
        queueName = "test-queue", 
        connection = "ServiceBusConnection", 
        dataType = "binary"
    )
    public byte[] sendSampleMessageToServiceBus(
        @TimerTrigger(name = "timerInfo", schedule = "0 * * * * *") String timerInfo, final ExecutionContext context
    ) {
        context.getLogger().info("Java Timer trigger function executed at: " + java.time.LocalDateTime.now());
        return new byte[] { 1, 3, 4, 5, 6, 7, 8, 9};
    }
}

根据文档,您似乎需要添加一个OutputBinding<Byte[]>类型的参数,并使用outputBinding.SetValue(bytes)在该参数中设置值,而不是从方法返回字节。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从天蓝色功能发送天蓝色服务总线中的完整代理消息 - send a full brokered message in azure service bus from an azure function 如何从azure功能向azure服务总线添加消息? - How to add message to azure service bus from azure function? 如何将服务总线消息标记为从 Azure 函数处理? - How mark a Service Bus message as processed from an Azure function? 如何从 Azure Function 更新服务总线消息? - How to renew Service Bus message from Azure Function? How to trigger both Azure Function by Service Bus message and output message to Service Bus within single Azure Function - How to trigger both Azure Function by Service Bus message and output message to Service Bus within single Azure Function 如何从Azure移动服务脚本向Azure服务总线队列发送消息 - How to send a message to Azure service bus queue from a Azure mobile services script 无法使用Azure功能将消息发送到Service Bus队列 - Unable to send message into Service Bus Queue using Azure function Azure Service Bus队列发送消息缓慢 - Azure Service Bus Queues slow to send message 如何从Azure函数将消息发布到Azure Service Bus? - How do I post a message to a Azure Service Bus from my Azure function? 如何仅向一个 Azure 服务总线订阅发送消息? - How to send a message to only one Azure Service Bus Subscription?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM