Я пытаюсь протестировать хранилище очередей Azure на эмуляторе Azurite в MacOS в локальной среде. Я написал фрагмент кода для отправки сообщения, которое нужно было просмотреть в Azure Storage Explorer. Я использую строку подключения https, как указано в документации по Азурите , и настроил самозаверяющий rootCA.pem
сертификат в Azure Storage Explorer. Однако когда я беру свой код в файл file.js
и запускаю node file.js
. Это все еще дает мне следующее сообщение об ошибке. Кто-нибудь знает, что я сделал неправильно? Дайте мне знать, если потребуется дополнительная информация.
файл.js
'use strict';
const storage = require('azure-storage');
const queueService = storage.createQueueService("DefaultEndpointsProtocol=https;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=https://127.0.0.1:11000/devstoreaccount1;QueueEndpoint=https://127.0.0.1:11001/devstoreaccount1;");
queueService.messageEncoder = new storage.QueueMessageEncoder.TextBase64QueueMessageEncoder();
function testing() {
queueService.createMessage('emailv2', "Hello world", (error) => {
if (error) {
console.info('Error encountered when enqueueing welcome message', error);
console.info()
}
});
}
console.info(testing())
Сообщение об ошибке
Error encountered when enqueueing welcome message Error: unable to verify the first certificate
at TLSSocket.onConnectSecure (_tls_wrap.js:1497:34)
at TLSSocket.emit (events.js:315:20)
at TLSSocket._finishInit (_tls_wrap.js:932:8)
at TLSWrap.ssl.onhandshakedone (_tls_wrap.js:706:12) {
code: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE'
}
@JimXu Да, я уже просматривал этот пост. Однако я не думаю, что это похожая ошибка, так как ошибка показывает ошибку инициализации службы, в то время как у меня идет отправка. Я тоже не инициализировал здесь переменные запроса в своей попытке
Что касается ошибки, кажется, что корневой сертификат отсутствует в комплекте ЦС вашего узла, после чего проверка цепочки завершается неудачно. Я предлагаю вам добавить корневой сертификат в среду выполнения вашего узла.
Например
Настройка HTTPS для эмулятора Азурите
а. создать файл PEM и файл ключа
mkcert -install
mkcert 127.0.0.1
б. Эмулятор Strat Azurite с HTTPS
azurite --cert 127.0.0.1.pem --key 127.0.0.1-key.pem -s -l c:\azurite -d c:\azurite\debug.log --oauth basic
Код
//add the root certificate in your HTTP angent
const rootCas = require("ssl-root-cas").create();
rootCas.addFile("<the path of rootCA.pem>");
require("https").globalAgent.options.ca = rootCas;
const storage = require("azure-storage");
const queue = storage.createQueueService(
"DefaultEndpointsProtocol=https;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=https://127.0.0.1:10000/devstoreaccount1;QueueEndpoint=https://127.0.0.1:10001/devstoreaccount1;"
);
// use our own HTTP anagent
queue.enableGlobalHttpAgent = true;
// the message encoding I use base64
queue.messageEncoder = new storage.QueueMessageEncoder.TextBase64QueueMessageEncoder();
queue.createMessage("test", "hello", (error) => {
if (error) throw error;
console.info("send sucessfully");
});
queue.getMessages("test", (error, serverMessages) => {
if (error) throw error;
console.info(serverMessages[0].messageText);
queue.deleteMessage(
"test",
serverMessages[0].messageId,
serverMessages[0].popReceipt,
(error) => {
if (error) throw error;
console.info("complete the message successfully");
}
);
});
Для получения более подробной информации, пожалуйста, обратитесь к здесь и здесь
Вы ссылались на stackoverflow.com/questions/41083308/…