[英]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.