javascript - 如何使用 javascript 在 azure 函数应用程序中使用服务总线主题 session

标签 javascript azure session servicebus azure-servicebus-topics

我有一个 Azure Functionapp,它可以处理一些数据并将这些数据推送到 Azure 服务总线主题中。

我需要在我的 servicebus 主题订阅上启用 session 。使用 javascript functionapp API 时,我似乎找不到设置 session id 的方法。

这是我的函数应用程序的修改摘录:

module.exports = function (context, streamInput) {
  context.bindings.outputSbMsg = [];
  context.bindings.logMessage = [];

  function push(response) {
      let message = {
          body: CrowdSourceDatum.encode(response).finish()
          , customProperties: {
              protoType: manifest.Type
              , version: manifest.Version
              , id: functionId
              , rootType: manifest.RootType
        }
        , brokerProperties: {
            SessionId: "1"
        }
    context.bindings.outputSbMsg.push(message);
  }

  .......... some magic happens here.

  push(crowdSourceDatum);
  context.done();
} 

但是 sessionId 似乎根本没有设置。知道如何实现这一点吗?

deadletter error

message properties

最佳答案

我在我的函数上测试了 sessionid,我可以设置消息的 session id 属性并在服务总线资源管理器中查看它。这是我的示例代码。

var connectionString = 'servicebus_connectionstring';
var serviceBusService = azure.createServiceBusService(connectionString);

var message = {
    body: '',
    customProperties:
    {
        messagenumber: 0
    },
    brokerProperties:
    {
        SessionId: "1"
    }
};

message.body= 'This is Message #101';
serviceBusService.sendTopicMessage('testtopic', message, function(error)
{
    if (error)
    {
        console.log(error);
    }
});

这是测试结果。

enter image description here

请确保您在创建主题和订阅时已启用分区和 session 。

enter image description here

关于javascript - 如何使用 javascript 在 azure 函数应用程序中使用服务总线主题 session ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43982323/

相关文章:

javascript - 数据库查询功能未异步运行

Azure ADF 如何确保复制的相同文件也被删除?

azure - 如何从 HDInsight 上运行的 Apache Spark 读取 Azure 表存储数据

php - 我应该在 CodeIgniter 中的哪里初始化 session 库?

javascript - Google 脚本 doGet TypeError : Impossible to call method "getSheetByName" of null

javascript - 根据用户填写的字段动态设置表单操作

javascript - 如何在等待下载后立即显示图像

powershell - 从 VSTS 发布期间修改 Azure 应用服务 IP 安全性

PHP curl,保留 session

java - 如何使用 Java 在 Tomcat 中以编程方式找出打开 session 的数量?