Azure Notification Hubs SDK voor JavaScript
Azure Notification Hubs bieden een uitgeschaalde push-engine waarmee u vanuit elke back-end (cloud of on-premises) meldingen kunt verzenden naar elk platform (Apple, Amazon Kindle, Firebase, Baidu, Xiaomi, Web, Windows, enzovoort). Notification Hubs werkt goed voor zowel bedrijfs- als consumentenscenario's. Enkele voorbeelden:
- Meldingen van belangrijk nieuws met een lage latentie verzenden naar miljoenen gebruikers.
- Coupons op basis van locatie verzenden naar geïnteresseerde gebruikerssegmenten.
- Meldingen voor evenementen verzenden naar gebruikers of groepen voor bijvoorbeeld media-, sport- en financiële toepassingen.
- Aanbiedingen pushen naar toepassingen om klanten te benaderen en werven.
- Gebruikers van bedrijfsgebeurtenissen, zoals nieuwe berichten en werkitems, op de hoogte stellen.
- Codes verzenden voor meervoudige verificatie.
Belangrijke koppelingen:
OPMERKING: Als u het pakket wilt gebruiken azure-sb
, raadpleegt u de migration guide to move from azure-sb to @azure/notification-hubs
Aan de slag
Momenteel ondersteunde omgevingen
- LTS-versies van Node.js
- Nieuwste versies van Safari, Chrome, Edge en Firefox.
Zie ons ondersteuningsbeleid voor meer informatie.
Het pakket installeren
npm install @azure/notification-hubs
Vereisten
een Azure Notification Hubs-resource Creatie
Een Azure Notification Hub kan op de volgende manieren worden gemaakt:
Nadat de Notification Hub is gemaakt, kan deze worden geconfigureerd met behulp van de Azure-portal of Azure CLI.
De client importeren
Deze SDK voor JavaScript biedt twee manieren om te communiceren met Azure Notification Hubs, via de op klassen gebaseerde benadering of met een modulaire ontwerpbenadering. De op klassen gebaseerde benadering is consistent voor alle pakketten om een client te maken en vervolgens te communiceren met de methoden op de client.
import {
NotificationHubsClient,
createAppleInstallation
} from "@azure/notification-hubs";
const client = new NotificationHubsClient("<connection string>", "<hub name>");
const installation = createAppleInstallation({
installationId: "<installation-id>",
pushChannel: "<push-channel>",
tags: ["likes_javascript"],
});
const result = await client.createOrUpdateInstallation(installation);
Met de modulaire aanpak kan de ontwikkelaar kiezen welke functies moeten worden geïmporteerd wanneer elke methode afzonderlijk wordt weergegeven. Deze benadering maakt gebruik van subpad-exports met ES-Modules om de methoden beschikbaar te maken via directe import. Met de afzonderlijke exports zorgt dit voor een betere tree-shaking-ervaring en kleinere bundelgrootten waarvan de ontwikkelaar kan profiteren.
Het maken van een client wordt weergegeven via het "@azure/notification-hubs/api"
subpad en alle clientmethoden worden weergegeven via het "@azure/notification-hubs/api"
subpad. Elke geëxporteerde functie neemt de client
als eerste parameter en de rest van de parameters blijven ongewijzigd.
De volgende subpaden worden weergegeven:
@azure/notification-hubs/api
- Het belangrijkste toegangspunt voor de client viacreateClientContext
en clientmethoden zoalsgetInstallation
ofsendNotification
@azure/notification-hubs/models
- De Notification Hubs-modellen en -factory-methoden.
Het bovenstaande codefragment wordt vervolgens het volgende:
import { createClientContext, createOrUpdateInstallation } from "@azure/notification-hubs/api";
import { createAppleInstallation } from "@azure/notification-hubs/models";
const context = createClientContext("<connection string>", "<hub name>");
const installation = createAppleInstallation({
installationId: "<installation-id>",
pushChannel: "<push-channel>",
tags: ["likes_javascript"],
});
const result = await createOrUpdateInstallation(context, installation);
De client verifiëren
Interactie met een Azure Notification Hub begint met de NotificationHubsClient
die ondersteuning biedt voor Shared Access Signature-verbindingsreeksen. Dit omvat de volgende machtigingsniveaus: Luisteren, Beheren, Verzenden.
Met Luisteren kan een client zichzelf registreren via de API voor registratie en installaties. Met Verzenden kan de client meldingen verzenden naar apparaten met behulp van de verzend-API's. Ten slotte kan de gebruiker met Beheren registratie- en installatiebeheer uitvoeren, zoals query's.
Er kan een nieuwe NotificationHubsClient
client worden gemaakt met behulp van de constructor met de naam van de verbindingsreeks en Notification Hub.
import { NotificationHubsClient } from "@azure/notification-hubs";
const client = new NotificationHubsClient("<connection string>", "<hub name>");
Met behulp van de modulaire benadering kan de createClientContext
worden geïmporteerd via het "@azure/notification-hubs/api"
subpad.
import { createClientContext } from "@azure/notification-hubs/api";
const context = createClientContext("<connection string>", "<hub name>");
Belangrijkste concepten
Zodra de NotificationHubClient
is geïnitialiseerd, kunnen de volgende concepten worden verkend.
- Apparaatbeheer via Installaties en RegistratieBeschrijvingen
- Meldingen verzenden naar apparaten
Apparaatbeheer
Apparaatbeheer is een kernconcept voor Notification Hubs om de unieke id van de systeemeigen Platform Notification Service (PNS) zoals APNs of Firebase op te slaan, en de bijbehorende metagegevens, zoals tags die worden gebruikt voor het verzenden van pushmeldingen naar doelgroepen. Dit wordt gedaan met twee API's, de installatie-API, het nieuwere en voorkeursmechanisme, en registraties.
Api voor installaties
Installaties zijn een nieuwere en systeemeigen JSON-benadering voor apparaatbeheer die aanvullende eigenschappen bevat, zoals een installatie-id en gebruikers-id die kunnen worden gebruikt voor het verzenden naar doelgroepen. De api voor installaties heeft op de volgende manieren enkele voordelen ten opzichte van de bestaande registratie-API's:
- Volledig idempotente API, dus het aanroepen van maken op de installatie, zodat een bewerking opnieuw kan worden geprobeerd zonder dat u zich zorgen hoeft te maken over duplicaties.
- Ondersteuning voor
userId
en-eigenschappeninstallationId
die vervolgens kunnen worden gebruikt in tag-expressies zoals$InstallationId:{myInstallId}
en$UserId:{bob@contoso.com}
. - Sjablonen maken nu deel uit van de installatie in plaats van een afzonderlijke registratie en kunnen op naam worden vermeld als een tag voor verzending.
- Gedeeltelijke updates worden ondersteund via de JSON Patch Standard, waarmee tags kunnen worden toegevoegd en andere gegevens kunnen worden gewijzigd zonder dat u eerst een query op de installatie hoeft uit te voeren.
Installaties kunnen worden gemaakt met behulp van de createOrUpdateInstallation
methode zoals de volgende:
import { NotificationHubsClient, createAppleInstallation } from "@azure/notification-hubs";
import { v4 as uuid } from "uuid";
const client = new NotificationHubsClient("<connection string>", "<hub name>");
// Create an installation for APNs
let installation = createAppleInstallation({
installationId: uuid(), // Must be unique
pushChannel: "00fc13adff785122b4ad28809a3420982341241421348097878e577c991de8f0", // PNS specific handle
tags: ["likes_hockey", "likes_football"],
});
installation = await client.createOrUpdateInstallation(installation);
Met behulp van de modulaire benadering ziet de code er als volgt uit:
import { createClientContext, createOrUpdateInstallation } from "@azure/notification-hubs/api";
import { createAppleInstallation } from "@azure/notification-hubs/models";
import { v4 as uuid } from "uuid";
const context = createClientContext("<connection string>", "<hub name>");
// Create an installation for APNs
let installation = createAppleInstallation({
installationId: uuid(), // Must be unique
pushChannel: "00fc13adff785122b4ad28809a3420982341241421348097878e577c991de8f0", // PNS specific handle
tags: ["likes_hockey", "likes_football"],
});
installation = await createOrUpdateInstallation(context, installation);
Een update van een installatie kan worden uitgevoerd via het JSON Patch-schema, zoals het toevoegen van een tag en een gebruikers-id met behulp van de updateInstallation
methode.
import { NotificationHubsClient, JsonPatch } from "@azure/notification-hubs";
const client = new NotificationHubsClient("<connection string>", "<hub name>");
const installationId = "<unique installation ID>";
const updates: JsonPatch[] = [
{ op: "add", path: "/tags", value: "likes_baseball" },
{ op: "add", path: "/userId", value: "bob@contoso.com" },
];
const installation = await client.updateInstallation(installationId, updates);
Met behulp van de modulaire benadering ziet de code er als volgt uit:
import { createClientContext, updateInstallation } from "@azure/notification-hubs/api";
import { JsonPatch } from "@azure/notification-hubs/models";
const context = createClientContext("<connection string>", "<hub name>");
const installationId = "<unique installation ID>";
const updates: JsonPatch[] = [
{ op: "add", path: "/tags", value: "likes_baseball" },
{ op: "add", path: "/userId", value: "bob@contoso.com" },
];
const installation = await updateInstallation(context, installationId, updates);
Als u een bestaande installatie wilt ophalen, gebruikt u de getInstallation
methode met uw bestaande unieke installatie-id.
import { NotificationHubsClient } from "@azure/notification-hubs";
const client = new NotificationHubsClient("<connection string>", "<hub name>");
const installationId = "<unique installation ID>";
const installation = client.getInstallation(installationId);
Met behulp van de modulaire benadering ziet de code er als volgt uit:
import { createClientContext, getInstallation } from "@azure/notification-hubs/api";
const context = createClientContext("<connection string>", "<hub name>");
const installationId = "<unique installation ID>";
const installation = getInstallation(context, installationId);
Api voor registraties
Een registratie is gekoppeld aan een PNS, net als de bovenstaande installatie, met de unieke apparaat-id van de PNS en bijbehorende tags. Sjablonenregistraties zijn een manier om vooraf gedefinieerde hoofdtekstsjablonen te maken die vervolgens tijdens het verzenden kunnen worden aangepast met eigenschappen die voor het bericht moeten worden ingevuld. Zie De documentatie over sjablonen voor meer informatie over sjablonen.
Een installatie kan op twee manieren worden gemaakt: eerst door een registratie-id van de server op te halen met behulp van getInstallationId
en vervolgens createOrUpdateRegistration
of via de createRegistration
methode.
import {
NotificationHubsClient,
createAppleRegistrationDescription,
} from "@azure/notification-hubs";
const client = new NotificationHubsClient("<connection string>", "<hub name>");
let registration = createAppleRegistrationDescription({
deviceToken: "00fc13adff785122b4ad28809a3420982341241421348097878e577c991de8f0",
tags: ["likes_hockey", "likes_football"],
});
registration = await client.createRegistration(registration);
console.log(`New Registration ID: ${registration.registrationId}`);
Met behulp van de modulaire benadering ziet de code er als volgt uit:
import { createClientContext, createRegistration } from "@azure/notification-hubs/api";
import { createAppleRegistrationDescription } from "@azure/notification-hubs/models";
const context = createClientContext("<connection string>", "<hub name>");
let registration = createAppleRegistrationDescription({
deviceToken: "00fc13adff785122b4ad28809a3420982341241421348097878e577c991de8f0",
tags: ["likes_hockey", "likes_football"],
});
registration = await createRegistration(context, registration);
console.log(`New Registration ID: ${registration.registrationId}`);
Updates kan worden uitgevoerd via de updateRegistration
methode, maar biedt in tegenstelling tot installaties geen ondersteuning voor incrementele updates. Query's uitvoeren op een bestaande registratie kan worden uitgevoerd met de getRegistration
-methode.
import { NotificationHubsClient } from "@azure/notification-hubs";
const client = new NotificationHubsClient("<connection string>", "<hub name>");
const registrationId = "<unique Registration ID>";
let registration = await client.getRegistration(registrationId);
registration.tags.push("likes_sports");
registration = await client.updateRegistration(registration);
Met behulp van de modulaire benadering ziet de code er als volgt uit:
import {
createClientContext,
getRegistration,
updateRegistration
} from "@azure/notification-hubs/api";
const context = createClientContext("<connection string>", "<hub name>");
const registrationId = "<unique Registration ID>";
let registration = await getRegistration(context, registrationId);
registration.tags.push("likes_sports");
registration = await updateRegistration(context, registration);
Registraties kunnen, in tegenstelling tot installaties, worden opgevraagd om alle registraties op te halen, registraties te koppelen aan een voorwaarde of door tags. Registraties kunnen worden opgevraagd met behulp van de listRegistrations
methode , listRegistrationsByChannel
en listRegistrationsByTag
. Alle methoden ondersteunen beperken via de top
optie en ondersteunen asynchrone paging.
import { NotificationHubsClient } from "@azure/notification-hubs/api";
const client = new NotificationHubsClient("<connection string>", "<hub name>");
const registrations = await client.listRegistrationsByTag("likes_hockey");
let page = 0;
for await (const pages of registrations.byPage()) {
console.log(`Page number ${page++}`);
for (const item of pages) {
console.log(JSON.stringify(item, null, 2));
}
}
Met behulp van de modulaire benadering ziet de code er als volgt uit:
import { createClientContext, listRegistrationsByTag } from "@azure/notification-hubs/api";
const context = createClientContext("<connection string>", "<hub name>");
const registrations = await listRegistrationsByTag(context, "likes_hockey");
let page = 0;
for await (const pages of registrations.byPage()) {
console.log(`Page number ${page++}`);
for (const item of pages) {
console.log(JSON.stringify(item, null, 2));
}
}
Verzendbewerkingen
Notification Hubs ondersteunt het verzenden van meldingen naar apparaten rechtstreeks met behulp van de unieke PNS-id, met behulp van tags voor het verzenden van het publiek of een algemene uitzending naar alle apparaten. Met behulp van de Standard-SKU en hoger kan de gebruiker met gepland verzenden meldingen tot zeven dagen van tevoren plannen. Alle verzendbewerkingen retourneren een tracerings-id en correlatie-id die kunnen worden gebruikt voor notification hubs-ondersteuningsaanvragen. Met de Standard-SKU en hoger wordt ook een meldings-id geretourneerd die kan worden gebruikt om telemetrie van meldingen op te halen via de getNotificationOutcomeDetails
methode.
Voor foutopsporing kunnen de enableTestSend
opties worden ingesteld op true
die direct feedback krijgt van de PNS over de sendNotification
methode, maar wordt niet ondersteund in productiescenario's. Dit wordt niet ondersteund op de geplande verzendmethoden.
Onbewerkte JSON- of XML-tekenreeksen kunnen worden verzonden naar de verzend- of geplande verzendmethoden, of de opbouwfuncties voor meldingen kunnen worden gebruikt om berichten per PNS samen te stellen, zoals APNs, Firebase, Baidu, ADM en WNS. Deze opbouwfuncties bouwen de systeemeigen berichtindeling, zodat u niet hoeft te raden welke velden beschikbaar zijn voor elke PNS.
// Using the class-based approach
import { createAppleNotificationBody } from "@azure/notification-hubs";
// Using the modular approach
import { createAppleNotification, createAppleNotificationBody } from "@azure/notification-hubs/models";
const apnsBody = createAppleNotificationBody({
alert: {
title: "Notification Title",
subtitle: "Notification Subtitle",
body: "Notification body goes here",
},
sound: "default",
interruptionLevel: "time-sensitive",
});
// Send the message using the modular approach
const notification = createAppleNotification({
body: apnsBody
})
const result = await sendNotification(context, notification);
Verzenden uitzenden
Notification Hubs kunnen worden gebruikt om meldingen te verzenden naar alle geregistreerde apparaten per platform met behulp van broadcast send via de sendNotification
methode.
import {
NotificationHubsClient,
createAppleNotification,
} from "@azure/notification-hubs/api";
const context = createClientContext(connectionString, hubName);
const messageBody = `{ "aps" : { "alert" : "Hello" } }`;
const message = createAppleNotification({
body: messageBody,
headers: {
"apns-priority": "10",
"apns-push-type": "alert",
},
});
const result = await client.sendNotification(message);
console.log(`Tracking ID: ${result.trackingId}`);
console.log(`Correlation ID: ${result.correlationId}`);
// Only available in Standard SKU and above
if (result.notificationId) {
console.log(`Notification ID: ${result.notificationId}`);
}
Met behulp van de modulaire benadering ziet de code er als volgt uit:
import { createClientContext, sendNotification } from "@azure/notification-hubs/api";
import { createAppleNotification } from "@azure/notification-hubs/models";
const context = createClientContext(connectionString, hubName);
const messageBody = `{ "aps" : { "alert" : "Hello" } }`;
const message = createAppleNotification({
body: messageBody,
headers: {
"apns-priority": "10",
"apns-push-type": "alert",
},
});
const result = await sendNotification(context, message);
console.log(`Tracking ID: ${result.trackingId}`);
console.log(`Correlation ID: ${result.correlationId}`);
// Only available in Standard SKU and above
if (result.notificationId) {
console.log(`Notification ID: ${result.notificationId}`);
}
Direct verzenden
Als u een apparaat rechtstreeks wilt verzenden, kan de gebruiker verzenden met behulp van de door het platform opgegeven unieke id, zoals het APNs-apparaattoken, door de sendNotification
methode aan te roepen met een deviceHandle
parameter.
import {
NotificationHubsClient,
createAppleNotification,
} from "@azure/notification-hubs";
const client = new NotificationHubsClient(connectionString, hubName);
const deviceHandle = "00fc13adff785122b4ad28809a3420982341241421348097878e577c991de8f0";
const messageBody = `{ "aps" : { "alert" : "Hello" } }`;
const message = createAppleNotification({
body: messageBody,
headers: {
"apns-priority": "10",
"apns-push-type": "alert",
},
});
const result = await client.sendNotification(message, { deviceHandle });
console.log(`Tracking ID: ${result.trackingId}`);
console.log(`Correlation ID: ${result.correlationId}`);
// Only available in Standard SKU and above
if (result.notificationId) {
console.log(`Notification ID: ${result.notificationId}`);
}
Met behulp van de modulaire benadering ziet de code er als volgt uit:
import { createClientContext, sendDirectNotification } from "@azure/notification-hubs/api";
import { createAppleNotification } from "@azure/notification-hubs/models";
const context = createClientContext(connectionString, hubName);
const deviceHandle = "00fc13adff785122b4ad28809a3420982341241421348097878e577c991de8f0";
const messageBody = `{ "aps" : { "alert" : "Hello" } }`;
const message = createAppleNotification({
body: messageBody,
headers: {
"apns-priority": "10",
"apns-push-type": "alert",
},
});
const result = await sendNotification(context, message, { deviceHandle });
console.log(`Tracking ID: ${result.trackingId}`);
console.log(`Correlation ID: ${result.correlationId}`);
// Only available in Standard SKU and above
if (result.notificationId) {
console.log(`Notification ID: ${result.notificationId}`);
}
Doelgroep verzenden
Naast het richten op één apparaat, kan een gebruiker zich richten op meerdere apparaten met behulp van tags. Deze tags kunnen worden opgegeven als een lijst met tags, die vervolgens een tagexpressie maakt die overeenkomt met geregistreerde apparaten, of via een tagexpressie die vervolgens Booleaanse logica kan gebruiken om de juiste doelgroep te bereiken. Zie Routering en tagexpressies voor meer informatie over tags en tags-expressies.
Als u een tagexpressie wilt maken op basis van een matrix met tags, is er een opbouwfunctie voor tagexpressies beschikbaar met de createTagExpression
methode die wordt weergegeven op het hoogste importniveau of @azure/notification-hubs/models/tagExpressionBuilder
modulair importeren, waarmee een 'of tag-expressie' wordt gemaakt op basis van de tags.
// Top level import
import { createTagExpression } from "@azure/notification-hubs";
// Modular import
import { createTagExpression } from "@azure/notification-hubs/models";
const tags = ["likes_football", "likes_hockey"];
const tagExpression = createTagExpression(tags);
console.log(tagExpression);
// likes_football||likes_hockey
Berichten met tagexpressies kunnen worden verzonden met behulp van de volgende code:
import {
NotificationHubsClient,
createAppleNotification,
} from "@azure/notification-hubs";
const client = new NotificationHubsClient("<connection string>", "<hub name>");
const tagExpression = "likes_hockey && likes_football";
const messageBody = `{ "aps" : { "alert" : "Hello" } }`;
const notification = createAppleNotification({
body: messageBody,
headers: {
"apns-priority": "10",
"apns-push-type": "alert",
},
});
const result = await client.sendNotification(notification, { tagExpression });
console.log(`Tracking ID: ${result.trackingId}`);
console.log(`Correlation ID: ${result.correlationId}`);
// Only available in Standard SKU and above
if (result.notificationId) {
console.log(`Notification ID: ${result.notificationId}`);
}
Met behulp van de modulaire benadering ziet de code er als volgt uit:
import { createClientContext, sendNotification } from "@azure/notification-hubs/api";
import { createAppleNotification } from "@azure/notification-hubs/models";
const context = createClientContext("<connection string>", "<hub name>");
const tagExpression = "likes_hockey && likes_football";
const messageBody = `{ "aps" : { "alert" : "Hello" } }`;
const notification = createAppleNotification({
body: messageBody,
headers: {
"apns-priority": "10",
"apns-push-type": "alert",
},
});
const result = await sendNotification(context, notification, { tagExpression });
console.log(`Tracking ID: ${result.trackingId}`);
console.log(`Correlation ID: ${result.correlationId}`);
// Only available in Standard SKU and above
if (result.notificationId) {
console.log(`Notification ID: ${result.notificationId}`);
}
Gepland verzenden
Pushmeldingen kunnen maximaal zeven dagen van tevoren worden gepland met Standard-SKU-naamruimten en hoger met behulp van de scheduleBroadcastNotification
methode voor het verzenden naar apparaten met tags of een algemene uitzending. Hiermee wordt een meldings-id geretourneerd die vervolgens kan worden gebruikt om indien nodig via de cancelScheduledNotification
methode te annuleren.
import {
NotificationHubsClient,
createAppleNotification,
} from "@azure/notification-hubs";
const client = new NotificationHubsClient("<connection string>", "<hub name>");
const tagExpression = "likes_hockey && likes_football";
const messageBody = `{ "aps" : { "alert" : "Hello" } }`;
// Schedule 8 hours from now
const scheduledTime = new Date(Date.now() + (8 * 60 * 60 * 1000));
const message = createAppleNotification({
body: messageBody,
headers: {
"apns-priority": "10",
"apns-push-type": "alert",
},
});
const result = await client.scheduleNotification(scheduledTime, message, { tagExpression });
console.log(`Tracking ID: ${result.trackingId}`);
console.log(`Correlation ID: ${result.correlationId}`);
// Can be used to cancel via the cancelScheduledSend method
console.log(`Notification ID: ${result.notificationId}`);
Met behulp van de modulaire benadering ziet de code er als volgt uit:
import { createClientContext, scheduleNotification } from "@azure/notification-hubs/api";
import { createAppleNotification } from "@azure/notification-hubs/models";
const context = createClientContext("<connection string>", "<hub name>");
const tagExpression = "likes_hockey && likes_football";
const messageBody = `{ "aps" : { "alert" : "Hello" } }`;
// Schedule 8 hours from now
const scheduledTime = new Date(Date.now() + (8 * 60 * 60 * 1000));
const message = createAppleNotification({
body: messageBody,
headers: {
"apns-priority": "10",
"apns-push-type": "alert",
},
});
const result = await scheduleNotification(context, scheduledTime, message, { tagExpression });
console.log(`Tracking ID: ${result.trackingId}`);
console.log(`Correlation ID: ${result.correlationId}`);
// Can be used to cancel via the cancelScheduledSend method
console.log(`Notification ID: ${result.notificationId}`);
Problemen oplossen
React Native-ondersteuning
React Native momenteel geen ondersteuning biedt voor [URLSearchParams
] die wordt gebruikt door de Azure Notification Hubs SDK. Als u de SDK in React Native wilt gebruiken, moet u het url-search-params-polyfill
pakket installeren en importeren voordat u de SDK gebruikt.
import 'url-search-params-polyfill';
We moeten ook polyfill bieden voor TextEncoder
API en asynchrone iterator-API. Zie ons React Native voorbeeld met Expo voor meer informatie.
Verwijderde meldingen diagnosticeren
Azure Notification Hubs bevat een volledige handleiding voor het oplossen van problemen met verwijderde meldingen in de handleiding Verwijderde meldingen diagnosticeren in Azure Notification Hubs.
Verzenden testen wordt ondersteund in de sendNotification
methode met de enableTestSend
optie:
// Using the client
const result = await client.sendNotification(notification, { tags, enableTestSend: true });
// Using the modular approach
const result = await sendNotification(context, notification, { tags, enableTestSend: true });
Logboekregistratie
Het inschakelen van logboekregistratie kan helpen bij het ontdekken van nuttige informatie over fouten. Als u een logboek met HTTP-aanvragen en -antwoorden wilt zien, stelt u de AZURE_LOG_LEVEL
omgevingsvariabele in op info
. U kunt logboekregistratie ook tijdens runtime inschakelen door aan te roepen setLogLevel
in de @azure/logger
:
const { setLogLevel } = require("@azure/logger");
setLogLevel("info");
Voor meer gedetailleerde instructies over het inschakelen van logboeken kunt u de @azure-/loggerpakketdocumenten bekijken.
Volgende stappen
In de volgende voorbeelden ziet u de verschillende manieren waarop u met Azure Notification Hubs kunt werken:
Apparaatbeheer:
- Api voor installaties
- Registratie-API
Verzendbewerkingen:
- Verzenden uitzenden
- Direct verzenden
- Lijst Verzenden door doelgroep met tags
- Doelgroep verzenden met tagexpressie
- Geplande uitzending verzenden
- Gepland verzenden
Beheerbewerkingen:
Bijdragen
Als u een bijdrage wilt leveren aan deze bibliotheek, leest u de handleiding voor bijdragen voor meer informatie over het bouwen en testen van de code.
De tests van deze module zijn een combinatie van live- en eenheidstests, waarvoor u een Azure Notification Hubs-exemplaar moet hebben. Als u de tests wilt uitvoeren, moet u het volgende uitvoeren:
rush update
rush build -t @azure/notification-hubs
- Creatie een .env-bestand met deze inhoud in de
sdk\notificationhubs\notification-hubs
map:NOTIFICATIONHUBS_CONNECTION_STRING=connection string for your Notification Hubs instance
NOTIFICATION_HUB_NAME=Notification Hub name
cd sdk\notificationhubs\notification-hubs
rushx test
.
Bekijk onze testmap voor meer informatie.
Verwante projecten
Azure SDK for JavaScript