登录
首页 >  Golang >  Go问答

在 Azure 存储队列中传输字节数组

来源:stackoverflow

时间:2024-02-15 22:36:23 244浏览 收藏

哈喽!大家好,很高兴又见面了,我是golang学习网的一名作者,今天由我给大家带来一篇《在 Azure 存储队列中传输字节数组》,本文主要会讲到等等知识点,希望大家一起学习进步,也欢迎大家关注、点赞、收藏、转发! 下面就一起来看看吧!

问题内容

我正在使用go包github.com/golang/protobuf/proto,我需要将protobuff排入存储队列。但根据库文档,enqueue 函数仅将消息作为字符串。

  • 来自 go 库:
*func (m MessagesURL) Enqueue(ctx context.Context, messageText string, visibilityTimeout time.Duration, timeToLive time.Duration) (*EnqueueMessageResponse, error)*

有什么方法可以将 protobuff 字节数组排入 azure 存储队列吗?

图书馆链接: https://pkg.go.dev/github.com/azure/azure-storage-queue-go/azqueue#messagesurl.enqueue


正确答案


Azure Storage Queue Go library 似乎没有为字节数组(或 protobuf 消息)提供任何内置支持。

但是,您可以应用自己的序列化并将 protobuf 消息转换为例如使用 protojson package 进行 json,然后将结果字符串传递给 Enqueue method

import "google.golang.org/protobuf/encoding/protojson"
[...]
jsonBytes, _ := protojson.Marshal(protoMessage)
json := string(jsonBytes)
[...]
messagesURL.Enqueue(ctx, json, time.Second*0, time.Minute)

以上就是《在 Azure 存储队列中传输字节数组》的详细内容,更多关于的资料请关注golang学习网公众号!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>