Publishing ServiceBus message from Node (Electron)

This is a handy little module that wraps up the Azure ServiceBus code in a tight little package. I don’t claim any of it as original work, since I have pulled from more sources than I can remember.

It is a work in progress, but I wanted to document what I have so far.

Code for azHelper.js

"use strict";

var azure = require("azure-sb");
var sbConnect = "Endpoint VALID CONNECTION STRING HERE...";
var sbService = azure.createServiceBusService(sbConnect);

function publishMessage(messageLabel, message, category) {
  if (!category) {
    category = 1000;
  console.log("Publishing message", messageLabel);

  var sbMessage = {
    body: JSON.stringify(message),
    brokerProperties: {
      Label: messageLabel
    customProperties: {
      Category: category

  sbService.sendTopicMessage("rapids", sbMessage, sbCallback);

var sbCallback = function(err) {
  if (err) {
    console.log("ERROR publishing message", err);
  } else {
    console.log("message published");

module.exports = {
  publish: publishMessage

And the calling code…

var azHelper = require("./azhelper.js");

var contentFoundMessage = {
    fileName: fileName,
    baseName: baseName

azHelper.publish("ContentFound", contentFoundMessage, 1100);
Print Friendly, PDF & Email