繁体   English   中英

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

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

我使用以下代码将一些示例二进制消息从 Azure 函数发送到服务总线,但在服务总线上,我总是收到内容为"System.Byte[]"和内容类型为"text/plain"的消息。 我还尝试使用 Java 应用程序从服务总线读取消息,我得到了相同的结果。 使用 Java 应用程序读取消息时,我希望收到指定的数组new byte[] { 1, 3, 4, 5, 6, 7, 8, 9} ,而不是代表字符串"System.Byte[]" 我假设 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM